need fix script for cancel and restart current running flow context

siva14
Tera Contributor

Hi All,

 

we need a fix script for cancel and restart the current running flow contexts , please help me.

 

#flow context #flow designer

 

4 REPLIES 4

pablo_itguy_pl
Mega Guru

Hi,

 

Please check FlowAPI - it should give you exactly what you need.

I have used below script, it cancel the flows, but didn't start the flows

 

var flowContext = new GlideRecord('sys_flow_context');
flowContext.addEncodedQuery('name=Knowledge - Article Review^state!=COMPLETE^state!=ERROR');
flowContext.addQuery('sys_id', gr.getUniqueValue());
flowContext.query();
while (flowContext.next()) {
    sn_fd.FlowAPI.cancel(flowContext.getUniqueValue());
    sn_fd.FlowAPI.startFlow('global.knowledge__article_review');
}

Hi @siva14 ,

 

Untested code but you can try,

 

 try {
            var inputs = {};
            inputs['table_name'] = 'sc_req_item';
            inputs['request_item'] = current; 

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

            // Execute Synchronously: Run in foreground.
            //sn_fd.FlowAPI.getRunner().flow('global.test').inForeground().withInputs(inputs).run();

        } catch (ex) {
            var message = ex.getMessage();
            gs.error(message);
        }

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

Sumanth16
Kilo Patron

Hi @siva14 ,

 

Give your table name, record sysID etc and flow name

(function() { 

	var now_GR = new GlideRecord('incident'); 
	now_GR.addQuery('number', 'INC0000050'); 
	now_GR.query(); 
	if(now_GR.next()){

		// get the flow context for this INC

		var flow = new GlideRecord("sys_flow_context");
		flow.addQuery('name', 'myFlow'); // your flow name
		flow.addQuery('source_record', now_GR.getUniqueValue());
		flow.addEncodedQuery('stateINWAITING,IN_PROGRESS,QUEUED');
		flow.query();
		while(flow.next()){

			var gpa = new sn_ph.GlideProcessAutomation(flow.getValue('sys_id'));

			if (!gpa.isTerminated()) {
				//cancel the flow and provide the reason
				gpa.cancel('Cancelling this flow');
			}

		}

	}

})();

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda