ServiceNow how to free up a flow with wait for message block by broadcasting the message
see my other post 'ServiceNow flow waiting for another flow' post http://www.cloudminus89.com/2026/07/servicenow-flow-waiting-for-another-flow.html
this mentions a community post:
in below code examples, the flow wait for message block is expecting a value of 'onboarding_flow_resume'
expanded:
option 1
if you know the workflow context, pass it
var wfcontext = <executing_context_sysid> + '';
var flowMsg = 'onboarding_flow_resume';
var res = sn_fd.FlowAPI.sendMessage(wfcontext, flowMsg, '');
option 2
if you don't know the workflow context, retrieve it using the source record sys id:
for this option, you need to pass the flow or sub flow name string
var ticketSysid ='<enter_sys_id>';
var grFlow = new GlideRecord('sys_flow_context');
grFlow.addQuery('state', 'WAITING');
grFlow.addEncodedQuery('source_record=' + ticketSysid + '^ORsource_record=' + reqplanSYSID);
grFlow.addQuery('name', '<flow or sub flow name>');
grFlow.orderByDesc('sys_created_on');
grFlow.query();
if (grFlow.next()) {
var contextId = grFlow.getUniqueValue();
var flowMsg = 'onboarding_flow_resume';
sn_fd.FlowAPI.sendMessage(contextId, flowMsg, '');
}
if you wanted to broadcast the message with parameters instead of empty string:
sn_fd.FlowAPI.sendMessage(contextId, flowMsg, JSON.stringify({
param1: "xmasDay:false",
param2: "calledFrom:BusRuleViaScriptIncl"
}));


Comments
Post a Comment