Inbound email Action Requested Item Replies creating multiple tickets and not comments

mattmm
Kilo Sage

I have an Inbound email action I’ve created to create Requested items when an email is sent to a particular mailbox  e.g abc123@cba321.com

Target table: sc_req_item

Action Type: Record Action

Active: yes

Stop processing: yes

When to Run

Type: New

Conditions > Recipients contains abc123@cba321.com

Actions

createRequest();
function createRequest() {
   var cart = new Cart();   //calling the cart API
   var item = cart.addItem('<SYSIDOFCATITEM>');   //sys_id of the catalog item I want to fire
   cart.setVariable(item, 'ps_desc', email.body_text);   //sets catalog variable to email's body
     var rc = cart.placeOrder();   //this launches the catalog item, and creates a request object.   rc = the request object
	 updateRITM(rc.sys_id);   //call a function immediately to update the ritm.   This must be a nested function, otherwise inbound actions get weird.
           //also, we're passing the sys_id of the request so we know what RITM to grab.
}
function updateRITM(req){
   var ritm = new GlideRecord('sc_req_item');
   ritm.addQuery('request', req);   //req is what we passed from the previous function. the sys_id of the request.
   ritm.query();
   while (ritm.next()){
       ritm.opened_by = gs.getUserID();          
       ritm.description = "received from: " + email.origemail + "\n\n" + email.body_text;   
	   ritm.short_description = email.subject;
	   ritm.requested_for = ritm.opened_by;
	   ritm.assignment_group = '<SYSIDOFASSIGNMENTGROUP>';
       ritm.update();
   }
}
function copyAttachments(cartItemID, rc) {
	GlideSysAttachment.copy('sys_email', rc, 'sc_cart_item', cartItemID);
}
current.setAbortAction(true);
event.state="stop_processing";

My issue is that A user emails abc123@cba321.com which correctly creates an RITM000111 with the desired info in Short description and Description.

The abc123 team then reply to that user via email, and the user in turn replies back, but the issue is now it creates another RITM000112.

With each subsequent reply to abc123@cba321.com a new ticket is created. I want it to add the new reply as comments to the original RITM not create a new one. How do I achieve this?

I updated the Update Requested Item inbound action with the condition > recipients is abc123@cba321.com and action below, but no luck.

gs.include('validators');

if (current.getTableName() == "sc_req_item") {
	current.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;
	
	if (gs.hasRole("itil")) {
		if (email.body.assign != undefined)
			current.assigned_to = email.body.assign;
		
		if (email.body.priority != undefined && isNumeric(email.body.priority))
			current.priority = email.body.priority;
	}
		current.update();
}