Call Flow from Workflow

Nikita50
Tera Expert

Hi All,

 

I am trying to call a flow from workflow using Run flow/subflow/action activity. Flow name has been added but on running the flow i am getting following error.

 

Nikita50_0-1757324181528.png

Nikita50_1-1757324322550.png

Please assit.

 

1 ACCEPTED SOLUTION

@Nikita50 

that doesn't answer the above question.

Are you calling flow or subflow?

If you are calling subflow then what input it's asking? are you sending that ?

share the screenshots of your subflow

If my response helped please mark it correct and close the thread so that it benefits future readers.

View solution in original post

14 REPLIES 14

Hi @Nikita50 

 

did u check these link?

Ajay_Chavan
Kilo Sage

@Nikita50 

 

Please use run script activity in workflow to start the flow 

user startFlow function

here is the sample code:

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

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

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

 

 

Link: https://www.servicenow.com/docs/bundle/zurich-api-reference/page/app-store/dev_portal/API_reference/...

miftikhar20
Kilo Patron

Hi @Nikita50 ,

You can call a flow from a workflow using "Run Script" activity and the sn_fd.FlowAPI class.

Follow the steps mentioned below:

 

  1. Add a "Run Script" activity: In your Workflow, drag a "Run Script" activity from the Core tab on the palette.

  2. Write the script: Inside the script editor, you'll use the sn_fd.FlowAPI to trigger the Flow.

 

(function() {
    try {
        // Define the inputs for your flow
        var inputs = {};
        inputs['table_name'] = current.getTableName(); 
        inputs['record'] = current; // Pass the current record (e.g., sc_req_item)
        
        // Replace 'global.your_flow_name' with the actual scope and name of your Flow.
        var flowName = 'global.your_flow_name';
        
        // Run the flow synchronously. This will make the workflow wait for the flow to complete.
        // Use .inBackground() instead of .inForeground() if you want the flow to run asynchronously.
        var result = sn_fd.FlowAPI.getRunner().flow(flowName).inForeground().withInputs(inputs).run();
        
        // If you need to check the result or use a value returned by the flow, you can do so here. For example:
        // var outputs = result.getOutputs();
        // workflow.scratchpad.flow_result = outputs.your_output_variable;

    } catch (ex) {
        var message = ex.getMessage();
        gs.error('Error calling flow from workflow: ' + message);
    }
})();


Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.