How to get a subflow return value

ty_roach
Tera Guru

In my scenario, I have two workflow's (call them A and B).

The main workflow,'A', calls the subflow 'B' (as a workflow activity). In the workflow activity where I call subflow 'B', I set the 'Map return value' to a variable that I created, called 'subflow_result'.

Workflow 'A' uses the 'Return Value Activity' to set a value based on its processing. In one path, it sets the value to be "Rejected" in the other path it sets the value to be "Approved".

In workflow 'A', immediate after the 'workflow' activity in which I call subflow 'B', I have an 'If' activity to test the result of the subflow call. Since I'm checking a variable, I've checked the advanced box in this activity and given the following script to check the variable holding the result of the subflow call:


answer = ifScript();
function ifScript() {
     gs.log("subflow result="+current.subflow_result);
     if (current.subflow_result == "Approved")
   return 'yes';
     else
   return 'no';
}


This does not seem to work. I always get "subflow result=undefined" in the log. I've tried the following combinations and none seem to work:
workflow.subflow_result
workflow.var.subflow_result
workflow.scratchpad.subflow_result

Any ideas?
3 REPLIES 3

ty_roach
Tera Guru

I think I figured it out.

I set my subflow call 'Map return value' field to be:
workflow.scratchpad.subflow_result

Then in the if-activity that follows, i reference that field.

It would still be good to know how to reference non-scratchpad variables, but at least I have a workable solution.


Emil4
Kilo Contributor

The activity writes the value from the subflow value variable to the parent scratchpad.


So it can explain why it works.


girish_deshpand
Giga Contributor

You can do it you need to set 'glide.workflow.enable_input_variables'property for this. and then use the below mentioned link to follow



http://wiki.servicenow.com/index.php?title=Using_Subflows