Skip to main content
Solved

Scripting - update variable value using a 'number' from a single select field


Hello, new to scripting, running into an issue on a single line as I hack my way through. Just trying to update script var “totes” to be 10 times the value recorded from the single select field “Pts this week”.
So if “Pts this week” has a value of 7, the script var totes should be 70 after this line is what I am trying to accomplish.

The line below gives me NAN so I’m doing something wrong on this particular line. If I am not mistaken, NUMBER() should do the trick as the single select value of 7 will be a string if taken as is.

Anyway, here is the line. Any help is appreciated.

totes = 10 * Number(record.getCellValue("Pts this week"));

Thanks in advance

Best answer by Justin_Barrett

I’m afraid that you are mistaken on that point. When using getCellValue to query a single-select field, the return isn’t a string. It’s an object containing properties about the selected item (name, ID, and color). To get the value as a string, use getCellValueAsString.

totes = 10 * Number(record.getCellValueAsString("Pts this week"));

Alternately, you could use getCellValue and then get the name property from the returned object:

totes = 10 * Number(record.getCellValue("Pts this week").name);
View original
Did this topic help you find an answer to your question?

2 replies

  • Inspiring
  • 4647 replies
  • Answer
  • February 4, 2022

I’m afraid that you are mistaken on that point. When using getCellValue to query a single-select field, the return isn’t a string. It’s an object containing properties about the selected item (name, ID, and color). To get the value as a string, use getCellValueAsString.

totes = 10 * Number(record.getCellValueAsString("Pts this week"));

Alternately, you could use getCellValue and then get the name property from the returned object:

totes = 10 * Number(record.getCellValue("Pts this week").name);

  • Author
  • New Participant
  • 3 replies
  • February 4, 2022
Justin_Barrett wrote:

I’m afraid that you are mistaken on that point. When using getCellValue to query a single-select field, the return isn’t a string. It’s an object containing properties about the selected item (name, ID, and color). To get the value as a string, use getCellValueAsString.

totes = 10 * Number(record.getCellValueAsString("Pts this week"));

Alternately, you could use getCellValue and then get the name property from the returned object:

totes = 10 * Number(record.getCellValue("Pts this week").name);

Beautiful. Thanks @Justin_Barrett!


Reply