The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Restarting a flow based on specific field value change.

jazz20
Kilo Contributor

Hi,

 With 'created or updated' trigger and run trigger as 'only if not currently running', once a flow is triggered and moves into 'wait for duration of time after' state (waiting for start date) , Now if record is updated e.g. start date is updated, the flow runtime value in wait for duration step is not updated, shows original start date value.

Not sure if this is FD limitation in NY release..how can I update the runtime value or update/restart the flow with new updated record?

Thanks!

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@jazz20 

You cannot re-run the flow.

So cancel the previous context and start new one.

You can start the flow again via script possibly after update BR when Start Date is Updated

(function executeRule(current, previous /*null when async*/) {

// Add your code here

var rec = new GlideRecord('sys_flow_context');
rec.addQuery('name','Flow Name Here');
rec.addQuery('source_record', current.sys_id);
rec.addQuery('state', 'IN_PROGRESS');
rec.query();
if(rec.next()){
rec.state = 'CANCELLED';
rec.update();
}

var inputs = {};
inputs['current'] = current;   
inputs['table_name'] = current.getTableName();

// Execute the global flow called test_flow 
sn_fd.FlowAPI.executeFlow('Flow Name Here', inputs);

})(current, previous);

Refer: Scripting with Flows, Subflows, and Actions

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

7 REPLIES 7

@Ankur Bawiskar

Thanks , that fixed the cross-scope access issue. Now original flow gets cancelled but  a new flow gets started, even after removing executeFlow block.

(function executeRule(current, previous /*null when async*/) {

    // Add your code here
    var rec = new GlideRecord('sys_flow_context');
    rec.addQuery('name','Flow Name');
    rec.addQuery('source_record', current.sys_id);
    rec.addQuery('state', 'WAITING');
    rec.query();
    while(rec.next()){
        rec.state = 'CANCELLED';
        rec.update();
        gs.info('--->flow state : '+ rec.state );
    }

})(current, previous);

Hi,

Please check the flow condition is Run once.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

 

One observation here is that flow gets executed again, However, approval won't trigger again if you have any prior approver. Any thoughts, please? Thanks.

 

Regards,

Nayan