
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2022 07:27 AM
There are loads of similar posts but nothing I try seems to work.
I have a field that contains a string called "Ignore Email". Sometimes it's a full email address but I want it to also work for part of an email address.
When an email comes in the inbound action calls a condition script and passes the email address over (variable = sender). The script compares the value in Ignore Email with the origemail value.
If I use a complete email address it will match it OK (sender.indexOf(ignoresender)!= -1), however, if I use part of an email it doesn't work at all.
So, my email address in the Ignore Email field (abettcher@mti.com) works fine but "@mti.com" doesn't work.
Why is this?
Most people ask for the entire script which I have added below but most of it is irrelevant to this issue. The problem is in line 62. The weird thing is that the other conditions such a the subject line match WILL work if only part of a subject line is used.
//var ignoreEmailTime = Class.create();
//ignoreEmailTime.prototype = {
//initialize: function() {
//},
//type: 'ignoreEmailTime'
//};
function ignoreEmailTime(sender, subject, body, body2){
sender = sender.toString().toLowerCase();
subject = subject.toString().toLowerCase();
body = body.toString().toLowerCase();
body2 = body.toString().toLowerCase();
var ignored = new GlideRecord('u_ignore_emails');
ignored.addQuery('u_emails_lower_case',sender.toLowerCase());
ignored.addQuery('u_active',true);
ignored.query();
while(ignored.next()){
var ignoresender = ignored.u_email_address;
var ignoresubject = ignored.u_ignore_only_if_subject_contains;
var ignorebody = ignored.u_ignore_only_if_body_contains;
var ignorebody2 = ignored.u_and_also_if_body_contains;
gs.log('Ignore Sender: ' + ignoresender);
gs.log('Sender:' + sender);
if (ignoresender){
ignoresender = ignoresender.toLowerCase();
}
if (ignoresubject){
ignoresubject = ignoresubject.toLowerCase();
}
if (ignorebody){
ignorebody = ignorebody.toLowerCase();
}
if (ignorebody2){
ignorebody2 = ignorebody2.toLowerCase();
}
if (ignorebody == '' && ignoresubject == ''){
return true; //if the ignore fields for both subject and body are blank, ignore the email.
}
else{ //otherwise, compare the ignore fields against the actual content of the subject and body of the email.
var ignoresendermatch = false;
var ignorebodymatch = false;
var ignorebody2match = false;
var ignoresubjectmatch = false;
var timecheck = false;
if (ignoresender == '' || sender.indexOf(ignoresender) != -1){
ignoresendermatch = true;
}
if (ignoresubject == '' || subject.indexOf(ignoresubject) != -1){
ignoresubjectmatch = true;
}
if (ignorebody == '' || body.indexOf(ignorebody) != -1){
ignorebodymatch = true;
}
if (ignorebody2 == '' || body2.indexOf(ignorebody2) != -1){
ignorebody2match = true;
}
var now = new GlideDateTime().getNumericValue();
var start = new GlideDateTime(ignored.u_start_time).getNumericValue();
var end = new GlideDateTime(ignored.u_end_time).getNumericValue();
var inRange = (now >= start && now <= end)? true: false;
if (inRange){
timecheck = true;
}
if (ignored.u_blackout == true && ignored.u_date_range == true){
if (ignoresendermatch){
if (ignoresubjectmatch){
if (ignorebodymatch){
if (ignorebody2match){
if (timecheck){
return true;
}
}
}
}
}
}
if (ignored.u_blackout == true && ignored.u_date_range == false){
var schedRec = new GlideRecord('cmn_schedule');
schedRec.addQuery('sys_id', ignored.u_schedule);
schedRec.query();
//if(typeof GlideSchedule != 'undefined'){
if(schedRec.next()){
var sched = new GlideSchedule(schedRec.sys_id);
var inSched = sched.isInSchedule(new GlideDateTime());
if(inSched){
return true;
}
else{
return false;
}}
if (ignoresendermatch){
if (ignoresubjectmatch){
if (ignorebodymatch){
if (ignorebody2match)
if(schedRec){
return true;
}
}
}
}
}
if (ignored.u_blackout == false && ignored.u_date_range == false){
if (ignoresendermatch){
if (ignoresubjectmatch){
if (ignorebodymatch){
if (ignorebody2match){
return true;
}
}
}
}
}
}
} //Note, the code will loop through other IGNOREs on the list, if a match not yet found.
//This allows multiple permutations of ignore for subject content / body content to be configured per email address.
//if the code gets to this stage, it means a match was not found.
return false;
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2022 07:40 AM
I'm a dope. I query the ignore records using the email field. Obviously if the contents of that field do not match the inbound email address then there is no record against which to run the rest of the script. Return is false.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2022 07:40 AM
I'm a dope. I query the ignore records using the email field. Obviously if the contents of that field do not match the inbound email address then there is no record against which to run the rest of the script. Return is false.