Help

scripting - writing to a multiple select field

Topic Labels: Extensions
940 3
cancel
Showing results for 
Search instead for 
Did you mean: 
cb_obm
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi all,

I'm very new to scripting and am struggling with the syntax to write to a multiple select field. 

I have single select fields ("Monday AM", "Monday PM", "Tuesday AM", etc) that can be Y, N, or blank.

I have formula fields ("First Monday AM", "First Monday PM", "First Tuesday AM", etc) that calculate a date based on a user-entered date.

I have a multiple select field called "Availability". If "Monday AM" is Y, I want to pick up the date from "First Monday AM" and put it into "Availability."

Here is my code:

 

 
let scheduleArray = [];

if (r.getCellValueAsString("Monday AM") == "Y") {
   monAM = r.getCellValue("First Monday AM");
   scheduleArray.push(monAM);
}
if (r.getCellValueAsString("Monday PM") == "Y") {
   monPM = r.getCellValue("First Monday PM");
   scheduleArray.push(monPM);
}
await s.tableSource.updateRecordAsync(r, {"Availability" : scheduleArray});
 
Error:
Can't set cell values: invalid cell value for field 'Availability'. Cell value has invalid format: <root>.0 must be an object, <root>.1 must be an object Multiple select field value must be an array of objects with at least one of 'id' or 'name' as a property.
 
I don't know how to fix the code to make my array into objects and how to use 'id' or 'name.' 

Thanks in advance!
3 Replies 3
TheTimeSavingCo
18 - Pluto
18 - Pluto

You'll need to use something like this:

 

const multipleSelectField = table.getField('My multiple select field');
await multipleSelectField.updateOptionsAsync({
    choices: [
        ...multipleSelectField.options.choices,
        {name: 'My new choice'},
    ],
});

 

I grabbed that from the documentation for multiple select fields and you can find that here

cb_obm
5 - Automation Enthusiast
5 - Automation Enthusiast

@TheTimeSavingCo 

Does this just update the options in the multiple select field? I want to update this particular record.

Yeah, you need to modify your code to use the structure above?  e.g.

await table.updateRecordAsync(RECORD_ID,{
    "Tags": [
        ...(record?.getCellValue('Tags')),
        {"name": "C"}]
})

  May I ask how much coding experience you have?