Dynamic coding with multiple values | Community
Skip to main content
Level 3
September 26, 2017

Dynamic coding with multiple values

  • September 26, 2017
  • 3 replies
  • 5845 views

What is the proper way to handle dynamic coding with multiple values?

Should we add an IN statement to syntax?

(  targetData.ita_contact_hist_enrich.xcoh_state_enrich IN ("CT", "VA","MN", "PA","OH") )

OR WOULD IT BE:

<%
                if (  targetData.ita_contact_hist_enrich.xcoh_state_enrich == "CT" )
                {
                %>Pre-Qualified<%
                }   
                 if (  targetData.ita_contact_hist_enrich.xcoh_state_enrich == "VA" )
                {
                %>Pre-Qualified<%
                }          
                 if (  targetData.ita_contact_hist_enrich.xcoh_state_enrich == "MN" )
                {
                %>Pre-Qualified<%
                }     
                 if (  targetData.ita_contact_hist_enrich.xcoh_state_enrich == "PA" )
                {
                %>Pre-Qualified<%
                }      
                 if (  targetData.ita_contact_hist_enrich.xcoh_state_enrich == "OH" )
                {
                %>Pre-Qualified<%
                }                                                                    
                else {
                %>Pre-Approved<%
                }
                %>

Thank you.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

vraghav
Adobe Employee
Adobe Employee
September 26, 2017

Hi Jae,

I'm not aware of an IN clause inside JavaScript.

The various IF statements you have defined is one of the correct ways to implement it but is not elegant and also not scalable.

Try defining the possible values inside an array and then make use of indexOf function,

More information here: JavaScript Array indexOf() Method

See if it helps.

Regards,
Vipul

Level 3
September 26, 2017

So I made this indexOf() script:

 

var states =["CT", "MN", "OH", "PA", "VA"];

var a = states.indexOf("CT");

var b = states.indexOf("MN");

var c = states.indexOf("NY");

...so how I do make use of this in my case?

Jean-Serge_Biro
Level 10
September 27, 2017

Hi Jael,

If you need to compare with dynamic values, in such case it is far better to use arrays technique as Vipul recommended.
For instance, if you load all the states from a queryDef on Country schema into an array, or better, an object (with name, ISO2, ISO3 fields), you can use easily with the typeOf or even directly by the indexing array / object to get the element.
And this technique is mandatory in case of for each loop.

Regards
JS

Jean-Serge_Biro
Level 10
September 26, 2017

Hi Jael,

IN operator is for SQL query where clause.

For Javascript use either operator || (OR) or switch statement to be more concise than your syntax, repeating the test in case of same action targeted. But of course your  syntax works fine as well...

Regards
J-Serge

Level 3
September 26, 2017

Hi all,

Thank you for your replies, when I develop the second option, if/Else statements, following the Adobe documentation Conditional content :  I got this error:

There is something it doesn’t like about the Else if in the bottom statement.

Why is it generating an error and what is the error pointing to?