How to convert "contains" as operator

Jeni Sebastian
Mega Contributor

Hi everyone! 

I have an existing business rule and I need to insert a condition inside the script using  "if (current." 

Condition :  If "user account" field contains "ETC"  

Field: u_useraccount

Field Type: string

What I did was this and I know that it's not really correct since I used "==".

if(current.u_useraccount =="ETC"){

}

 

I'll appreciate if someone respond to this. Thanks in Advance! 

1 ACCEPTED SOLUTION

Aman Kumar S
Kilo Patron

You can use:

var str = current.getValue("u_useraccount");

if(str.indexOf("ETC") > -1){// checks if u_useraccount contains ETC, indexOf returns -1 if not found, else returns the index where the substring is found.

View solution in original post

5 REPLIES 5

Aman Kumar S
Kilo Patron

You can use:

var str = current.getValue("u_useraccount");

if(str.indexOf("ETC") > -1){// checks if u_useraccount contains ETC, indexOf returns -1 if not found, else returns the index where the substring is found.

Hi @Aman Kumar ! Thanks for this one !

So if the condition is : "DOES NOT CONTAIN" 

will it look like this?

if(str.indexOf("ETC") < -1){

sorry is that right?

It should be like below,

if(str.indexOf("ETC")== -1){

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit
Community Rising Star 2022

It should be:

if(str.indexOf("ETC") == -1){

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂