Help

Re: Scripting Assistance Please - Record Update Script Error

2646 8
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

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?

Doug

Nope. No matter what field you’re copying from, Linked fields only accept updates via scripts in the form of arrays of objects.

Kamille - Appreciate your feedback and apologies for my naivety, but I must not have this right as it still throws an error:

ERROR

TypeError: record.getCellvalue is not a function
at main on line 13

Where am I going wrong?

Capitalize the ‘v’ in .getCellValue()

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

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

I really appreciate your assistance.
Doug

The capitalization was a typo on my end which I have since corrected.

Is the value of your {NPI} field a record ID?

Good morning Kamille. the NPI field is a single line text field. NPI Reference is a linked field to another table.

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”.