Save the date! Join us on October 16 for our Product Ops launch event. Register here.
Apr 27, 2021 09:49 AM
Hello Community!
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:
“Copying NPI 1316340000 into record id recHQVgBpFoVSezTP”
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}
);
await Shifts.updateRecordAsync(recordID, {
"NPI Reference": record.getCellValue("NPI")
})
}
}
Thank you for your help!
Doug
Apr 30, 2021 08:07 AM
Good morning Kamille - No, the {NPI} field does not include “rec…”. Here’s an example:
“Record id rec004jYbE8Tsmf9k, NPI:1184159147”
Apr 30, 2021 09:05 AM
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}]
})
}
}