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

How to pass value of catalog variables to the flow?

 

Hi,
You can pass the catalog variables like the following example:

(function() {
    try {
        var inputs = {};
        // 1. Pass the current record (the RITM)
        inputs['record'] = current;
        
        // 2. Access the catalog variables and add them to the inputs object.
        // To pass a single-line text variable named 'requester_email':
        inputs['user_email'] = current.variables.requester_email;
        
        // To pass a reference variable named 'new_laptop_model':
        // For reference variables, you often need the sys_id:
        inputs['laptop_sys_id'] = current.variables.new_laptop_model.sys_id;
        
        // If your flow input is expecting the Display Value (string):
        // inputs['laptop_display_name'] = current.variables.new_laptop_model.getDisplayValue();

        var flowName = 'global.your_flow_name';
        var result = sn_fd.FlowAPI.getRunner().flow(flowName).inForeground().withInputs(inputs).run();
        
    } catch (ex) {
        var message = ex.getMessage();
        gs.error('Error calling flow from workflow: ' + message);
    }
})();

 

@Nikita50 - try calling subflow from the workflow, i did this in our project-

 

Screenshot 2025-09-08 at 14.46.49.png

 

script: 

 try {
       var inputs = {};
       inputs['task_sys_id'] = current.sys_id.toString();
       inputs['task_number'] = current.number.toString();
       inputs['jira_issue_key'] = current.correlation_id.toString();
       inputs['change_summary'] = 'Task deactivated - Current State: ' + currentStateDisplay;
       inputs['state_details'] = currentStateDisplay;
       inputs['updated_by'] = gs.getUserName();
       inputs['updated_on'] = new GlideDateTime().getDisplayValue();
       
       // Start the subflow
       var result = sn_fd.FlowAPI.getRunner()
           .subflow('global.sc_task_to_jira_state_sync')
           .inForeground()
           .withInputs(inputs)
           .run();
           
       var outputs = result.getOutputs();
       gs.info('Jira state sync subflow triggered for task: ' + current.number + 
               ' (Deactivated - State: ' + currentStateDisplay + ') by user: ' + gs.getUserName());
               
   } catch (ex) {
       var message = "Error occurred in Jira state sync: " + ex;
       gs.error(message);
   }

 

Just make sure you create all the inputs for the subflow and use it in the script as inputs['subflowInput'] 

 

 

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*****

Ankur Bawiskar
Tera Patron
Tera Patron

@Nikita50 

are you calling flow or 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

 Calling flow from workflow using Run flow/subflow/action activity.