Update ticket based on Email description

Iqbal1
Kilo Contributor

Hi All,

We currently get service status update email from a vendor when their service is down, and another email when service is back up.

The vendor email provides a ticket number (from their own system) in the emails subject, and when the service issue is resolved ,they include the original ticket number and the word "done" in the email subject.

Rather than having two tickets creating, I would like to have the second ticket (resolution ticket - "done") to be appended to the original ticket.

I was thinking about doing this using Inbound Emails Actions, but I am not familiar with it. I hope you can either assist or provide an alternative solution.

With Inbound Email action how do filter based on external emails (non-ServiceNow account emails). I am currently getting in "invalid reference error", and I I assume I will have to create an account to resolve it.

Thank you.

9 REPLIES 9

Iqbal1
Kilo Contributor

UPDATE: It works now in the "Background - Scripts" section. I'm going to try this in the inbound actions script context

Great!

Keep the updates posted in case of any issue.

Hope you can help with this, but I don't think I understand what the `current` is or what the variable does.

When I write the below:

logger.log(current.number)

The output is the incidentNumber+1. I assumed this would be the incident number that gets created form the `Create Incident` inbound action

Does each inbound action increment the incident Number

 

My current code: 

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

	// Implement email action here
	var regex = /#\d{6}/;
	var vendorTicket = '';
	var subject = email.subject;
	vendorTicket = subject.match(regex);
	
	//Query for original ticket using the `vendorTicket` variable which is #123456
	var originalTicket = new GlideRecord('incident');
	
	originalTicket.addQuery('short_description', 'CONTAINS', vendorTicket);
	originalTicket.addQuery('short_description', 'DOES NOT CONTAIN', 'done');
	
	originalTicket.query(); // Issue the query to the database to get all records 
	
	while (originalTicket.next()) { 
		// add code here to process the incident record
		originalTicket.comments = current.comments;
		originalTicket.update();
	}
	
	//logger.log("From Logger vendorTicket Number: " + vendorTicket);

})(current, event, email, logger, classifier);

Hi Iqbal,

current will refer to the record just created/updated.

current.number will give the number of the record that is just created/updated.

From your script, I don't see any creation intention so my query

vendorTicket = subject.match(regex);

Does the above line gives required number from subject, to check it a put log just below this line. Make sure it is not including spaces.

and when you are querying the same in glide function then does it update comments?

Put a log inside the while().

Hi Iqbal,

Any update on the progress of this issue?