- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2025 08:53 AM
Use case: There is a requirement, where on receiving an email, an interaction should be created. The mail body text should be displayed on 'description' field. And if we get reply to the mail, the description should be update.
I have created 2 inbound action, one for New type, other for Reply type.
Ques: How to showcase mail that was send for creating an interaction and on the same field, if any reply comes, that should also be displayed. Basically concatenate both emails.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2025 09:34 AM
Hi Ankur, On Reply inbound email action I wrote below script and It worked for interaction table.
current.u_description =
"\n\n============================\n" +
"Reply from " + email.from + " on " + new GlideDateTime().getDisplayValue() + "\n" +
"----------------------------\n" +
email.body_text +
"\n============================\n" +
(current.u_description || '');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2025 09:29 PM
Hello @GarimaU,
-
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.
- Update the relevant field(s): Typically, you'd update the
- 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.
// Inside a Script Include or Client Script
function 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();
-
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2025 10:19 PM
you need to have a journal field OR concatenate the description field
in your Reply type inbound email action you can concatenate it just before the update
current.description = current.description + email.body_text;
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2025 08:07 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2025 09:34 AM
Hi Ankur, On Reply inbound email action I wrote below script and It worked for interaction table.
current.u_description =
"\n\n============================\n" +
"Reply from " + email.from + " on " + new GlideDateTime().getDisplayValue() + "\n" +
"----------------------------\n" +
email.body_text +
"\n============================\n" +
(current.u_description || '');