n21lv1
Tera Contributor

For quite a long time I have been trying to figure out a way to do this without modifying the 'EmailDisplay' Processor, and it looks like I finally managed to, partially thanks to ServiceNow introducing a new property to store the email body style settings in one of the last few releases.

What am I talking about? How about an easy, 1-click way to open a sys_email record straight from the Activity log?

Here's how to achieve this.

  1. Create a new String property glide.ui.activity.style.email
  2. Set its value to this script:
    } </style>
    <script>
        function goToEmail() {
            const queryString = window.location.search;
            const urlParams = new URLSearchParams(queryString);
            const email_id = urlParams.get('email_id');
            window.open('/sys_email.do?sys_id=' + email_id, '_blank');
        }
    </script><p><button onclick="javscript: goToEmail()">Open Email record</button></p>
    <style>
    <!-- PUT YOUR CUSTOM EMAIL BODY STYLE HERE -->
        body {​

And voilà! Now when you click the 'Show email details' link, you will see a button on top of the email body that, when clicked, will take you directly to the email record!

UPD: Now available on Share!

Comments
n21lv1
Tera Contributor

I was playing a bit more with this idea and made a more sophisticated version. If you want the button to only be visible for users having a specific role, use this instead:

} </style>
<script>
    function goToEmail() {
        const queryString = window.location.search;
        const urlParams = new URLSearchParams(queryString);
        const email_id = urlParams.get('email_id');
        window.open('/sys_email.do?sys_id=' + email_id, '_blank');
    }
</script>
<script>
    function toggleEmailButton() {
        var emailButtons = document.getElementsByClassName('button-go-to-email');
        for (let i = 0; i < emailButtons.length; i++) {
            emailButtons[i].style.display = "block";
        }
    }
</script>
<p class="button-go-to-email" style="display: none;">
    <button onclick="javscript: goToEmail()">Open Email record</button>
</p>
<script>
    let gUser = window.top.document.gsft_main == undefined? 
        g_user:
        window.top.document.gsft_main.g_user;
    if (gUser && gUser.hasRole(<YOUR_COOL_ROLE>)) {
        toggleEmailButton();
    }
</script>

<style>
    body {
/* ADD CUSTOM EMAIL BODY STYLE HERE */
Bharath38
Giga Sage
Giga Sage

Hey n21lv,

This is a cool feature, I have created property but I don't see any button on email logs ? what am I missing here ? 

n21lv1
Tera Contributor

I am not sure you followed the instructions properly. The button should appear inside the email body. Can you post a screenshot of how an expanded email looks in any Activity log?

n21lv1
Tera Contributor

I have just realised that if you have a record opened in a tab without the SN frameset (no Navigator on the left) window.top.document.gsft_main is undefined.

I have updated the script so it accounts for that, so try the new version and tell me if that works

Bharath38
Giga Sage
Giga Sage

working as expected.. Thank you!

Max Lin
Tera Contributor

WWWorking well!  THANK YOU!

  if (gUser && gUser.hasRole('admin')) {

 

Is there a way we can show syslog_email.do of the email record in the activities also?

 

n21lv1
Tera Contributor

Hello Max, really glad it helped you!

Could you clarify what did you mean by showing syslog_email.do in the activities? Do you want to see all syslog_email records associated with the email?

Max Lin
Tera Contributor

Hi there! Thank you for replying! 

Yes, we would like to view the email logs (could have multiple sometimes) that is associated with the email. 

Actually, the useful information here is to know which Notification triggered this email (for the below screenshot, Notification "Email to All Assessors (no assessor)" is the triggering notification that triggered this email). 

Thanks!!!


find_real_file.png

n21lv1
Tera Contributor

You already have this information, since when you click the button, there's an embedded list above email body that shows exactly that, but if you really want to show this inside activities, I think you could use a GlideAjax to retrieve the notification record from sys_email_log.do?sys_id={{EMAIL_SYSID}} and then modify the HTML being injected as needed.

I recommend using Jon Holderman's swissArmyUtil SI to save on creating a new GlideAjax SI each time you need to retrieve a specific value from a GlideRecord

Version history
Last update:
‎02-04-2022 12:08 PM
Updated by: