Hi All,
I'm having difficulty automating a task that I need for my database. Essentially what I'm trying to do is to have a default value in the "Link to Field" selection, which is then removed when another option is added.
The data is currently pulled in from another table using a 'Link to Field' column, I currently have the automation working to add default option back when options are removed but having difficulty creating the script to remove the default option when a second option is added.
Below is my current code, which pulls the current options from the cell and checks whether they are the same as the field being updated, which then passes those choices to an updateOptionsAsync, from which my understanding is the wrong function to be calling.
Any help would be greatly appreciated!!
let inputConfig = input.config();
let currentRecord = (inputConfig.recordID);
let table = base.getTable("Deals");
let field = table.getField("Properties");
let queryResult = await table.selectRecordsAsync({fields: ["Properties"]});
let results = queryResult.records;
results.forEach(record => {
if (record.id == currentRecord) {
let selections = record.getCellValue("Properties");
propertiesCleaner(selections);
}
});
async function propertiesCleaner(choices) {
console.log(choices);
console.log(field);
console.log(field.options.choices);
await field.updateOptionsAsync(
{ choices: [...field.options.choices.filter((choice) => choice.name !== "Default Property ")] },
{ enableSelectFieldChoiceDeletion: true }
);
};