Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to rerun the flow on RITM

shaik_irfan
Tera Guru

Hi,

I have a flow which got cancelled, i want to rerun the flow i see some script but its not working for me, can anyone please help me how to rerun the flow.

 

(function() { 

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

      try { 
          var inputs = {}; 
          inputs['current'] = now_GR; // GlideRecord of table: 
          inputs['table_name'] = 'sc_req_item'; 

          // Starts the flow asynchronously.
          var contextId = sn_fd.FlowAPI.startFlow('global.hardware_request', inputs); 

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

 
// Call the cancel() method using the context Id returned from the startFlow() method
sn_fd.FlowAPI.cancel(contextId, 'Flow took too long to execute.');
2 REPLIES 2

Jay Uttanoor
Tera Contributor

Found a solution that worked for me, instead of inputs['current'] had to give inputs['request_item']

hope this is helpful

(function() { 


var grScReqItem = new GlideRecord('sc_req_item');
grScReqItem.addEncodedQuery("Query");// provide a Query
grScReqItem.orderBy('sys_created_on');
grScReqItem.setLimit(1);
grScReqItem.query();
while (grScReqItem.next()) {
try {
	
	var flow = grScReqItem.cat_item.flow_designer_flow;
	var flowName = flow.sys_scope.scope + "." + flow.internal_name;
    var inputs = {};
    inputs['request_item'] = grScReqItem; // GlideRecord of table: sc_req_item
    inputs['table_name'] = 'sc_req_item';

    var contextId = sn_fd.FlowAPI.startFlow(flowName, inputs);	
	
  } catch (ex) {
    var message = ex.getMessage();
    gs.error(message);  
  }
}
})();

@Jay Uttanoor  we have to give flow name ?