Expand my Community achievements bar.

Announcing the launch of new sub-community for Campaign Web UI to cater specifically to the needs of Campaign Web UI users!
SOLVED

Store an array in variable, pass it and display in delivery

Avatar

Level 3

Hi,

I have a workflow that is built from Query activity, Advanced Javascript and delivery. For each recipient from the query I am doing calculations in Advanced JS activity and it returns an array. Its length may be different - from 1 element to 5.

 

So for example, in JS activity after I'm done with all business logic I save the array (myArray) to instance.vars:

var myArray = [1, 50, 100];
instance.vars.arrayForDelivery = myArray;

Let's assume that I want to have each element in a separate paragraph:

<% for (var i=0; i < (arrayForDelivery.length - 1); i++) { %> 
<p>instance.vars.arrayForDelivery[i]</p>
<%}%>

What should be done next, in the delivery, to loop through all arrayForDelivery elements? The code above is just example because it seems to not be working.

 

Best,

Dominik

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hello @dwnuk 

 

Follow these steps:

  1. Open your delivery properties and create a string variable there. Let's call it arrayForDelivery. Select the data type as a string.
  2. Now in your workflow, use the Delivery activity from the Action tab.
  3. In the script tab of the Delivery activity, use this code
    delivery.variables._var[0].stringValue=instance.vars.arrayForDelivery;​
  4. Now in the delivery, you will have access to this data using variables.arrayForDelivery

 

You were missing point no 3.

 

Let me know if it works.

 


     Manoj
     Find me on LinkedIn

View solution in original post

4 Replies

Avatar

Community Advisor

Hi @dwnuk ,

 

I see you have almost completed most of the tasks required here and now you can do as such to display these arrayBlocks in the delivery.

 

Step 1: Create an Html variable with labels such as:

var deliveryVar = "";
deliveryVar += "<table id=t01 border=0>";                                                               // Table header
deliveryVar += "  <tr><th colspan=7><h2><u>Array List</u></h2></th></tr>";
deliveryVar += "  <br>";
deliveryVar += "  <tr>";
deliveryVar += "    <th align='left'>My arrays</th>";
deliveryVar += "  </tr>";

 

Step 2: Keep storing the values of Arrays in this variable with a loop, such as:

for (var i=0; i < (arrayForDelivery.length - 1); i++) {        
            deliveryVar += "  <tr>";  
            deliveryVar += "    <td>" +   instance.vars.arrayForDelivery[i]  + </td>";
            deliveryVar += "  </tr>";
          };

Once all the loop runs the HTML variable will have all the array values stored in Html table rows. 

 

Step 3: Covert the HtmlVariable to instance variable:

vars.deliveryHtml = deliveryVar;

 

Step 4: Place this Html variable in your delivery wherever you like.

<P><%= vars.deliveryHtml %></P>

 

P.S. As I used the variables as per your query so there might be syntax errors above which can be easily solved when testing, but I hope you got the idea how it can done!

 

Br,

Shubham

Avatar

Level 3

Thanks @Shubham_Goyal__, indeed I can pass in from one activity to another. However, I have a strange issue when I try to use the variable inside the delivery. 

 "Error while compiling script 'content htmlContent' line 4: vars is not defined. SCR-160012 Javascript&colon; error while evaluating script 'content htmlContent'."

I have added additional javascript activity in between Advanced one and delivery. I can ready variable in it but it throws the error in delivery:

1. Advanced JS: save to vars (or instance.vars) and log to console -> works

2. Javascript activity: read vars (or instance.vars) -> works, I can see variable

3. Delivery: the error

 

Any clue what's wrong?

Avatar

Correct answer by
Community Advisor

Hello @dwnuk 

 

Follow these steps:

  1. Open your delivery properties and create a string variable there. Let's call it arrayForDelivery. Select the data type as a string.
  2. Now in your workflow, use the Delivery activity from the Action tab.
  3. In the script tab of the Delivery activity, use this code
    delivery.variables._var[0].stringValue=instance.vars.arrayForDelivery;​
  4. Now in the delivery, you will have access to this data using variables.arrayForDelivery

 

You were missing point no 3.

 

Let me know if it works.

 


     Manoj
     Find me on LinkedIn

Avatar

Level 3

Thank you both for help. Adding the code from point #3 solved the issue.