Flow restart for custom table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2024 05:22 AM
Hi Everyone,
I have an custom table that runs on Flow Designer. Now, I want to cancel the flow and restart the flow again, when user changes the "approver" field on the form. I have created the before "update" business rule and it's working as expected. But, the issue is Flow trigger only when record is "CREATED".
The BR script canceling the flow and it's attached the new flow. But during the new flow attached time the flow gets "completed" at action level. How to over come this situation? Can you please help me on this?
Business Rule: Change request
condition; Approver "chnages"
script:
(function executeRule(current, previous /*null when async*/) {
gs.info("Business rule started");
var now_GR = new GlideRecord("sys_flow_context");
now_GR.addQuery("name", "C2MT SSB Change request"); // flow designer name
now_GR.addQuery("source_record", current.sys_id);
now_GR.query();
while (now_GR.next()) {
gs.info("Cancelling flow: " + now_GR.getUniqueValue());
sn_fd.FlowAPI.cancel(now_GR.getUniqueValue(), 'C2MT SSB Change request'); // flow designer name
}
try{
var inputs = {};
inputs['table_name'] = "u_ssb_change_request";
gs.info("Inputs for new flow: " + JSON.stringify(inputs));
var contextId = sn_fd.FlowAPI.startFlow('global.c2mt_ssb_change_request', inputs);
gs.info("New flow started with context ID: " + contextId);
var grFlowcontect = new GlideRecord("sys_flow_context");
if(grFlowcontect.get(contextId)){
grFlowcontect.source_table = "u_ssb_change_request";
grFlowcontect.source_record = current.sys_id.toString();
grFlowcontect.update();
gs.info("Flow context updated for record: " + current.sys_id);
}
}
catch (ex){
var message = ex.getMessage();
gs.error("Error Message: " + message);
gs.error("Full Exception: " + ex);
}
gs.info("Business rule ended");
})(current, previous);
Thanks,
Rajesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2024 05:28 AM
@Rajesh Bandila According to this support article https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0855865 you should delete the previous flow context and let the new flow context trigger on the update operation.