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.

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.

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

View solution in original post

14 REPLIES 14

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Nikita50 

 

https://www.servicenow.com/community/developer-forum/trigger-flow-from-script-with-inputs/m-p/244320...

 

https://www.servicenow.com/community/developer-forum/how-to-call-a-flow-from-a-workflow/td-p/2563561

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Hi @Nikita50 

 

did u check these link?

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

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/...

Glad I could help! If this solved your issue, please mark it as Helpful and Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****

Community Alums
Not applicable

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.