indexOf doesn't match the exact string?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2018 04:08 AM
Hi team,
I have a requirement to get the exact string comparison results.
if my condition is like [ if (emailTo.indexOf("networkoperation@test.com") != -1) ]
it will also satisfy the conditions if the email To contains like the following("operation@test.com")
How to find the exact string matching?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2018 06:01 AM
Hi Harshvardhan,
I have tested your script it is working fine if the Email To contains only one recipients,
but it fails when more than one recipients in Email To condition,
Ex,
var emails='networkoperation@test.com , operation@test.com ';
if (emails.startsWith("operation@test.com"))
{
gs.print('hello');
}
else
{
gs.print('not hello');
}
It is executing the else part.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2018 06:26 AM
ok then in this scenario here we go
var emails=["networkoperation@test.com","operation@test.com"];
var temp=0;
for (var i=0; i<emails.length;i++)
{
gs.print(emails[i]);
if(emails[i] === "harsh@test.com"){ // mention the email you want to compare here
temp = true;
break;}
else
{
temp= false;
}
}
if (temp)
{
gs.print('hello');
}
else
{
gs.print('not hello');
}
//gs.print(temp);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2018 12:58 AM
have you tried this? i tested on my pdi and this will also fulfill your requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2018 04:22 AM
you might try to use .match() method along with regex to get the string that matches the expression

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2018 04:23 AM
Try email.to.indexOf("networkoperation@test.com")!=-1