Upcoming database upgrades. to improve our reliability at 03:30 UTC on Feb. 25 / 7:30pm PT on Feb. 24. Some users may briefly experience slow load times or error messages. Learn more here
Jun 20, 2020 03:14 PM
Hi - I have a newbie question here. I am writing a script with the script block to write a value into a single select field but I keep bashing my head against the wall. Can someone give me some guidance?
Here’s the short and skinny:
If I use the below, it all works, because the “ZIP CODE” field is of type “single line text”. I can write “12345” into it all day long.
let newPreference = "12345";
// update the notes history value and reset the notes value
VoterTable.updateRecordAsync(record, {
"ZIP CODE": newPreference
})
However, in the below, the “PARTY” field is of type “single-select”. One of the options is “Green” but I cannot write “Green” into the field at all. In fact, I cannot write ANY of the options into the field at all. I tried prepending the ordinal value as “11Green” and “11|Green” (Green is the 11th value) and nothing works. Every time I run this, nothing happens.
let newPreference = "Green";
// update the notes history value and reset the notes value
VoterTable.updateRecordAsync(record, {
"PARTY": newPreference
})
Any help for a newbie is appreciated … thanks.
Solved! Go to Solution.
Jun 20, 2020 11:40 PM
Welcome to the community, @aalj! :grinning_face_with_big_eyes: The syntax for updating a single-select field isn’t terribly intuitive. There are actually multiple ways to do it, but here’s how to pull it off using the text of the item you want to select:
let newPreference = "Green";
// update the notes history value and reset the notes value
VoterTable.updateRecordAsync(record, {
"PARTY": {name: newPreference}
})
Jun 20, 2020 11:40 PM
Welcome to the community, @aalj! :grinning_face_with_big_eyes: The syntax for updating a single-select field isn’t terribly intuitive. There are actually multiple ways to do it, but here’s how to pull it off using the text of the item you want to select:
let newPreference = "Green";
// update the notes history value and reset the notes value
VoterTable.updateRecordAsync(record, {
"PARTY": {name: newPreference}
})
Jun 21, 2020 08:58 AM
Thank you that works! You are right, the documentation for that syntax is pretty much non-existent, at least with the first 5 pages of Goog search that I did. :slightly_smiling_face:
Jun 22, 2020 08:30 AM
Google definitely won’t help you. You need to know what’s expected by the scripting block API, and that’s actually documented in the API itself, at the bottom of the editor. I actually found the hint in the popup annotation while testing the code, but if you look in the “Cell values & field options” section of the API docs, you’ll find it there as well.
If you would, please mark my answer above as the solution to your question. This helps others who may be searching with similar questions. Thanks!