abbasshaik4
Tera Sage

Hello @GarimaU,

 

To concatenate old mail content with the latest email reply in ServiceNow, you can use a combination of Inbound Email Actions and scriptingThe core idea is to process the incoming email reply and append it to the existing conversation, potentially filtering out repeated text. Here's a breakdown of the steps:
 
1. Configure Inbound Email Actions:
  • Identify the Target Table:
    Determine the table (e.g., Incident, Task) where the email conversation is stored.
  • Create an Inbound Email Action:
    This action will be triggered when an email is received that matches certain criteria (e.g., replying to a specific email or a pattern in the subject line).
  • Define Action Steps:
    • Update the relevant field(s): Typically, you'd update the comments field (for example) or a dedicated field for email history.
    • Process the email body: You'll need to extract the relevant part of the email reply (the new content) from the email's body. This may involve parsing the email using methods like string manipulation or regular expressions to remove watermarks or previous email content. 
       
2. Scripting for Email Content Extraction and Concatenation:
  • Use Script Include or Client Script: Create a script include or client script to perform the string manipulation and concatenation.
  • Access the relevant fields: Get access to the current record's email history and the email's body from the incoming email. 
     
  • Extract the new email content: Parse the email body to extract the user's reply, potentially removing any watermarks or previous email content. 
     
  • Concatenate the content: Combine the new email content with the existing email history.
  • Update the target field: Update the target field with the concatenated content. 
     
Example (Conceptual):
 
// Inside a Script Include or Client Scriptfunction concatenateEmailContent() {  var emailBody = email.body_text; // Get email's body  var existingComments = current.comments; // Get existing comments  // -- Extract the new email content from emailBody (using regex or string manipulation) --  var newContent = extractNewContent(emailBody); // Example function to extract new content  // -- Concatenate the new content with the existing comments --  current.comments = existingComments + "\n\n" + newContent; // Simple example  // -- Update the Comments field --  current.update();}//Example function to extract New content:function extractNewContent(emailBody){  // Remove watermark if present.  Watermark example: "---  Original Message Below ---"  var watermark = "---  Original Message Below ---";  if (emailBody.indexOf(watermark) > -1){    var index = emailBody.indexOf(watermark);    emailBody = emailBody.substring(0, index);    // Remove any lines after the watermark.    emailBody = emailBody.trim();  }  return emailBody;}// -- Call the function within the Inbound Email Action (or a Business Rule) --concatenateEmailContent();
Key Considerations:
  • Watermarks:
    ServiceNow automatically inserts watermarks (e.g., "--- Original Message Below ---") in outbound emails to aid in identifying replies and forwards. You'll need to handle these watermarks when extracting the new content. 
     
  • Email Format:
    Consider both plain text and HTML emails when extracting content. You might need to handle HTML formatting differently than plain text. 
     
  • Performance:
    Be mindful of the performance implications of querying the sys_email table, especially if you're fetching a large number of emails. Consider using other methods like the journal to store email history if necessary. 
     
  • User Experience:
    Design the user interface to display the email history in a clear and organized manner. 
     
  • Advanced Email Parsing:
    For more complex scenarios, you might consider using regular expressions or specialized libraries for email parsing and content extraction. 
     
By carefully configuring Inbound Email Actions and using appropriate scripting techniques, you can effectively concatenate old mail content with the latest email reply in ServiceNow, creating a clear and informative email conversation history.
 
If it is helpful, please hit the thumbs up icon and accept the correct solution by referring to this solution in future it will be helpful to them.
 
Thanks & Regards,
Abbas Shaik