I am trying to develop a script with a mutli-select option. Is there a code for each of these so if I choose to change the actual name, it won’t be a problem?
Hi @Rose_Haft1 - Single and Multi-select fields have a similar structure. A single select is an object of id, name and colour. Multi-select is an array of these objects:
You can reference the select value or values by the id rather than the name and if the name is changed the id will remain the same. When creating or updating a single select field you can write to is using the id or the name:
So, as you want to do, if you go for the id option here you will be fine.
Hi @Rose_Haft1 - Single and Multi-select fields have a similar structure. A single select is an object of id, name and colour. Multi-select is an array of these objects:
You can reference the select value or values by the id rather than the name and if the name is changed the id will remain the same. When creating or updating a single select field you can write to is using the id or the name:
So, as you want to do, if you go for the id option here you will be fine.
Thanks. That is great. Do you have a sample of how I would reference these with script? I have not been able to figure this out…
Thanks. That is great. Do you have a sample of how I would reference these with script? I have not been able to figure this out…
@Rose_Haft1 - if I have two single select fields like this:
Then this script will get the values of each value in the first field, then updates the second field with its value:
let table = base.getTable('Table 1');
let query = await table.selectRecordsAsync();
// read the values
for (let record of query.records) {
let id = record.getCellValue('Single Select').id;
let name = record.getCellValue('Single Select').name;
let color = record.getCellValue('Single Select').color;
// read/log the values
console.log(id, name, color)
// write the values
table.updateRecordAsync(record, {
'Single Select 2': {id: id}
// or:
// 'Single Select 2': {name: name}
})
}
It is similar for a multi-select, but you would have to iterate over each value within the field:
record.getCellValue('Multi Select')
Is there a way to reference the list of potential single-select values? If so, this could be used to simulate a dropdown single-select using the button input.
Is there a way to reference the list of potential single-select values? If so, this could be used to simulate a dropdown single-select using the button input.
You can get the values from the field options.
You don’t actually need the select ids. I usually map the single select choice names to the choices for an input button.
You can get the values from the field options.
You don’t actually need the select ids. I usually map the single select choice names to the choices for an input button.
Thank you for calling this out!
I usually map the single select choice names to the choices for an input button.
Do you have an example?
Edit: Figured it out. Hopefully this helps someone else:
let exampleTable = base.getTable("table");
let fieldName = 'example dropdown'
let buttonVal = await input.buttonsAsync(`Example button label`, exampleTable.getField(fieldName).optionsn'choices'].map(choice => {
return {
'label': Object.values(choice)e1]
}
}));
@Rose_Haft1 - if I have two single select fields like this:
Then this script will get the values of each value in the first field, then updates the second field with its value:
let table = base.getTable('Table 1');
let query = await table.selectRecordsAsync();
// read the values
for (let record of query.records) {
let id = record.getCellValue('Single Select').id;
let name = record.getCellValue('Single Select').name;
let color = record.getCellValue('Single Select').color;
// read/log the values
console.log(id, name, color)
// write the values
table.updateRecordAsync(record, {
'Single Select 2': {id: id}
// or:
// 'Single Select 2': {name: name}
})
}
It is similar for a multi-select, but you would have to iterate over each value within the field:
record.getCellValue('Multi Select')
Thank you. Are these all the properties that can be accessed?
Thank you. Are these all the properties that can be accessed?
Yes. They are all that are listed in the documentation. Note that the color might not exist if the options are not in color. You can also determine the order of the options from the order of the choices in the array.
Were you hoping for additional properties? If so, which ones?
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.