Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Using "Do the following in parallel" into a loop "do the following until"

CKJ-BeOS
Tera Contributor

Hi,

 

I try to do a loo where i want to execute one action if a sc_task is updated OR if 2 minutes is passed

but repeat 5 times.

When le loop is executed one time and passed on one branch of the "do the following in parallel" it not wait a second time in the branch where the wait.

I think when used a "Do the following in parallel" it's only execute one time the branch, not execute a second time.

But need to find solution to loop until a task is updated or 2 minutes passed and execute the "wait 2 minutes" only 5 times.

 

Regards,

Cédric

7 REPLIES 7

Sarthak Kashyap
Kilo Sage

Hi @CKJ-BeOS ,

 

I create a sample script for you please check 

 

var taskSysId = '46c5cd93938932d09305f520ed03d60a'; // your sc_task sys_id
var maxAttempts = 5;
var intervalMs = 2 * 60 * 1000; // 2 minutes in milliseconds
var updated = false;

for (var i = 0; i < maxAttempts; i++) {

    var task = new GlideRecord('sc_task');
    if (task.get(taskSysId)) {
        if (task.state == 3 || task.u_your_field == 'done') { // your sample condition
            gs.info('Task updated - exiting loop.');
            updated = true;
            break;
        }
    }

    gs.info('Attempt ' + (i + 1) + ': not updated, waiting 2 minutes');
    gs.sleep(intervalMs);
}

if (!updated) {
    gs.info('Task not updated after 5 attempts (10 minutes total).');
}

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards,

Sarthak

hi @Sarthak Kashyap,

thanks, but i would like to do without scripting if possible, only using Flow Designer

CKJ-BeOS
Tera Contributor

@Ankur Bawiskar @Sarthak Kashyap 

finally i find a solution by using Two subflkow

the first contain a Loop waiting the task is closed

the second contain only a Parallel executing :

- a wait on update task

- 2 minutes

i put here my two sublow need to obtain result

Capture d’écran 2025-11-12 à 17.41.28.pngCapture d’écran 2025-11-12 à 17.41.52.png