Help

The Community will be temporarily unavailable starting on Friday February 28. We’ll be back as soon as we can! To learn more, check out our Announcements blog post.

Script exceeded max cpu time of 1000 milliseconds

1436 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Ali_Ahmed
5 - Automation Enthusiast
5 - Automation Enthusiast

I know about the restriction related with max CPU time (“Scripts can use a maximum of 1 second of CPU time”). I created a script that runs into automation section, in 95% of times, it runs using less than 500 miliseconds of CPU time but sometimes it exceeds the 1000 miliseconds.

Screen Shot 2020-09-09 at 11.10.31 AM

I dont think so but I need try: there is an way (even paying more) to get more time?
If it is not possible, what is the best approach to try reduce the time? I mean, what is the part of the code that are “more CPU time consuming” for Airtable perpective?

let users = base.getTable('CoreVette');
let reps = base.getTable('Reps');
let refs = base.getTable('References');

let inputConfig = input.config();
let newRecordId = inputConfig["recordId"];

let repsResult = await reps.selectRecordsAsync();
let repsStorage = {};
for (let recordRep of repsResult.records) {
    repsStorage[recordRep.getCellValue('Email')] = recordRep.getCellValue('Manufacturer');
}

let refsResult = await refs.selectRecordsAsync();
let refsStorage = {},
    ptAux = '',
    refAux = '';

for (let recordRef of refsResult.records) {
    ptAux = recordRef.getCellValue('PT VALUE');
    if (ptAux == null) {
        ptAux = '';
    }
    refAux = recordRef.getCellValue('LIST OR TYPE');
    if (refAux == null) {
        refAux = '';
    }
    refsStorage[recordRef.getCellValue('DOMAIN')] = {
        'point': ptAux,
        'reference': refAux
    };
}

let result = await users.selectRecordsAsync();

let flagUpdate = false,
    objectToUpdate = {},
    domain = '',
    email = '',
    manufacturer = '',
    refValue = '',
    pointValue = '';

for (let record of result.records) {

    if (record.id == newRecordId && record.getCellValue('Email')) {
        domain = record.getCellValue('Domain');
        email = record.getCellValue('Email');
    
        flagUpdate = false;
        objectToUpdate = {};
        
        if (typeof repsStorage[email] != "undefined") {
            manufacturer = repsStorage[email];
            if (typeof manufacturer != "undefined") {
                objectToUpdate['Rep Mfr'] = manufacturer;
                flagUpdate = true;
            }
        }
    
        if (typeof refsStorage[domain] != "undefined" && refsStorage[domain]) {
            refValue = refsStorage[domain]['reference'];
            pointValue = refsStorage[domain]['point'];

            if (typeof refValue != "undefined") {
                objectToUpdate['References'] = refValue;
                flagUpdate = true;
            }

            if (typeof pointValue != "undefined") {
                objectToUpdate['Point Value'] = pointValue;
                flagUpdate = true;
            }
        }

        if (flagUpdate) {
            await users.updateRecordAsync(record, objectToUpdate);
        }
    }
}
1 Reply 1

I answered this in your other post on the same topic.