Setting up inputs & outputs for subflow

Tara Bauch
Tera Contributor

I have a workflow that needs to call in an approval subflow, but I'm unsure how to set up the outputs. The subflow input uses a reference field and calls up the catalog service request that needs to get approval, but what would my outputs look like? I watched a couple of videos and it looks like the approval state is usually set up as a string so I set up "approved" and "rejected" and then assigned subflow outputs based on that (see the pictures for reference). The error that the regular flow throw up when it gets to this subflow references a "null" value. Maybe I need to set up outputs for all the approval state choices? Or maybe it should be a choice type rather than string and reference the approval table? Can someone help me figure out how to get this set up correctly so that the approval subflow correctly passes the approval to the main flow? Thanks! 

outputs.PNG

assign approve outputs.PNG

assign reject outputs.PNG

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

Hi Tara,

I can't tell from your screenshots and description if this is a workflow that you created in the Workflow Editor, or a flow that uses Flow Designer.  Here is an example in workflow. 

 

The sub-flow is called in a Workflow Instance activity which is created by dragging the sub-flow name from the Workflows list onto the canvas.  This activity notes the name of the workflow (sub-flow) to execute, and a return value that can be mapped to a scratchpad variable

BradBowman_0-1666628221507.png

In the sub-flow, you have a Return Value activity for approved, and one for rejected on paths that come from the Approval activity  Approved and Rejected conditions.

BradBowman_1-1666628345173.png

Then back on the main workflow, the Workflow Instance activity leads to an If activity to determine if the return value is approved or rejected

answer = ifScript();

function ifScript() {
	if (workflow.scratchpad.approval_result == 'approved') {
		return 'yes';
    }
		return 'no';
}

 

Tara Bauch
Tera Contributor

Hi Brad, 

Sorry about that - it's in Flow Designer. And I have no experience in using/writing scripts or the scratchpad - I just started using ServiceNow in March and our organization had just moved to Flow Designer so I also didn't have any experience working in the older Workflow version. But it looks like based on what you're saying here, I just need to put it together with True/False - with approved returning "true", and rejected returning "false"? As well as if there's any of the other approval stage choices - those need to return "no" to the main workflow if they're selected. Conceptually that seems like it would work as I think through it. Let me know if I'm at all on the right path! Thanks for your response ðŸ˜Š

That seems like it's the right direction, but unfortunately I don't have any experience with Flow Designer to know how to accomplish this in there.