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
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

@Ankur Bawiskar I am working with scoped app and with the above script, get error 'access to api 'put(sys_flow_context.state) from scope<xx> has been refused due to the api's cross-scope access policy. What needs to be changed to make it work from a scoped app?

@jazz20 

create restricted caller access record

1) left nav type Restricted caller

2) create new record

3) Give source scope as your Custom Scope and details as per image below

find_real_file.png

Regards
Ankur

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

@jazz20 

Hope you are doing good.

Did my reply answer your question?

If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.

Thanks!
Ankur

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