indexOf not working as expected?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2021 06:14 AM
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()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2021 06:45 AM
Hi,
if you are sure the value you want to compare will be present exactly then you can directly use double equal to opeartor
if(comment == myString)
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2021 06:50 AM
but the comment not only contains the item name, it will be like below
comments = 'EVMTMW-WOZ' item not found/n 'TMAQW-WOZ' does not exist
myString = 'EVMTMW' (Queried from item name table hold's the item name and need to compare with the comment)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2021 06:58 AM
Hi,
then I believe you need to use indexOf only as your mystring can be present at any place
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2021 06:19 AM
Hello,
How is JavaScript's IndexOf "not working as expected"?
Anyways, there's regex and I believe another method, but it's a bit more complicated when this whole thing may need to be. You should be fine using IndexOf if used properly:
https://www.w3schools.com/jsref/jsref_indexof.asp
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2021 06:23 AM
Hi,
Try using
.startsWith("<field>")
var emails='networkgroup@abc.com';
if (emails.startsWith("network@abc.com"))
{
gs.print('exact');
}
else
{
gs.print('not exact');
}
Tried giving me Not exact.
Please mark Correct✅/helpful???? if applicable, thanks!!
Aman