Update incident from email with no watermark AND 2 incident numbers in the subject line

Ricky S Larsson
Tera Guru

I'm trying to setup an inbound email action for an integration between the customer and their vendor that will update an existing incidents in the customer instance based on the INC number that is included in the email from the vendor. No watermark is included. I know there is a possibility to create an inbound action that doesn't require a watermark, just the ticker number.

Problem is, there is also another INC number (the vendor's INC) in the reply email from the vendor. The email subject line looks like this:

[Vendor's INC number] - New ticket from Customer [Customer INC number] has been assigned to Group

How would I setup an inbound action that could take the Customer INC number and match it to that incident and update it, and ignore the Vendor INC number?

Web Services / REST integration is out of the question at the moment as this vendor doesn't work with WS / REST

1 ACCEPTED SOLUTION

asifnoor
Kilo Patron

Hi Richard,

A quick fix would be to read the subject and then fetch the customer INC number.

To do that, you need to have 1 word at least constant (pre or post) of that customer INC number. Let say, Customer followed by XXXXXX would always be there. In that case, you can simply write below code which returns the customer INC number.

var subject = "XX3234241 - New ticket from Customer 787XX2342 has been assigned to Group";
var find_str = subject.indexOf("Customer");
if (find_str > -1) {
var customer_str = subject.substring(find_str,subject.length);
var customer_no=customer_str.split(" ");
gs.print("customer number is "+customer_no[1].trim().toString());
}

Mark the comment as a correct answer and also helpful once worked.

View solution in original post

10 REPLIES 10

asifnoor
Kilo Patron

Hi Richard,

A quick fix would be to read the subject and then fetch the customer INC number.

To do that, you need to have 1 word at least constant (pre or post) of that customer INC number. Let say, Customer followed by XXXXXX would always be there. In that case, you can simply write below code which returns the customer INC number.

var subject = "XX3234241 - New ticket from Customer 787XX2342 has been assigned to Group";
var find_str = subject.indexOf("Customer");
if (find_str > -1) {
var customer_str = subject.substring(find_str,subject.length);
var customer_no=customer_str.split(" ");
gs.print("customer number is "+customer_no[1].trim().toString());
}

Mark the comment as a correct answer and also helpful once worked.

This looks like a neat way to grab the INC number! Thanks!

But what would I have to do next? I'm trying to use a GlideRecord script to be able to update the INC number I just got

	// Implement email action here
	
	// Find Company Ticket Number from Subject Line
	var subject = email.subject;
	var findStr = subject.indexOf("Ticket from Company:");
	
	// If "Ticket from Company" is found in the Subject line, take out the INC number after it
	if (findStr > -1) {
		var endStr = subject.substring(findStr,subject.length); // Return everything from after findStr
		var array = endStr.split(" "); // Split string into array
		var customerNo = array[1].trim().toString(); // Take index 1 which is the INC number, trim and display as string
		
		// Query the INC number on the Incident table
		var gr = new GlideRecord('Incident');
		gr.addQuery('number', customerNo);
		gr.query();
		
		// If a matching Incident record is found, update the record
		if (gr.next()) {
			
			gr.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;
			
			if (email.body.assign != undefined)
				gr.assigned_to = email.body.assign;
			
			if (email.body.priority != undefined && isNumeric(email.body.priority))
				gr.priority = email.body.priority;
			
			if (email.body.category != undefined)
				gr.category = email.body.category;
			
			if (email.body.short_description != undefined)
				gr.short_description = email.body.short_description;
			
			gr.update();
		}
			
	}

 

I must have missed something because the Inbound Action won't update when I try to email with a subject of an existing INC number:

Skipping 'Vendor Update Incident', did not create or update incident

Hi Richard,

Can you add few logs and check once. Also, check if your inbound action got executed or not.

I modified your code slightly and also added few logs. can you check once. 

You can veiw the logs system logs by navigating to System Logs -> System Log -> All

// Implement email action here
	gs.include('validators');
	// Find Company Ticket Number from Subject Line
	var subject = email.subject;
	var findStr = subject.indexOf("Ticket from Company:");
	
	// If "Ticket from Company" is found in the Subject line, take out the INC number after it
	if (findStr > -1) {
                gs.log("Entered into the if condition 1");
		var endStr = subject.substring(findStr,subject.length); // Return everything from after findStr
		var array = endStr.split(" "); // Split string into array
		var customerNo = array[1].trim().toString(); // Take index 1 which is the INC number, trim and display as string
		gs.log("Incident number is "+customerNo);
		// Query the INC number on the Incident table
		var gr = new GlideRecord('Incident');
		gr.addQuery('number',customerNo);
		gr.query();
		
		// If a matching Incident record is found, update the record
		if (gr.next()) {
			gs.log("Incident record matched here in 2nd if condition");
			gr.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;
			
			if (email.body.assign != undefined)
				gr.assigned_to = email.body.assign;
			
			if (email.body.priority != undefined && isNumeric(email.body.priority))
				gr.priority = email.body.priority;
			
			if (email.body.category != undefined)
				gr.category = email.body.category;
			
			if (email.body.short_description != undefined)
				gr.short_description = email.body.short_description;
			
			gr.update();
		}
			
	}

Mark the comment as helpful and correct once worked.

Also, in the inbound action, check if you have configured the Type as New or Reply?