- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
I currently have a workflow that has a run script in it that kicks off a Flow. This is working as expected.
One question I have though....how can I pass a workflow scratchpad variable to the Flow? I know the Flow can read the inputs from the Requested Item, but how can you get a workflow scratchpad variable to the Flow?
Here is the Run Script in the Workflow that kicks off the Flow.
(function() {
try {
var inputs = {};
inputs['request_item'] = current; // GlideRecord of table: sc_req_item
inputs['table_name'] = 'sc_req_item';
// Start Asynchronously: Uncomment to run in background.
var result = sn_fd.FlowAPI.getRunner().flow('global.outlook_distribution_list').inBackground().withInputs(inputs).run();
// Execute Synchronously: Run in foreground.
//var result = sn_fd.FlowAPI.getRunner().flow('global.outlook_distribution_list').inForeground().withInputs(inputs).run();
//gs.info("RESULT OF FLOW VAR: " + result.contextId);
//The Sys ID of a flow execution (contextId)
var ritmcontextId = result.getContextId();
current.flow_context = ritmcontextId;
current.update();
} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}
var contextId = result.getContextId(); //get flow context sys_id
var fc = new GlideRecord('sys_flow_context'); //query the table sys_flow_context using the flow context sys_id to get the sys_flow_context record and populate the fields source_table and source_record
fc.addQuery('sys_id', contextId);
fc.query();
while (fc.next()) {
fc.setValue('source_table', 'sc_req_item');
fc.setValue('source_record', current.sys_id); //sys_id of the RITM on which you want to start the flow
fc.update();
}
})();
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
if you are creating a flow then flow can't accept any input
You can create subflow and pass input to that subflow and then use it in your subflow.
Scripting with Flows, Subflows, and Actions
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Scratchpad variable from workflow can be used in Sub flow. Check below service now doc link:
Pass a variable from a workflow to a subflow
Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.