How to ignore email in ServiceNow?

m_servicenow
Kilo Contributor

Hi All,

 

My requirement is i want to ignore the email which comes in service now from outside through email. if Change state is closed.

 

Scenario:

 

Step 1:   I create one change_request and it goes for manager approval.

Step 2: Manager approved this. and change closed.

Step 3: If user again try to approve/reject through Email link then he will send one email to service now instance e.g(xxx.service-now.com). So according to my idea i have to write on Inbound Action which is given below:

 

Please help me where i need to change the code so that it can work.

 

[code]

var skipmsg = false;

      if (email.subject != undefined) {

              var subject = email.subject;

                  if (subject.toLowerCase().indexOf("Re: approve") > -1 )

                      skipmsg = true;

 

             

      }

     

      if (!skipmsg) {

              gs.log("ELSE PART");

      }

[/code]

 

Thanks Everyone in advance.

8 REPLIES 8

Thanks Bhavesh



But my requirement is something different please see the requirements:




Ignore Approval Records   Change Request is Closed:




Scenerio: Ignore Email incoming in Servicenow if change request has been closed.


Condition:



1. If the Change Request Status is "Rejected", ignore ALL Approval request responses.


2. If the Change Request status is "Pending" (Waiting CR verification) then only accept response if the Approval Record State is "Requested".


Like I mentioned in my code, you can refer to the fields of the change request by using below code.



if (email.subject.indexOf("approve") >= 0 && current.state == "requested" && current.sysapproval.state == 'Pending')  


current.state = "approved";  


if (email.subject.indexOf("reject") >= 0 && current.state == "requested" && current.sysapproval.state == 'Pending')  


current.state = "rejected";  


Note : current.sysapproval refers to the change request.


current.sysapproval.state refers to the status of the change request.


Hi Bhavesh,



I modified the existing code in Update Approval Request(OOB) according to your script.



But when i am approving the change request through Email outlook and change state is Pending Approval. So according to my condition no email should be fired. Please help me why it is not working. All Re:CHG0002 Mail is coming again and again.



the code is which i modified is as below:



if (email.subject.indexOf("approve") >= 0 && current.state == "requested" && current.sysapproval.state == '-4') // Where -4 is value of change request


                      current.state = "approved";


              if (email.subject.indexOf("reject") >= 0 && current.state == "requested" && current.sysapproval.state == 'Pending')


                      current.state = "rejected";


Write a business rule on sys_email table and do all the coding there.



Condition : Before insert -->current.type == 'received'


Script : Adjust the above query so it fits in a business rule


if(all the conditions gets satisfied)


{


current.type = 'received-ignored';


current.update();


}