Expand my Community achievements bar.

SOLVED

How to use javascript variable to check condition and use in email delivery template

Avatar

Level 3

Hi,

 

I have used Javascript code to make a functional call using API. I have stored that value in a variable. Now, I'm trying to use the value to check if the value of variable is greater than static value and if yes, I want to go ahead in further step in workflow. If not, I want to end the workflow.

 

Also, I want to use the variable value in email delivery.

 

I have tried few things to do this however, I was just able to fetch variable in Javascript code block and after that, there are only errors.

 

Can anyone help with first part of question - that is, trying to check variable value against static value ?

 

test-1.JPG

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @vinay16 ,

You can use 'Advanced JavaScript Code' Activity for your use case.

ParthaSarathy_0-1680676248360.png

Copy paste the script in Advanced JS, and pass your variable value as mentioned below,

vars.variable_Value= 1000; //Pass the Variable value here
vars.staticNumber = 100; //HardCode Static value here

if(vars.variable_Value > vars.staticNumber)
{
instance.vars.variable_Value = vars.variable_Value;
task.postEvent(task.transitionByName("ok"));
}
else
{
task.postEvent(task.transitionByName("no"));
}

ParthaSarathy_1-1680676440053.png

To add the variable in Delivery,

1) Delivery > script tab,

delivery.variables._var[0].stringValue=instance.vars.variable_Value;

ParthaSarathy_2-1680676567115.png

2) Delivery > Property > Variable's tab > Add > Name: variable_Value > Ok

ParthaSarathy_3-1680676668109.png

3) Now you can call this variable in email body, Delivery Parameters > variable_Value

ParthaSarathy_4-1680676764580.png

 

 

 

View solution in original post

9 Replies

Avatar

Community Advisor

Hello @vinay16,

Take a look at this for taking variable to the delivery
https://experienceleaguecommunities.adobe.com/t5/adobe-campaign-classic-questions/how-to-display-a-w...

 

In any filtering condition you can bring the variable in by following expression

$(vars/@myvar)
$(instance/vars/@myvar)



Marcel

Avatar

Correct answer by
Community Advisor

Hi @vinay16 ,

You can use 'Advanced JavaScript Code' Activity for your use case.

ParthaSarathy_0-1680676248360.png

Copy paste the script in Advanced JS, and pass your variable value as mentioned below,

vars.variable_Value= 1000; //Pass the Variable value here
vars.staticNumber = 100; //HardCode Static value here

if(vars.variable_Value > vars.staticNumber)
{
instance.vars.variable_Value = vars.variable_Value;
task.postEvent(task.transitionByName("ok"));
}
else
{
task.postEvent(task.transitionByName("no"));
}

ParthaSarathy_1-1680676440053.png

To add the variable in Delivery,

1) Delivery > script tab,

delivery.variables._var[0].stringValue=instance.vars.variable_Value;

ParthaSarathy_2-1680676567115.png

2) Delivery > Property > Variable's tab > Add > Name: variable_Value > Ok

ParthaSarathy_3-1680676668109.png

3) Now you can call this variable in email body, Delivery Parameters > variable_Value

ParthaSarathy_4-1680676764580.png

 

 

 

Avatar

Level 3

Hi,

 

Thanks for your reply.

 

I have used "Advanced Javascript Code" and wrote the following code -

 

vars.jackpotAmount = function for fetching the value --- I was able to fetch the value.

 

After that I have used query in which I'm comparing the value of this variable against static value and I could get result out of this step as well. Also, added jackpotAmount as complementary information in this query. 

 

In delivery - I have used <% targetData.jackpotAmount %> - but I am getting empty result. I am not sure what is the reason behind that?

 

Can you please help ?

 

I have attached relevant images.test-2.JPGtest-3.JPGtest-4.jpg

Avatar

Community Advisor

If you pause delivery and run the workflow can you see that variable populated in target data?

Avatar

Level 3

I have disabled the delivery and open the delivery and I can still see the variable in target data. Did you mean to ask that?

 

If not, can you please tell me how I can check populated variable in target data after running workflow?

Avatar

Community Advisor

Hi @vinay16 ,

As you had created @jackpotAmount using enrichment, Enable 'keep the interim result' in workflow property, and run the WKF.

Now Right click the enrichment transition > display the target > You can able to cross check here whether there is any value present for @jackpotAmount

Avatar

Level 3

I was able to implement the workflow with dummy accounts and ran workflow so I was able to fetch the data that way. Thank you so much..

Avatar

Administrator

Hi @vinay16,

Were you able to resolve this query with the help of the given solutions or do you still need more help here? Do let us know. In case the given solutions were helpful, then kindly choose the one that helped you the most as the 'Correct Reply'.
Thanks!



Sukrity Wadhwa