Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Hello All,



I have used below code but its not working for me so could you please help me on this.



function isEmailInList(list, email) {


  var gr = new GlideRecord('sys_user');


  gr.addQuery('email', email);


  gr.query();


  while(gr.next());


  {


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


          {


  return true;


  }


  return false;


}


}



And my condition is ((new CSEMailUtil).isUserExist(email.from)) && (current.contact.email == email.from) || isEmailInList(current.watch_list, email.from)


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Narender,



Please refer below blog for more info. Adjust your script accordingly.


Managing Glide Lists


Hello All,



I have used below code but its not working for me so could you please help me on this.



function isEmailInList(list, email) {


  var gr = new GlideRecord('sys_user');


  gr.addQuery('email', email);


  gr.query();


  while(gr.next());


  {


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


          {


  return true;


  }


  return false;


}


}



And my condition is ((new CSEMailUtil).isUserExist(email.from)) && (current.contact.email == email.from) || isEmailInList(current.watch_list, email.from)


You have a syntax error in your code, remove the semicolon after while. Instead you could make your script short by using chuck's code


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))