How to get the Outputs to a Scripted REST API response from sub flow outputs

Lucky1
Tera Guru

Hello all,

 

In a scripted REST API, I am calling a sub flow,

 

var result = sn_fd.FlowAPI.getRunner().subflow('global.create_normal_cr').inForeground().withInputs(inputs).run();
                var output = result.getOutputs();
                gs.log("Conflict Status OP is "+output[conflict_status]);
 
 
 
I have created a custom action and created two inputs, 
1. chg_sys_id 
2. conflict_status
 Secondly, in the Script, I am glide recorded the conflict table and getting the conflict records for the created change request.
 
var gr = new GlideRecord('conflict');
gr.addQuery('change.sys_id',change_sys_id);
//gr.addEncodedQuery('change.sys_id=8c59718d3bb9e2501021a58c24e45a50'+change_sys_id);
gr.query();
gs.log("Check for conflicts ACTION Row count is "+gr.getRowCount()+gr.change+" "+change_sys_id);
if(gr.next()){
    var type = gr.type;
    gs.log("Check for conflicts ACTION Conflict type is "+type);
}
outputs.conflict_message = gr.type.toString(); // I checked the flow operations, and I am getting value as expected.
 
........................................................................................................................................................................
Now I created a sub flow, and here below are the actions in sequence I am using
1. Create Record
2. Wait for duration (10 seconds) // this is to let the conflicts run
3. Look up Record (taking the record that got created in step:1)
4. Custom action 
(as inputs to the custom action, I am passign change request sys_id and conflict_status)
5. If condition - If Conflict
6. Assign Sub flow outputs
 
Here, when I trigger the API, and check the flow operations, I see the outputs for step:6
conflict_status - CI already scheduled
 
Now My Question is, I am not able to get this output at scripted REST API, in the result of the subflow.
 
 
Can someone help me here?
 
 
 
Regards,
Lucky
 
 
In my sub flow, I have created inputs where I am passing them from Scripted REST API
and then 
3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Lucky1 

you are calling subflow from scripted REST API and using foreground run

then you can access the subflow outputs directly

Assigning Subflow Outputs 

flow designer - How to use subflow outputs in flow script 

something like this

// Get the subflow runner
var flowAPI = new sn_fd.FlowAPI();

// Define inputs (if any)
var inputs = {
  "input_field_1": "value_1",
  "input_field_2": "value_2"
};

// Execute the subflow synchronously
var result = flowAPI.getRunner().subflow('my_subflow_name').inForeground().withInputs(inputs).run();

// Access the outputs
var outputs = result.getOutputs();

// Use the outputs
gs.info(outputs.output_field_1); // Example: Accessing an output variable
gs.info(outputs.output_field_2);

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

Hello ANkur,

 

Yes, I am calling in the same way you showed in the script.

But I am not getting outputs in the log messages.

 

 

Regards,

Lucky

@Lucky1 

then it means you have not configured any output variable

share your subflow how outputs are configured

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