Anyway to make script wait to next record is updated?

Topic Labels: Scripting extentions
Jump to Solution
4153 10
Showing results for 
Search instead for 
Did you mean: 

I’m trying to make a script to make product planning easier in conjunction with the gantt chart.

I have four fields.

  1. startDate (date)
  2. endDate (formular)
  3. depended (link field to same table)
  4. lookUp (looks up the endDate via the depended link field)

In the first record I put I set a startDate and endDate gets automatically calculated based on various parameters.
in the second record link to to the first record and and the look up field looks up the above endDate, which my script then passes into the startDate and then it stops.

My problem is that I want to have a bunch of records stacked on top of each other. Set the dependency field (which job it should follow) and press a button and then it’ll pass the lookUp endates into every start date, but because the lookUp takes a little time to update, it stops after the the first date.

Is there away to make kind of make if loop over itself again and again until all dates with dependencies are filled?

const luPlanRecords = await prodView.selectRecordsAsync();


for(let record of luPlanRecords.records){
    let startDate = record.getCellValue(prodStartDate);
    let endDate = record.getCellValue(prevFinishDate)

    if(startDate !== endDate && endDate !== null ){
        await prodTable.updateRecordAsync(record, 
        {'start (vs2)': new Date(endDate)});

I’ve been playing around with a while loop, but that didn’t help me much.
Does anyone have any idea how I can solve this problem?

10 Replies 10

Thank you @Jeremy_Oglesby and thank you for the advise - I’ll try to keep my queries out of my loops, its just so tempting… :grimacing:

For some reason my brain have been fixating on working with the look up that I completely blocked out better ways.
Basically I just want the calculated end-date of the above record passed in as a start date in the below record.
It’s a small script for the Gaant chart block. Instead of using dependencies I just want to quickly stack a bunch of records. Put a startDate in the first record click a button and then have the script to calculate all the other start and end dates based upon a few different parameters.

As you point out I assume I can just save the endDate Value outside the loop and use it in the next iteration, or use part of the other code you helped me with the other day and grab the endDate directly from the record below.
These ways might also be more desirable as it takes out the need to use dependencies which was just one extra step to get the look up to work.