Expand my Community achievements bar.

SOLVED

Calling instance variable in Query’s ‘Is included in’ operator

Avatar

Level 3

Hello everyone,

In Query I have to fetch @account is included in '111','222','333','444'

 

In my workflow the above (dynamic) values are stored in an instance variable in JavaScript before the Query.

instance.vars.dynamicVariable = "'111','222','333','444'";

 

In Query,  I have to call this instance variable, So I have used the syntax $(instance/vars/@dynamicVariable)

@account is included in $(instance/vars/@dynamicVariable)

 

But this $(instance/vars/@dynamicVariable) is getting converted to string (though I have opened editor and removed ‘ ‘ and saved the workflow again, still the expression is getting converted to string)

 

SD_11_0-1704099455218.jpeg

 

SD_11_1-1704099455220.jpeg

 

 

The same is working when I change the operator to ‘Equals to’ and the value can be read as ‘Value of parameter instance variable’. But my objective is to use ‘is included in’ operator and to make use of previous created instance variable.

SD_11_2-1704099455222.jpeg

 

 

Kindly help in fixing this. Either by making modification in instance variable or in Query!

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @SD_11,

 

you can make it work by editing the expression in the advanced section of your query activity (initialization script), as follows:

 

isahore_0-1704183726894.png

 

Inside the query editor, you can have any condition which will be overwritten by this line of code.

You can basically play around with the query expression as a string to your liking, which is either completely replace the expression as in this example, or use string replacement functions to replace sections of it.

 

The reason why your code does not work is that the "IN" (is included in) expression tries to replace the instance variable as a single value, not as a concatenation of values.

It would work if you put all the possible values into different instance variables, and then use them in the query editor comma separated. But I guess you have already explored it and it is not what you are looking for in the first place.

 

Let me know if that worked for you.

 

Regards,

Ishan

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

Hi @SD_11,

 

you can make it work by editing the expression in the advanced section of your query activity (initialization script), as follows:

 

isahore_0-1704183726894.png

 

Inside the query editor, you can have any condition which will be overwritten by this line of code.

You can basically play around with the query expression as a string to your liking, which is either completely replace the expression as in this example, or use string replacement functions to replace sections of it.

 

The reason why your code does not work is that the "IN" (is included in) expression tries to replace the instance variable as a single value, not as a concatenation of values.

It would work if you put all the possible values into different instance variables, and then use them in the query editor comma separated. But I guess you have already explored it and it is not what you are looking for in the first place.

 

Let me know if that worked for you.

 

Regards,

Ishan

Avatar

Community Advisor

Hello @SD_11,
comment from @Amine_Abedour in tech bytes 

I use it when I have a need to use the 'IN' or 'NOT IN' operator in my query.
Let's say vars/@myVar = 'A','B','D'. If I do "@col IN $(vars/@myVar)" in Adobe, it translates it as "@col IN (''A','B','D'')" which doesn't work :/.
With $noescaping, the quotes aren't added, and the query works just fine.

  You can add conditions directly in the query builder with use of $noescaping()

Marcel_Szimonisz_0-1704223278434.png

Code for it

//vars.myVar = "1,2"

$noescaping(vars/@myVar) 

 

result

Marcel_Szimonisz_1-1704223372642.png

 

You can see similar asnwers here
https://experienceleaguecommunities.adobe.com/t5/adobe-campaign-classic-questions/can-i-use-js-varia...
https://experienceleaguecommunities.adobe.com/t5/adobe-campaign-classic-questions/how-do-we-pass-mor...

 

Marcel Szimonisz

 

Avatar

Administrator

Hi @SD_11,

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