- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2024 03:00 AM
Hello, everyone.
The script should check if the string contains any of the tags. However, the script below returns "not found" even when the tag is contained in the string.
var excludedtags ='[URGENT],[JUNK],[DUPLICATE],[IGNORE]';
var subject: 'HELP NEEDED - [[URGENT] Your account is temporarily blocked]';
var outputStr = excludedtags.split(',');
var tagArr = [];
for (var i = 0; i < outputStr.length; i++) {
tagArr.push('"' + outputStr[i] + '"');
}
tagArr.join(); //return "[URGENT]","[JUNK]","[DUPLICATE]","[IGNORE]"
for (var i2 = 0; i2 < tagArr.length; i2++) {
if (subject.indexOf(tagArr[i2]) > -1) {
gs.info('found ' + tagArr[i2]);
} else {
gs.info(' not found ' + tagArr[i2]);
}
}
//result:
*** Script: not found "[URGENT]"
*** Script: not found "[JUNK]"
*** Script: not found "[DUPLICATE]"
*** Script: not found "[IGNORE]"
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2024 03:45 AM
These are not found as the subject does not contain the tag in quotes. Change your push to this and it will work, also correcting the var subject typo : instead of =
tagArr.push(outputStr[i]);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2024 03:42 AM
Can you check if this works:
var excludedTags = '[URGENT],[JUNK],[DUPLICATE],[IGNORE]';
var subject = 'HELP NEEDED - [[URGENT] Your account is temporarily blocked]';
var tagArray = excludedTags.split(','); // Split the excluded tags into an array
for (var i = 0; i < tagArray.length; i++) {
if (subject.indexOf(tagArray[i]) > -1) {
gs.info('found ' + tagArray[i]);
} else {
gs.info('not found ' + tagArray[i]);
}
}
I think wrapping the tags in quotes when pushing them into the array is the issue.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2024 03:45 AM
These are not found as the subject does not contain the tag in quotes. Change your push to this and it will work, also correcting the var subject typo : instead of =
tagArr.push(outputStr[i]);