Hello everyone,
About one week ago, we started seeing more and more of this “Script exceeded max CPU time” error.
I looked at the code and don’t see “major performance flaws”. (but I am not an expert with JS and I might be doing something wrong without noticing)
I looked at @Bill.French race condition suggestion but cannot see one here.
I also checked that I wasn’t doing a “single update” multiple times. (@kuovonne recommendation on another thread)
Can anyone help me find some ways to optimize this script ?
let config = input.config();
let triggeredRecordId = config.RECORD_ID;
let candidateEmail = config.EMAIL;
let jobId = config.JOB[0];
let applicationsTable = await base.getTable("Applications");
let query = await applicationsTable.selectRecordsAsync();
let records = query.records;
let recordsWithSameEmailAndJob =
records
.filter(
filterOlderApplications
);
function filterOlderApplications(a) {
let currentRecEmail = a.getCellValueAsString("Email");
let currentJobs = a.getCellValue("Job");
if (currentJobs === null || currentJobs === undefined || currentJobs.length === 0) return false;
let currentRecJob = currentJobs[0].id;
let currentRecId = a.id;
let isSameApplication = currentRecEmail === candidateEmail
&& currentRecJob === jobId
&& currentRecId !== triggeredRecordId;
if (isSameApplication) console.log(isSameApplication);
return isSameApplication;
}
let recordsUpdate = recordsWithSameEmailAndJob.map(r => {
return {
"id": r.id,
"fields": {
"Is not last version": true
}
}
});
let updated = await applicationsTable.updateRecordsAsync(recordsUpdate);
Thank you !
Florian
