Expand my Community achievements bar.

Pass variable to Sub Workflow

Avatar

Level 2

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.

 

n235ps_0-1724942263620.png

 

 

 

n235ps_1-1724942263795.png

 

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?

 

n235ps_2-1724942263933.png

 

 

n235ps_3-1724942263662.png

 

Matthew

4 Replies

Avatar

Level 5

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

MeitMedia_0-1724949034423.png

 

 

Avatar

Level 2

Thank you Meit.

 

I set a javascript activity

 

n235ps_0-1724956046194.png

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.

 

n235ps_1-1724956120174.png

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

n235ps_2-1724956216233.png

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

Avatar

Community Advisor

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
     Find me on LinkedIn

Avatar

Level 2

I'm not able to pull in instance variables in the sub workflow or a javascript activity in either location for code.

 

Matthew