indexOf not working as expected?

gokulraj
Giga Expert

How to compare the string with exact match?

myString = "networkgroup@abc.com";

"network@abc.com" also satifying this condtion

Is there a way to find the exact string insted of indexOF()

16 REPLIES 16

Steven Parker
Giga Sage

You should be able to find the exact string using something like this.  This is in an IF statement in a run script in a workflow:

answer = ifScript();
     function ifScript() {
      if (workflow.scratchpad.outputdataUser.indexOf("CN=TEST_EMAIL_GROUP") > -1) {
         return 'no';
      }
      return 'yes';
   }

Just put exactly what you are looking for in the string.

If the string is just an email address and that's all that is in it each time, you could just use an IF statement then.  indexOf() is typically used to find a string location within a larger string and if it returns a number greater than -1 then the string was found.


Please mark this response as correct and/or helpful if it assisted you with your question.
Steven

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

in your current string if you try to find network@abc.com it should give you index as -1 as it won't find that

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

That's for example

Comment = 'EVM00238-to1' not found/n 

mystring = EVM00238

if(Comment.indexOF(mystring)>-1)

this condition is satifying right now but I dont't want to do that, instead I want to match the exact string

I am not comparing eamil id for exaMPLE i HAVE shared that,

Comment = 'EVOOTBM-T05' is not exist;

myString = EVOOTBM;

if(Comment.toString.indexOF(myString)>1)

Now this should not satify but is is matching,

That's why I want a exact string matching condition