Access the context sys_id from inside the running workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2023 03:11 PM
I am using a Parallel Flow Launcher in my parent flow, based on sc_req_item. Within the triggered subflow, I need to access the context associated to the subflow. There are multiple Parallel Flow Launchers at different points in the parent, so I need to be able to identify the one that is running. I don't want to rely on doing an active query search:
var ctxt = new GlideRecord("wf_context");
ctxt.addActiveQuery();
ctxt.addQuery("id", wfRelRecId); <== this is essentially current.sys_id
ctxt.addQuery("workflow_version.name", wfName);
ctxt.query();
This is currently working, but I would rather just get the active context directly:
var ctxt = new GlideRecord("wf_context");
ctxt.get(activeContextSysId);
Is there an object or variable within the workflow, or in the WorkflowCoordinator/Parallel Flow Launcher, that holds the currently running context sys_id?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2023 04:08 PM
Ugh... been a few years since I've had to do this. I believe I configured it as a parameter that was passed to the Parallel flow launcher... NOT something I calculated from within.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2023 01:42 PM
Robert,
Thanks for the quick reply. I would love to compare notes with how you did this, but you set me on a path.
In my subflow, I added an input variable called u_workflow_instance_id and in the coordinator I set that variable to
gs.generateGUID()
Then, in the subflow I query wf_context for a context with that variable value
var gr = new GlideRecord('wf_context');
gr.query();
while(gr.next()){
if(gr.workflow.vars.u_workflow_instance_id == workflow.inputs.u_workflow_instance_id){
workflow.scratchpad.subflow_context_sys_id = gr.sys_id.toString();
}
}
And now I have the sys_id of the context that the subflow is running as. Does that look like something you might have done?