Cancel and re-run flow designer on a record by script

Moncef1
Kilo Contributor

Hello, 

In my case i have a workflow who runs on a record waiting for condition, i want to cancel the excecution of this flow designer when a field changes and re-run it from the begining.

How can i proceed ? 

Thank you.

7 REPLIES 7

Muralidharan BS
Mega Sage
Mega Sage

HI Moncef,

Open the flow and click on the 3 dots you will get code snippet which will help you to trigger the flow for a record. 

To Trigger

inputs['table_name'] = 'sc_req_item';
inputs['request_item'] = 'ritm001'

// Start Asynchronously: Uncomment to run in background.
sn_fd.FlowAPI.getRunner().flow('global.flowname').inBackground().withInputs(inputs).run();

 

To cancel

sn_fd.FlowAPI.cancel(contextId, 'cancelled');

 

API details here - https://docs.servicenow.com/bundle/orlando-application-development/page/app-store/dev_portal/API_ref...

 

Thanks

Hello Murali, 

I want to cancel and re-run it after a field change.

Do you have any ideas ?

Thank you.

HI Moncef,

Instead of cancelling the flow, try to create another flow and use trigger condition - update a record

then jot down your actions. this may work for you. But if you had any approvals in the first flow, then you have to consider adding actions to cancel them. 

Thanks

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Moncef,

Can you explain your business use-case here?

you need to re-run the flow using a script.

but you have mentioned that you have workflow which runs on that record.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader