Issue with inbound action not finding a target record

Richard S Lars1
Kilo Contributor

I have this issue with an email inbound action to target the right record. We have this email integration between the company and an external vendor and since we don’t have a watermark we need to use the incident number from the subject line. Challenge here is that we have 2 incident numbers: Vendor’s and Company’s

(company and vendor names have been anonymized)

INC0003504930 - New Ticket from Company: INC0032389 has been assigned to Vendor

We use the second Incident number. To target that incident record I wrote the following script in the inbound action (target table is Incident) to get the right incident number and then match the result with a GlideRecord query:

// 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) {
	
	var endStr = subject.substring(findStr,subject.length); // Return everything from after findStr
	var array = endStr.split(" "); // Split string into array
	var incNumb = array[3].trim().toString(); // Take index 3 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',incNumb);
	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();
	}
	
	// Force incident record as email target since inbound action script doesn't use Current
	sys_email.instance = gr.sys_id;
	sys_email.target_table = gr.getTableName();
}

Problem now is that we are using gr. Instead of current which becomes trouble for the inbound action to find the right target record. Therefor, I force the target with the last two lines of code. But by doing that, the inbound action is not really updating the record.

This becomes another problem when we are sending email back and forth in the incident. Because there is no watermark or a matching target record, all emails are of the type “New” instead of “Reply”. The vendor is not accepting “New” emails to a current incident.

This means that our users have to add re: prefix manually everytime and that is not good practice…

 

How can I re-write the inbound action to use "current" and get the right target record?

1 ACCEPTED SOLUTION

dalip wadhawan
Giga Contributor

Hi Richard,

If your issue is that the associated email instance record is not updating the target attribute, then please try "sys_email.update();" at the end of your script where you are forcing the target.

 

Regards,

Dalip

View solution in original post

3 REPLIES 3

dalip wadhawan
Giga Contributor

Hi Richard,

If your issue is that the associated email instance record is not updating the target attribute, then please try "sys_email.update();" at the end of your script where you are forcing the target.

 

Regards,

Dalip

This did help to keep the target record. Thank you!

 

But then I have one issue still: When we are trying to reply to the first email from the vendor, it doesn't add any re: prefix by itself.

I don't know if our reply is actually counted as a reply email but I would assume it is? Or am I thinking wrong here? If they reply back to our reply, then an re: prefix is added.

 

find_real_file.png

find_real_file.png

dalip wadhawan
Giga Contributor

Hi,

 

Please look for the template which is being used for this mail composition.

Navigate to System Policy > Email > Client Templates.

I believe it should be with name "reply-received". It can be different.

Try editing the subject by adding your prefix. It might take some playing around but seems good.

 

Regards,

Dalip