Help

Re: Help with Automation Script Time Out

1495 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Michael_Andrew
7 - App Architect
7 - App Architect

I am looking for suggestions to change my script so that it does not time out. My script is below. Basically when a new record enters a view on a Table A (‘Verifier Bodies’), I want to update another Table B (‘Technical Comments for VB’) by linking all the records in that view in Table A to records in the view on Table B. The script below ‘works’, but is now timing out due to the number of records. I think I need to make a change so that just the new record is added to the field ‘Verifier Body List’ in Table B without overwriting the already linked records. How would I go about that? Any help is appreciated.

let TBTable = base.getTable(“Technical Comments for VB”);

let TBView = TBTable.getView(‘General Share for VB’)

let TBQuery = await TBView.selectRecordsAsync();

let TBRecord = TBQuery.records;

let VBTable = base.getTable(“Verifier Bodies”);

let VBView = VBTable.getView(‘List of SLCP for Higg Co.’)

let VBQuery = await VBView.selectRecordsAsync();

let VBRecords = VBQuery.records;

let d = []

VBRecords.forEach(c => d.push({id: c.id}));

TBRecord.forEach(x => {TBTable.updateRecordAsync(x.id, {‘Verifier Body List’: d})})

8 Replies 8

You are updating records one at a time with updateRecordAsync. You can speed up the process by updating records in a batch process with updateRecordsAsync, note the s at the end of records.

Michael_Andrew
7 - App Architect
7 - App Architect

How does that alter the code? I don’t think I can just put the ‘s’ in as the this will have an error.

image

You create an array to hold all of the updates, and then submit the requests in batches of 50. The “Find and Replace” example script in the documentation gives one example of how to do this.

Thanks for your advice. I am reading and trying things, but can’t get it. I’m not a coder and don’t know JS. I’m basically learning by trial and error, but it’s almost all error. Any additional help on the code would be greatly appreciated.

Hi @kuovonne ,

I do not (yet) index automatically then search this Scripting App Community .json by best relevance criteria but it seems to me that I have a big big internal index of this Scripting App Com., somewhere inside my brain. :grinning_face_with_smiling_eyes:

Do you think this (that was published 1 month after Scripting (Block) App non-Beta release) should be relevant in context of Automation Script ?

Sorry not to try by myself but I’m now in a GAS scripting (2) time although I continue to follow you and Bill here on a daily base.

oLπ

Welcome to the world of coding! Learning to code is like learning a new language and culture at the same time. When you learn a new language, you don’t start by writing an essay (a whole program). You start by writing simple sentences and gradually building up. If you’re having lots of errors, I recommend taking a step back and writing something smaller, something where you understand all of the parts. Then, gradually add one thing at a time as you learn each new thing.

You could also try a “learn to code” class. There are many courses on the internet, including free and paid courses. Understand the basic data structures and syntax of JavaScript will make it easier to mix in those concepts with Airtable concepts…


In particular, instead of calling updateRecordAsync in this line

TBRecord.forEach(x => {TBTable.updateRecordAsync(x.id, {‘Verifier Body List’: d})})

Use TBRecord.map() to map the array to a new array of updates. Then submit the new array to TBTable.updateRecordsAsync()

By the way TBRecord is a bit of a misleading name, as it implies that there is only one record. However it looks like the variable is an array of records.

let TBRecord = TBQuery.records;

I personally don’t use a batching function like the one in that thread., as I prefer to simply include the “while” statement directly in my functions. However, that script should work just fine inside an automation script. One the other hand, I don’t think that that script is applicable to this system. That script assumes that you already have an array of updates, but the original script in this thread does not have an array of updates.

Hi @kuovonne,

Thank you for your detailed answer,

olπ