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

ravi1_tandon
Kilo Guru

In you code you need to check for the change state and execute the inbound script only if the it returns true or false depending on the condition that you are evaluating



something like this



if (current.state != "Approved")


{


                  //then do something;


}


else


{


        event.state = "stop_processing";


}


Thanks Ravi,



i got the idea but on which table i have to write inbound action "change_request" or "sysapproval_approver".   Because when i approve or reject and request through outlook Mail i have to ignore the mail if the change request is state is already "closed". and if the change request state is still "pending" then servicenow will receive Email.



Please guide me if you have any idea or scripts.



waiting for positive response.


Hi Mukesh,



Question for you, if your Change is closed and a Approval email is sent in, is it currently impacting your change? Hence why you want to ignore the email?   If so tackle the big issue via a Data Policy that restricts changing the State of the Approval Record if the Change is closed. The Email will still be attached to the approval, but it does nothing to the change (unless coded otherwise).


Bhavesh Jain1
Giga Guru

Hi Mukesh,



I would like to tweak your requirement to frame it in another way.


Once a user has approved/rejected a change request, the user should not be allowed to approve/reject again.


If this is your requirement, you already have an inbound action 'Update Approval Request'.


All you need to do is fine tune the code inside.



Existing Code :



if (email.subject.indexOf("approve") >= 0)
          current.state = "approved";


      if (email.subject.indexOf("reject") >= 0)
          current.state = "rejected";


Modified Code :



if (email.subject.indexOf("approve") >= 0 && current.state == "requested")
          current.state = "approved";


      if (email.subject.indexOf("reject") >= 0 && current.state == "requested")
          current.state = "rejected";




So now if your request is already approved or rejected, the above code will not modify the State field.



You may want to write additional condition here like : current.sysapproval.state != 'Closed'....