How to get the Flow sys_id (sys_flow_context.sys_id) from the trigger record sys_id?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2019 01:37 PM
In a background script editor, I successfully ran the following methods to cancel a Flow Designer workflow:
var gpa = new sn_ph.GlideProcessAutomation('91dd1c84dbc73b849aab755a8c961993');
gpa.cancel('manually cancelled');
My issue is that this method requires the sys_id of the sys_flow_context record. If I'm on the record that triggers the flow, how do I get from the trigger record to the sys_flow_context sys_id?
When I look at how sc_req_item is implemented (trying to ascertain how this was done elsewhere), it has a Flow Context field. Do I need to do the same thing - add this field? If so, then from Flow Designer, how do I retrieve the sys_flow_context sys_id of the executing workflow in order to update the trigger table Flow Context field? Also, the link between sys_flow_context and trigger record must be available somewhere for this to work in the first place so I would think creating the Flow Context field should be unnecessary.
Note: I also did a search for GlideProcessAutomation in docs.servicenow and didn't find anything.
In addition, when I check the sys_flow_context table, there are 2 fields: Source Table and Source Record, which appear to be the right fields, but unfortunately, they are empty for my existing workflows.
- Labels:
-
flow designer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2019 03:06 PM
You need to pass sys_id by querying sys_flow_context table.
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2019 07:01 PM
I may have found the answer. The table, sys_flow_plan_context_binding, appears to have this information. It has a Hash Code field, which has the trigger record sys_id and Sys Flow Context field, which has the id of the sys_flow_context record.
Regarding Sachin's post above, I'm aware that the sys_flow_context table has the contexts, my problem was how to cross walk from the trigger record sys_id to determine the sys_flow_context sys_id. My goal is to be able to cancel the workflow from the trigger record form via a UI action.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2019 08:05 PM
Hi Erik,
I couldn't find any records in sys_flow_plan_context_binding table. Do we need enable any properties to create records in this table ? Please help to get the details.
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2019 05:38 AM
I'm not sure. I didn't do anything to set it up. Note, I'm using a scoped application, not a catalog item or global scope. I hope that helps, but I'm learning here too and am not sure.