UI Action to Cancel a Item related to a Flow

LearnerNow
Mega Guru

We started using Flow for our RITM. and we have already an UI Action that cancel the RITM. But unfortunantly it's working only for Catalog Item linked to Workflow, not to a Flow.

How can I change the script of the UI to cancel the Catalog Items related to Flow too ? as I can't find function that cancel the Flow similar to : 

var workflow = new Workflow();
workflow.cancel(current);

Hereis the UI Action script : 

find_real_file.png

1 ACCEPTED SOLUTION

Have you tried using the Flow context field on the ritm? If your UI action is running on the sc_req_item table you should just be able to do this:

var contextID = current.getValue('flow_context'); //you may have to query for this
sn_fd.FlowAPI.cancel(contextId, 'Cancellation reason.');

View solution in original post

4 REPLIES 4

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Similar to the Workflow API you can use the FlowAPI to cancel a flow using the contextID of the flow. There are some code examples in the link, but it's basically:

var contextID = 'flow context sys_id'; //you may have to query for this
sn_fd.FlowAPI.cancel(contextId, 'Cancellation reason.');

LearnerNow
Mega Guru

Hi @Brad Tilton ,

It's a great API, it will definitly help me with other issues too !

But now I can't figure out how to get the context ID related to my current RITM.

I found very little documetnation related this questionm like this imcomplete thread :

https://community.servicenow.com/community?id=community_question&sys_id=64252844db0bfb08190dfb243996...

But I still not able to find which tables to query to get the context ID of the current RITM.

 

Have you tried using the Flow context field on the ritm? If your UI action is running on the sc_req_item table you should just be able to do this:

var contextID = current.getValue('flow_context'); //you may have to query for this
sn_fd.FlowAPI.cancel(contextId, 'Cancellation reason.');

LearnerNow
Mega Guru

Yes, you're right.

I updated mu UI so it can cancel RITMs related to both Flow and WorkFlow :

find_real_file.png

 

Thanks a lot ! 🙂