Skip to main content

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

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


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


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.



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?


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()


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": d{id: record.getCellValue("NPI")}]
})
}
}

I really appreciate your assistance.

Doug


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?


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.


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


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


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

“Record id rec004jYbE8Tsmf9k, NPI:1184159147”


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": I{id: match.id}]
})
}
}

Reply