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

Erik Gunther2
Kilo Guru

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.

11 REPLIES 11

sachin_namjoshi
Kilo Patron
Kilo Patron

You need to pass sys_id by querying sys_flow_context table.

 

Regards,

Sachin

Erik Gunther2
Kilo Guru

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.

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.

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.