Help

Save the date! Join us on October 16 for our Product Ops launch event. Register here.

Scripting Assistance Please - Record Update Script Error

3245 11
cancel
Showing results for 
Search instead for 
Did you mean: 
Doug-CUSOM
6 - Interface Innovator
6 - Interface Innovator

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:

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});

    await Shifts.updateRecordAsync(recordID, {
        "NPI Reference": record.getCellValue("NPI")
    })    
} 

}

Thank you for your help!
Doug

11 Replies 11

Good morning Kamille - No, the {NPI} field does not include “rec…”. Here’s an example:
“Record id rec004jYbE8Tsmf9k, NPI:1184159147”

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}]
      })
   }
}