The Zurich release has arrived! Interested in new features and functionalities? Click here for more

SCTASK emails sent from "More Options" menu need to display in RITM Activity Stream and Service Port

WayneHadley
Tera Contributor

Greetings,

I have a business request to display emails sent from the "More Options" menu [3 dots] on the SCTASK to add them to the RITM Activity Stream and thus also show them in the Service Portal, in addition the request is to show any email attachments in the RITM Activity Stream and Service Portal. I have configured a Business Rule as follows:

When to Run: Async

Insert: true

Update: true

Filter Conditions: Type is sent; Target Table = sc_task; Copied to RITM** = false [** I created a custom field in the sys_email table u_copied_to_ritm to have an "idempotent flag"; the rule will check this flag before running, and the last thing the rule does is set the flag so it never runs on that record again.]

Business Rule:

(function executeRule(current, previous /*null when async*/) {

    // --- IDEMPOTENCY CHECK ---
    if (current.u_copied_to_ritm == true) {
        return;
    }

    // --- IGNORE AUTOMATED EMAILS CHECK ---
    if (gs.nil(current.user_id)) {
        return;
    }

    // Get the SCTASK record the email was sent from
    var grTask = new GlideRecord('sc_task');
    if (grTask.get(current.instance)) {

        // Get the parent RITM record
        var grRit = new GlideRecord('sc_req_item');
        if (grRit.get(grTask.request_item)) {

            var fromUser;
            if (grTask.assigned_to.getDisplayValue()) {
                fromUser = grTask.assigned_to.getDisplayValue() + ' (' + grTask.assigned_to.email + ')';
            } else {
                fromUser = current.from;
            }

            var emailContent = '';
            emailContent += 'Email sent from related task ' + grTask.number + '\n';
            emailContent += 'From: ' + fromUser + '\n';
            emailContent += 'To: ' + current.recipients + '\n';
            emailContent += 'Subject: ' + current.subject + '\n\n';
            emailContent += 'Body:\n' + current.body_text;

            grRit.comments = emailContent;
            grRit.update(); 

This works well to add the email details to the RITM Activity Stream and SP but I have not been unable to solve the requirement for attachments.

 

Has anyone in the Community done something like this, if so, how were you able to accomplish it?

 

One concern I have is that by copying attachments to the RITM, we'll be adding duplicates, increasing storage usage, data redundancy etc. I'd welcome any feedback and guidance around this.

 

Feedback also welcome on the above business rule.

 

Thank you,


Wayne

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@WayneHadley 

Not a good idea to have custom field on OOTB sys_email table

Also yes don't copy attachments again on RITM as it will increase table size.

if you want to show attachments in ticket page on RITM then do this

1) in standard ticket config create a new tab

AnkurBawiskar_1-1758285869643.png

 

2) in that use custom widget and show attachments from SC Task on RITM

AnkurBawiskar_0-1758285725464.png

 

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

Thank you for the reply @Ankur Bawiskar  I was hesitant to add the custom field to sys_email but I could think of no other way to address the issue I was seeing in testing i.e. the business rule without the idempotent flag was resending emails that were sent in the past so I was seeing duplicates and triplicates in the activity stream on the RITM and in the Service Portal. I'm open to ideas to solve this without using a custom field. 

I like the idea of the custom tab for attachments, but that doesn't help me solve the business request to display attachments in the RITM Activity Stream and Service Portal, this is a key requirement for them. I'd welcome you insights on this piece.

@WayneHadley 

where you want to see attachments on ticket page in portal or native?

if native then you can add related list, see this link

TNT: "Related Attachments" Related List 

if portal ticket page then custom tab should help you

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