Best way to pass variables or parameters to a sub-workflow? | Community
Skip to main content
Level 2
February 12, 2021
Solved

Best way to pass variables or parameters to a sub-workflow?

  • February 12, 2021
  • 2 replies
  • 2128 views

I am attempting to create shared (sub) workflows which other users could reuse them to do common tasks. What would be the best/proper way to pass variables that would work as parameters to these sub-workflows?

 

Atm I am using instance variables, but I have a major issues with it. The following workflow, for example:

 

Both sub-workflows use the instance.vars.parameter. Internally, on my sub-workflow, I would build a logic that halts the execution if the variable/parameter is not properly set. But, if the user forgets to set it on the second fork path, it will use the same instance.vars.parameter value of the first fork path.

 

Does anyone have any suggestions on how to approach it?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Jonathon_wodnicki

Hi,

 

AFAIK it's just instance.vars available to sub-workflow, though can also use xtk:option with get/setOption().

Set a diff parameter for each path?

 

Thanks,

-Jon

2 replies

Jonathon_wodnicki
Community Advisor
Jonathon_wodnickiCommunity AdvisorAccepted solution
Community Advisor
February 16, 2021

Hi,

 

AFAIK it's just instance.vars available to sub-workflow, though can also use xtk:option with get/setOption().

Set a diff parameter for each path?

 

Thanks,

-Jon

AdrianESanchez
Level 2
November 28, 2022

Considering the workflow description field

As a sub-workflow is not going to be "readable" but the template, I propose another solution for the description field.


Using the sub-workflow activity, place your configuration code as JSON:

subWorkflow.desc = JSON.stringify({ myVariable: "some value" });


Then within the workflow template (sub-workflow) read that config from the description field:

var wkfConfig = JSON.parse(instance.desc);

 


Regards.

 

 

Level 2
August 23, 2024

I tried this approach and it did not work for me. 

 

I would like to call a subworkflow from a campaign, send the campaign internal name to the subworkflow, and pull that into the subworkflow query which builds a report for that campaign that was passed to it.

 

 

 

What code can I add to the subworkflow script that would pull instance.operation.internalName

 

and then what code do I need in the Javascript activity in the subworkflow to pull out that internal name and pass it to the query?

 

 

Matthew