HTML email body into the RITM

Merza Lyn
Mega Guru

I created an inbound action to create RITM

 

var createRITM = true;  // Condition to create a RITM (assuming no duplicate check logic is required)
var curr_record;
// Check if the subject is valid to create a RITM
if (createRITM) {
   // Create the cart and add the item (assuming the item ID is the same as in the sample code)
   var cart = new Cart();
   var item = cart.addItem('c05b5b904704e2102fa8cfba516d43b3'); // Item ID for ATK Shift Change
   // Set the variables based on the email content
   cart.setVariable(item, 'email_body', email.body_text);  // Set email body content
   cart.setVariable(item, 'desc', email.subject);  // Set email subject as description
   cart.setVariable(item, 'email_sender', email.from);  // Set email sender
   // Place the order and capture the RITM number
   var rc = cart.placeOrder();
   var ritm = current.number;  // Get current RITM number
   ritm = ritm.split('M');
   ritm = Number(ritm[1]) + 1;  // Increment the RITM number for tracking purposes
} else {
   var grr = new GlideRecord("sc_req_item");
   grr.addQuery("number", ritm);  // RITM number query
   grr.query();
   if (grr.next()) {
       curr_record = grr;
   }
}

 

And created Business rule to populate the email body to the RITM activity log

MerzaLyn_0-1740647377657.png

 



But the email body in the RITM is like this:

MerzaLyn_0-1740647139346.png


How can I make email body to be like this?
 

MerzaLyn_1-1740647161030.png

 

7 REPLIES 7

Hi @Ankur Bawiskar 
I update my inbound action, but I am not sure if this is correct since it is not working.

var createRITM = true;  // Condition to create a RITM (assuming no duplicate check logic is required)
var curr_record;
// Check if the subject is valid to create a RITM
if (createRITM) {
   var cart = new Cart();
   var item = cart.addItem('c05b5b904704e2102fa8cfba516d43b3'); // Item ID for ATK Shift Change
   // Set the variables based on the email content
   cart.setVariable(item, 'email_body', email.body_text);  // Set email body content
   cart.setVariable(item, 'desc', email.subject);  // Set email subject as description
   cart.setVariable(item, 'email_sender', email.from);  // Set email sender
   // Place the order and capture the RITM number
   var rc = cart.placeOrder();
   var ritm = current.number;  // Get current RITM number after placing the order
   ritm = ritm.split('M');
   ritm = Number(ritm[1]) + 1;  // Increment the RITM number for tracking purposes
   // Now, retrieve the RITM record and update the comments field
   var grRITM = new GlideRecord("sc_req_item");
   grRITM.addQuery("number", ritm);
   grRITM.query();
   if (grRITM.next()) {
       // Update the comments field with the specified format
       grRITM.comments = "received from: " + email.origemail + "\n\n" + email.subject + "\n\n" + email.body_text;
       grRITM.update(); // Save the changes to the RITM record
       // Now, create an activity log for the RITM with the email content
       grRITM.insertActivity("Email received",
           "received from: " + email.origemail + "\n\n" +
           email.subject + "\n\n" +
           email.body_text);
   }
} else {
   // Handle case where the request already exists (you can modify this logic for checking duplicates)
   var grr = new GlideRecord("sc_req_item");
   grr.addQuery("number", ritm);  // RITM number query (you can adjust the logic as per your needs)
   grr.query();
   if (grr.next()) {
       curr_record = grr;
   }
}

 I added this lines

var grRITM = new GlideRecord("sc_req_item");
   grRITM.addQuery("number", ritm);
   grRITM.query();
   if (grRITM.next()) {
       // Update the comments field with the specified format
       grRITM.comments = "received from: " + email.origemail + "\n\n" + email.subject + "\n\n" + email.body_text;
       grRITM.update(); // Save the changes to the RITM record
       // Now, create an activity log for the RITM with the email content
       grRITM.insertActivity("Email received",
           "received from: " + email.origemail + "\n\n" +
           email.subject + "\n\n" +
           email.body_text);
   }

 

@Merza Lyn 

check this link and it has solution

Handling inbound emails with HTML in RITM Description field 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Merza Lyn
Mega Guru

I need this in the RITM activity stream

MerzaLyn_0-1740701542885.png

 

MerzaLyn_2-1740701605261.png