Help

Re: Script Errors: 15 mutations per second, and Slow Run-Time

Solved
Jump to Solution
1140 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Dean_Arnold
7 - App Architect
7 - App Architect

Hi there,

I adapted the below script by @Justin_Barrett. Everything was working great until I added a few hundred new records to the ‘TaskLog’ table.

The script now throws this error:
Exceeded quota of 15 mutations per second at main on line 20:

let result = await table.selectRecordsAsync()

In addition, the run time is now 23.8/30s - also an error for my purposes - as any run time that goes over say 6-seconds will make the script unusable.

Can anyone tell me exactly how to edit the script to include batch processing or another solution that will solve the two errors at hand?

Ideally, the script should be able to quickly search through thousands of records in the TaskLog table in order to mark the ones that match the Account ID from the first step of the automation (inputConfig.AccountID)

Here is the script:

// Remove all existing markers (ie make all Task Log records 'current' value null)

let TaskLogTbl = base.getTable("TaskLog");
let TaskLogRcds = await TaskLogTbl.selectRecordsAsync();
for (let record of TaskLogRcds.records) {
   
        // Change Current field value for all records to Null
        TaskLogTbl.updateRecordAsync(record, {
            "Current": null
            
        })        
    }

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 originalValue = record.getCellValue("Account");
    let recordValue = record.getCellValue("Account");

    if (recordValue == inputValue && originalValue != inputValue) {
        updates.push({
            id: record.id,
            fields: {
                ["Current"]: null,
            }
        });
    } else if (originalValue && originalValue != inputValue) {
        updates.push({
            id: record.id,
            fields: {
                ["Current"]: "1",
            }
        });
    }
}

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


1 Solution

Accepted Solutions

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

See Solution in Thread

3 Replies 3

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”

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