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 27, 2021 11:19 AM
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")}]
Apr 27, 2021 12:49 PM
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?
Doug
Apr 27, 2021 12:55 PM
Nope. No matter what field you’re copying from, Linked fields only accept updates via scripts in the form of arrays of objects.
Apr 27, 2021 02:25 PM
Apr 27, 2021 04:38 PM
Capitalize the ‘v’ in .getCellValue()
Apr 27, 2021 07:40 PM
Oh my - that’s embarrassing. Did I mention I’m a novice? With that correction, I still get an 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}’);
await Shifts.updateRecordAsync(recordID, {
"NPI Reference": [{id: record.getCellValue("NPI")}]
})
}
}
I really appreciate your assistance.
Doug
Apr 27, 2021 07:42 PM
The capitalization was a typo on my end which I have since corrected.
Is the value of your {NPI}
field a record ID?
Apr 28, 2021 08:00 AM
Good morning Kamille. the NPI field is a single line text field. NPI Reference is a linked field to another table.
Apr 28, 2021 08:14 AM
That doesnt answer my question. A single line text field can contain any text values. Record ids are text values.
Do the values in the {NPI}
field all look like this: “rec#########…”? If not, then the answer is “no”.