Feb 09, 2021 07:52 AM
Hello, I have a script that is intended to copy a set of predefined task records whenever a new project is created. The problem I am running into is with the multiple-select columns. The documentation says that I should be able to write to a multi-select column using the selection ids, but I always get this vague error when testing despite having no syntax/linting errors:
“ERROR
Error: Field “Phase” cannot accept the provided value.
at on line 30
at main on line 15”
Here is my script, plus a picture of the error:
// get respective project
const inputConfig = input.config();
const project = {id:inputConfig.project};
// get tables
const sourceTable = base.getTable("Source");
const destTable = base.getTable("Dest");
// get all template tasks
let query = await sourceTable.selectRecordsAsync();
// for making dynamic functionality later
// TODO: make dynamic functionality later
let cols = sourceTable.fields;
let getColName = (c) => { return c.name; };
let colNames = cols.map(getColName);
query.records.forEach((r) => {
// get phases
let phases = [];
if (r.getCellValue("Phase")) {
for (const x of r.getCellValue("Phase")) {
console.log(x.id);
phases.push({
"id":x.id
});
};
}
// create task record
// TODO: figure out what the problem is with Phase and Who does Task Involve
let cra = destTable.createRecordAsync({
"Task": r.getCellValue("Task"),
"Phase": phases,
"Task Owner": r.getCellValue("Task Owner"),
//"Notify Collaborator(s)": r.getCellValue("Notify Collaborator(s)"),
"Start Date": r.getCellValue("Start Date"),
"End Date": r.getCellValue("End Date"),
// "Who does Task Involve": r.getCellValue("Who does Task Involve"),
"Project": [project]
});
// console.log(cra);
});
Everything works fine except for the multiple-select columns. Am I missing something?
Solved! Go to Solution.
Feb 09, 2021 02:00 PM
Hi @Christopher_Alexeev - the problem here is that you’re creating an array of ids from the source table and trying to push them to the destination table - but the ids will be different here (even though the names are the same). To make this work, the two fields need to have the same set of options (option names) and when you form your array do:
phases.push({
name: x.name
})
Then on your record create you’ll pass through an array of status names which will match with the receiving field’s names.
Feb 09, 2021 02:00 PM
Hi @Christopher_Alexeev - the problem here is that you’re creating an array of ids from the source table and trying to push them to the destination table - but the ids will be different here (even though the names are the same). To make this work, the two fields need to have the same set of options (option names) and when you form your array do:
phases.push({
name: x.name
})
Then on your record create you’ll pass through an array of status names which will match with the receiving field’s names.
Feb 10, 2021 07:45 AM
Thank you @JonathanBowen. I had also tried using names, but apparently the problem was a small typo in one of the selections in the destination table… Definitely one of the dumber mistakes I have made :grinning_face_with_sweat:
As a note to Airtable, it would have be nice to see the value name in the error message.