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
Solved! Go to Solution.
Views
Replies
Total Likes
Hello @dwnuk
Follow these steps:
delivery.variables._var[0].stringValue=instance.vars.arrayForDelivery;
You were missing point no 3.
Let me know if it works.
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
Views
Replies
Total Likes
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: 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?
Views
Replies
Total Likes
Hello @dwnuk
Follow these steps:
delivery.variables._var[0].stringValue=instance.vars.arrayForDelivery;
You were missing point no 3.
Let me know if it works.
Thank you both for help. Adding the code from point #3 solved the issue.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies