Skip to main content

ServiceNow how to free up a flow with wait for message block by broadcasting the message

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:

https://www.servicenow.com/community/developer-blog/sending-message-to-an-active-flow-from-outside-of-context/ba-p/3194739 


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

Popular posts from this blog

URL link in addInfoMessage

var ga=new GlideAjax('gld_HR_ajax'); ga.addParam('sysparm_name', 'checkEmployeeNumber_hrProfile'); ga.addParam('sysparm_hrprofilenumber', g_form.getValue('number')); ga.addParam('sysparm_employeenumber', newValue); ga.getXMLAnswer(function(answer) { if (answer!='undefined' && answer!=''){ var navURL="<a style='text-decoration:underline;color:blue' href=hr_profile.do?sysparm_query=number=" + answer + ">" + answer + "</a><img width='3' src='images/s.gif'/>"; var sMsg='The employee number entered already exists on another HR Profile ' + navURL; //alert(sMsg); g_form.showErrorBox('employee_number', 'error - please check'); g_form.addInfoMessage(sMsg); } });

ServiceNow check for null or nil or empty (or not)

Haven't tested these all recently within global/local scopes, so feel free to have a play! option 1 use an encoded query embedded in the GlideRecord , e.g.  var grProf = new GlideRecord ( 'x_cls_clear_skye_i_profile' ); grProf . addQuery ( 'status=1^ owner=NULL ' ); grProf . query (); even better use the glideRecord  addNotNullQuery or addNullQuery option 2 JSUtil.nil / notNil (this might be the most powerful. See this link ) example: if ( current . operation () == 'insert' && JSUtil . notNil ( current . parent ) && ! current . work_effort . nil ())  option 3 there might be times when you need to get inside the GlideRecord and perform the check there, for example if the code goes down 2 optional routes depending on null / not null can use gs.nil : var grAppr = new GlideRecord ( 'sysapproval_approver' ); var grUser = new GlideRecord ( 'sys_user' ); if ( grUser . get ( 'sys_id' , current . approver )){...