How to get the email from watch list in inbound email condition

narenreddy
Giga Guru

Hi,

I am using the inbound email notification Update Case via AcceptReject, Where I need to modify the condition on this. Given the requirement below.

Current Logic:   ((new CSEMailUtil).isUserExist(email.from)) && (current.contact.email == email.from)

New Logic:     ((new CSEMailUtil).isUserExist(email.from)) && ((current.contact.email == email.from)     OR   (user is on the customer update list))

It has to accept the email from who are there in watch list. So please assist me.

1 ACCEPTED SOLUTION

Blow code works for me.



Script Include:-


==================


var isEmailInList = Class.create();


      isEmailInList.prototype = {


      initialize: function() {


      },


      isEmailInWL : function(list, email) {


              var u = new GlideRecord('sys_user');


              u.addQuery('email', email);


              u.query();


              if(u.next())


              {


              var id = u.getValue('sys_id');


              var lst = list.toString();


              var array = lst.split(",");


              for(var i = 0; i < array.length; i++)


              if(array[i] == id)


              {


                    return true;


              }


                  else{


                    return false;


  }


  }


  },



      type: 'isEmailInList'


};



Condition:-


(((new CSEMailUtil).isUserExist(email.from)) && (current.contact.email == email.from)) || ((new isEmailInList).isEmailInWL(current.watch_list, email.from))


View solution in original post

9 REPLIES 9

Abhinay Erra
Giga Sage

narender,



Create a new script include and name it as getEmails and add this script in there


function getEmails(id){


var arr=[];


var gr= new GlideRecord('sys_user');


gr.addQuery('sys_id','IN',id);


gr.query();


while(gr.next()){


arr.push(gr.getValue('email'));


}


return arr.toString();


}


Your modified condition will be


((new CSEMailUtil).isUserExist(email.from)) && ((current.contact.email == email.from) || (getEmails(current.<put your watch_list field name here>.toString()).indexOf(email.from.toString())>-1))


That was my approach first, but then realized you don't need to get ALL the users in the watch list, you only need to get one (the one you are checking) and see if their sys_id is in the list.


LOL, I agree. I was in a hurry to provide an answer.


Chuck Tomasi
Tera Patron

Here's how I would do it. Create a script include called isEmailInList. Take out the sample code and replace it with this function.



function isEmailInList(list, email) {


  var u = new GlideRecord('sys_user');


  if (u.get('email', email)) {


  if (list.indexOf(u.getValue('sys_id')) > 0)


  return true;


  }



  return false;


}



Now in your condition, add



|| isEmailInList(current.watch_list, email.from)



Modify current.watch_list to what ever list field you want to use.



Note: completely untested.