You have two places where you are updating records. The first time you are updating records one at a time (updateRecordAsync
without the s
) without the await
keyword.
Rewrite this first set of updates to use batches (updateRecordsAsync
with the s
) to match the syntax of your second update.
Or do a rewrite of the script so that you only update the records once instead of twice.
You have two places where you are updating records. The first time you are updating records one at a time (updateRecordAsync
without the s
) without the await
keyword.
Rewrite this first set of updates to use batches (updateRecordsAsync
with the s
) to match the syntax of your second update.
Or do a rewrite of the script so that you only update the records once instead of twice.
Hi @kuovonne
Taking your advice, I ditched the first part of the script and tweaked it as below. That solved the mutations error, but I can’t get the script to find or mark the ‘Current’ field as expected.
let table = base.getTable("TaskLog");
let field = table.getField("Account");
let inputConfig = input.config();
let inputValue = inputConfig.AccountID;
// Load all of the records in the table
let result = await table.selectRecordsAsync();
// Find every record we need to update
let updates = [];
for (let record of result.records) {
let recordValue = record.getCellValue('Account');
if(recordValue && recordValue == [{id : inputValue}]) {
updates.push({
id: record.id,
fields: {
["Current"]: "true",
}
});
}else {
//For all other records to have current value as null
updates.push({
id: record.id,
fields: {
["Current"]: null,
}
});
}
}
// Update records - Only up to 50 updates are allowed at one time, so do it in batches
while (updates.length > 0) {
await table.updateRecordsAsync(updates.slice(0, 50));
updates = updates.slice(50);
}
Could the reason be that the ‘Account’ field is a linked field and the script is not matching the input variable (A record ID itself) to the ID of the linked field?
In the hope of matching one to the other, I’ve also tried this:
let recordValue = record.getCellValue('Account');
let recordValueid = recordValue[0].id;
if(recordValueid && recordValueid == inputConfig["AccountID"])
I got an error saying: “Cannot read property ‘0’ of null”
Hi @kuovonne
Taking your advice, I ditched the first part of the script and tweaked it as below. That solved the mutations error, but I can’t get the script to find or mark the ‘Current’ field as expected.
let table = base.getTable("TaskLog");
let field = table.getField("Account");
let inputConfig = input.config();
let inputValue = inputConfig.AccountID;
// Load all of the records in the table
let result = await table.selectRecordsAsync();
// Find every record we need to update
let updates = [];
for (let record of result.records) {
let recordValue = record.getCellValue('Account');
if(recordValue && recordValue == [{id : inputValue}]) {
updates.push({
id: record.id,
fields: {
["Current"]: "true",
}
});
}else {
//For all other records to have current value as null
updates.push({
id: record.id,
fields: {
["Current"]: null,
}
});
}
}
// Update records - Only up to 50 updates are allowed at one time, so do it in batches
while (updates.length > 0) {
await table.updateRecordsAsync(updates.slice(0, 50));
updates = updates.slice(50);
}
Could the reason be that the ‘Account’ field is a linked field and the script is not matching the input variable (A record ID itself) to the ID of the linked field?
In the hope of matching one to the other, I’ve also tried this:
let recordValue = record.getCellValue('Account');
let recordValueid = recordValue[0].id;
if(recordValueid && recordValueid == inputConfig["AccountID"])
I got an error saying: “Cannot read property ‘0’ of null”
The issue is resolved.
There were some blank Account records, so when changing the script as below, everything goes smoothly.
let table = base.getTable("TaskLog");
let field = table.getField("Account");
let inputConfig = input.config();
let inputValue = inputConfig.AccountID;
// Load all of the records in the table
let result = await table.selectRecordsAsync();
// Find every record we need to update
let updates = [];
for (let record of result.records) {
let recordValue = record.getCellValue('Account');
if(recordValue && recordValue[0].id == inputValue) {
updates.push({
id: record.id,
fields: {
["Current"]: "true",
}
});
}else {
//For all other records to have current value as null
updates.push({
id: record.id,
fields: {
["Current"]: null,
}
});
}
}
// Update records - Only up to 50 updates are allowed at one time, so do it in batches
while (updates.length > 0) {
await table.updateRecordsAsync(updates.slice(0, 50));
updates = updates.slice(50);
}