I’d love some guidance on a script error that I am receiving while updating a record.
I have a table that gets refreshed every day with physician work shift data. The refreshed records contain the physician’s NPI value (single line text) as a text field and I want to populate NPI Reference (Linked field) with this same NPI value using a scheduled automation script.
When I run my script, I receive this information:
CONSOLE.LOG
“Copying NPI 1316340000 into record id recHQVgBpFoVSezTP”
ERROR
Error: Field “NPI Reference” cannot accept the provided value.
at main on line 12
Here’s my script:
let Shifts = base.getTable(“Shift Schedules”);
let shift = await Shifts.selectRecordsAsync();
// loop through the records
for (let record of shift.records)
{
if (record.getCellValue(“NPI Reference”) == null)
{
let recordID = record.getCellValue(“Record ID”);
console.log(Copying NPI ${record.getCellValue("NPI")} into record id ${recordID});
Linked fields only accept values in the format of arrays, where each array item is an object with the sole key-value pair of the record id. So: [{id: 'recXXXX'}].
Assuming your {NPI} field stores a singular record ID, then you would adjust your NPI Reference: line to be: [{id: record.getCellValue("NPI")}]
Thank you, Kamille, for your quick response. Regarding the fields, NPI is a single line text field and the NPI Reference field is a linked field to another table with additional data. The values I’m copying from NPI to the NPI Reference field are valid.
Is there something unique with putting a text value into a Linked field?
Oh my - that’s embarrassing. Did I mention I’m a novice? With that correction, I still get an error:
ERROR
Error: Field “NPI Reference” cannot accept the provided value.
at main on line 12
let Shifts = base.getTable(“Shift Schedules”);
let shift = await Shifts.selectRecordsAsync();
// loop through the records
for (let record of shift.records)
{
if (record.getCellValue(“NPI Reference”) == null)
{
let recordID = record.getCellValue(“Record ID”);
console.log(‘Copying NPI {record.getCellValue(“NPI”)} into record id {recordID}’);
Well then you’re going to have to get a list of all the records in the [NPI] table, and filter for the one where the primary field equals the value of record.getCellValue("NPI"), which would look something like this:
let NPItable = base.getTable("Table Name")
let NPIquery = await NPItable.selectRecordsAsync()
let match = NPIquery.records.find(x => x.name == record.getCellValue("NPI"))
if (match) {
await Shifts.updateRecordAsync(recordID, {
"NPI Reference": [{id: match.id}]
})
}
}