Update Sctask comments with reply email body

Sujana Vadagana
Tera Contributor

Hi Team,
My requirement is to update the SCTASK comments from the reply email we received automatically. So that even if an external user who does not have access to ServiceNow replies we wont be missing anything.  

Scenario : When there is worknotes added on sctask an email will be sent to user and when user replies to that mail, I want the email body to be automatically updated in comments of that sctask.

I've been trying to implement this but can't find the exact solution. Could anyone suggest the correct approach?
Thank you.

2 REPLIES 2

HasanM
Kilo Sage

Hi @Sujana Vadagana 

You can do this with an Inbound Email Action:

  1. Make sure the outbound notification on sc_task includes the watermark (it does by default). When the user replies, ServiceNow uses the watermark to match the email to that SCTASK.

  2. Go to System Policy > Email > Inbound Actions and create a new one:
    Target table: Catalog Task [sc_task]
    Type: Reply
    Action type: Record Action
    Script:

    current.comments = "Reply from: " + email.origemail + "\n\n" + email.body_text;
    current.update();

  3. To keep only the new reply and drop the quoted email history, check the separators in the glide.pop3.reply_separators system property.

If the sender isn't a user in ServiceNow, the email is processed as Guest. Test that external replies are accepted and not blocked by ACLs or email filters.

If this helped, please mark it as the solution.

PradeepReddyA
Tera Guru

Hi @Sujana Vadagana 

 

When work notes are added to an SCTASK, an email notification can be triggered to send the updates to the respective user.

This can be configured through Notifications in ServiceNow.

  • Table:sc_task

  • Condition: Work notes changes

  • Configure the who will reciev and email content what users should see

Whenever work notes are updated on the SCTASK, the notification will trigger and send an email to the user.

2. Inbound Email Action – Processing User Replies

To capture the user's reply and update it in the Comments field of the SCTASK, this can be configured through Inbound Email Actions in ServiceNow.

Configure the Inbound Email Action with the following details:

  • Target table:sc_task

  • Action type: Reply

  • Condition: Received

The inbound email action processes the incoming email reply and updates the Comments or Work notes field on the corresponding SCTASK based on the requirement.

3. Inbound Email Action Script

The following script extracts and cleans up the incoming email content by removing quoted replies, email formatting, and unnecessary whitespace before updating the SCTASK.

var receiver = email.from;
var bodyText = email.body_text;

bodyText = bodyText.replace(/\r\n/g, '\n');
bodyText = bodyText.replace(/On\s+\w{3},[\s\S]*?wrote:[\s\S]*/i, '');
bodyText = bodyText.replace(/^>.*$/gm, '');
bodyText = bodyText.replace(/<[^>]*>/g, '');
bodyText = bodyText.replace(/[ \t]+/g, ' ');
bodyText = bodyText.replace(/\n{3,}/g, '\n\n');
bodyText = bodyText.trim();

current.work_notes =
    'Reply From: ' + receiver + '\n\n' +
    bodyText;

 


Hope that helps!