Pass variable to Sub Workflow | Community
Skip to main content
Level 2
August 29, 2024
Question

Pass variable to Sub Workflow

  • August 29, 2024
  • 1 reply
  • 905 views

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

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

1 reply

MeitMedia
Level 4
August 29, 2024

Hi @n235ps ,

 

In the Configuration script section of the Sub-workflow activity, you can try to add the following code to pull the instance.operation.internalName:

// Retrieve the internal name of the campaign vars.internalName = instance.operation.internalName; // Now, you can use vars.internalName in the subworkflow to perform operations.

You can now reference vars.internalName anywhere within the subworkflow to build queries or generate reports.
Example Query:

var query = xtk.queryDef.create( <queryDef schema="nms:delivery" operation="select"> <select> <node expr="@internalName"/> </select> <where> <condition expr={"[operation/@internalName]='"+vars.internalName+"'"}/> </where> </queryDef> ); var result = query.ExecuteQuery(); // Further processing to build the report

 

Best regards,

MEIT MEDIA (https://www.meitmedia.com)

Find us on LinkedIn

Contact Us: infomeitmedia@gmail.com

 

 

n235psAuthor
Level 2
August 29, 2024

Thank you Meit.

 

I set a javascript activity

 

and added the code with a command to print to the log.

 

// Retrieve the internal name of the campaign
vars.internalName = instance.operation.internalName;
logInfo("raw internal name: " + instance.operation.internalName);
logInfo("campaign internal name master: " + vars.internalName);
// Now, you can use vars.internalName in the subworkflow to perform operations.

 

but I'm not getting a value for the campaign internal name as seen in the log.

Seems pretty straight forward and should be easy. What am I doing wrong?

Manoj_Kumar
Community Advisor
Community Advisor
August 30, 2024

Hello @n235ps  Use the code in advanced tab of jump activity in sub workflow and it will work.

 

logInfo("campaign internal name master: " + vars.internalName);

Manoj  | https://themartech.pro