- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2024 04:43 AM
Helo all,
The script below is returning me 'No'. What could be the issue?
var email = GlideRecord('sys_email');
email.addEncodedQuery('mailbox=received^sys_id=67acb6c247109a10b58a86fd436d4312');
email.query();
if (email.next()) {
var e = 'test@email.com';
var recipientsArray = [];
recipientsArray.push(email.recipients.toUpperCase().split(','));
for (var i = 0; i < recipientsArray.length; i++) {
if ((recipientsArray.indexOf(e) > -1)) {
gs.info('Yes');
} else if ((recipientsArray.indexOf(e) == -1)) {
gs.info('No');
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2024 05:20 AM
Hi @tsoct
The issue is recipientsArray.push(email.recipients.toUpperCase().split(',')); creates a nested array, and when you later check recipientsArray.indexOf(e), it doesn't work as expected because recipientsArray contains an array inside of it, not a flat array of strings.
Try the below script :-
var email = new GlideRecord('sys_email');
email.addEncodedQuery('mailbox=received^sys_id=67acb6c247109a10b58a86fd436d4312');
email.query();
if (email.next()) {
var e = 'test@email.com';
var recipientsArray = email.recipients.toUpperCase().split(',');
for (var i = 0; i < recipientsArray.length; i++) {
if (recipientsArray[i] === e.toUpperCase()) {
gs.info('Yes');
break;
} else if (i === recipientsArray.length - 1) {
gs.info('No');
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2024 05:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2024 05:17 AM
Hello @PrashantLearnIT ,
Inbound Email Action is unable to meet my use case, which involves checking header text against the list of recipients. The script I added is only the part that is not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2024 05:20 AM
Hi @tsoct
The issue is recipientsArray.push(email.recipients.toUpperCase().split(',')); creates a nested array, and when you later check recipientsArray.indexOf(e), it doesn't work as expected because recipientsArray contains an array inside of it, not a flat array of strings.
Try the below script :-
var email = new GlideRecord('sys_email');
email.addEncodedQuery('mailbox=received^sys_id=67acb6c247109a10b58a86fd436d4312');
email.query();
if (email.next()) {
var e = 'test@email.com';
var recipientsArray = email.recipients.toUpperCase().split(',');
for (var i = 0; i < recipientsArray.length; i++) {
if (recipientsArray[i] === e.toUpperCase()) {
gs.info('Yes');
break;
} else if (i === recipientsArray.length - 1) {
gs.info('No');
}
}
}