Check if value in array

 4 Replies
 1 Subscribed to this topic
 52 Subscribed to this forum
Sort:
Author
Messages
Nabil
Veteran Member
Posts: 61
Veteran Member

    Hello,

    I query a table and add values to a Message Builder array (var1) then run another SQL to check if the value is part of 'var1'.

     

    I'm using a Branch to determine if I need to add or remove Security access. My branch condition is 

     

    var1.includes(SQLQuery8410_POSITIONCODE); 

     

    The problem is it skips it, even if the POSITIONCODE is in the var1 array.

     

    Any ideas how I can tackle this?

     

    Thank you!

    jamesraceson
    Veteran Member
    Posts: 52
    Veteran Member
      Yeah, you would logically think the include functionality "should" work, but I've had it not work reliably enough within IPD. I usually get the results you are speaking of (doesn't go into error, but doesn't do what it is supposed to do either). So, one way I found to get around this is to take your result from the query, set it to a string var, and use the indexOf in JavaScript. Another option is use regular expressions to find what you are looking for. I know most people shy away from regular expressions, but once you tune it to what you need, they work really well and fast. Hope these ideas help.
      Nabil
      Veteran Member
      Posts: 61
      Veteran Member
        I tried the indexOf as well... here is how it's setup, but it still doesn't function correctly and go into 'true' even if the value is part of the string (var1).



        Bob Canham
        Veteran Member
        Posts: 217
        Veteran Member
          If you use indexOf, you need to add a comparison. It returns a value no matter what the result, but if it doesn't find the value, it returns -1. So if you do
          var1.indexOf(SQLQuery8410_POSITIONCODE)>=0 
          it will check to see if the value exists.

           

          Also, your branches are out of order.  Your catchall true value needs to be last, otherwise it will trigger every time.

          Nabil
          Veteran Member
          Posts: 61
          Veteran Member
            Thank you so much! that did it and now my branch is working as it should