Close Inc via email

Stergios Stergi
Mega Guru

Hello!

 

We are trying to implement a system where we close an incident via email.

 

We want to read the subject that will contain the INC number at the beginning.

 

The script is,

 

(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {


var emailSub = email.subject; // read the email Subject
emailSub = emailSub.substring(0,10);

var grTask = new GlideRecord('incident');  // Table = incident
grTask.addQuery('number', emailSub); // get the Inc Record
grTask.addQuery('active', true);       // check if incident is active
grTask.query();

// if(grTask.next()){
grTask.state = 7 ; // 7 is choice code for close completed in sys_choice table for incident.
grTask.update();
// }



})(current, event, email, logger, classifier);
 
In the When to Run tab of the inbound action I have a couple of rules that filter out the incoming email that seem to work.
But it doesnt work.
 
Can someone take a look into the script?
 
Thank you so much in advance!
1 ACCEPTED SOLUTION

@Stergios Stergi 

 

Can you update the code as below and let me know please

 

grTask.state = 7;

grTask.close_code = "Workaround provided";

grTask.close_notes = "Closed from inbound action";

grTask.update();

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.

View solution in original post

16 REPLIES 16

Community Alums
Not applicable

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Stergios Stergi 

 

https://www.servicenow.com/community/developer-forum/how-to-close-incident-through-e-mail/m-p/196428...

https://www.servicenow.com/community/developer-forum/close-the-incident-via-email-notification/m-p/1...

https://www.servicenow.com/community/itsm-forum/how-do-i-close-an-incident-from-an-inbound-email/td-...

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Prince Arora
Tera Sage
Tera Sage

@Stergios Stergi 

 

// if(grTask.next()){
grTask.state = 7 ; // 7 is choice code for close completed in sys_choice table for incident.
grTask.update();
// }
 
Why you have commented two lines?

Hi @Prince Arora it was part of a test I did while trying to figure out how to do it.
I think that the IF there is not needed now.