The CreatorCon Call for Content is officially open! Get started here.

Is it possible to configure an onload client script to for the email client?

peterscaramuzzo
Tera Expert

I know that it is possible for users to email information via the Email Client option available for table forms like incidents. There is some concern that users could be including confidential information. Is there a way to run an onload script to post a warning? I was looking at the Email Client Templates and there doesn't appear to be something that I can directly hook onto for the onload action. Anyone know if this is possible?

1 ACCEPTED SOLUTION

KKM's UI Script code with a few modifications worked for me.

(function() {
    function showWarning() {
        if (window.top.document.title.includes("Compose Email")) {
            alert("Warning: Do not include confidential information in emails.");
        }
    }
    window.onload = showWarning;
})();

View solution in original post

15 REPLIES 15

KKM
Tera Guru

Hi Peter,
How do you want the warning to appear ie., whether Globally or only for incidents.
With Best Regards,

Krishna Kumar M

maheshkhatal
Mega Sage
Mega Sage

@peterscaramuzzo It pulls out from sys_email_client_template tables so you should be able to create the onload client script on that table and pop an alert warning. 

I have taken screenshot for your help.client_template.JPG

Please mark my response as helpful/accept solution if it resolved your doubt.

Thanks,

Mahesh.

 

KKM
Tera Guru

@peterscaramuzzo - Yes, it is possible to display a warning message when users open the Email Client option in ServiceNow. However, since there is no direct onLoad event for the Email Client modal and you need to use a combination of UI Scripts, Client Scripts and possibly using UI Action to achieve this.

Approach 1: Using window.onload in a UI Script

You can use JavaScript into the Email Client modal by creating a UI Script that runs when the modal is loaded.

  • Navigate to System UI > UI Scripts.
  • Create a new UI Script:
    • Name: email_client_warning
    • Check the Global box.
    • Script:
       
      (function() { function showWarning() { if (window.g_form && window.top.document.title.includes("Email Client")) { alert("Warning: Do not include confidential information in emails."); } } window.onload = showWarning; })();
  • Save the script.

This will pop-up an alert whenever the Email Client modal is opened.

 

Approach 2: Adding a Client Script on the Incident form

You can use a Client Script on the Incident table that detects when the Email Client is opened.

  • Navigate to System Definition > Client Scripts.
  • Create a new Client Script:
    • Table: incident
    • Type: onLoad
    • UI Type: All
    • Script:
       
      (function executeRule(current, gForm, gSNC) { function showWarning() { var emailClientButton = document.querySelector('button[data-action-name="email_client"]'); if (emailClientButton) { emailClientButton.addEventListener("click", function() { setTimeout(function() { alert("Warning: Do not include confidential information in emails."); }, 500); }); } } setTimeout(showWarning, 1000); })(current, gForm, gSNC);
  • Save and test.

This script applies for the Email Client button click on the Incident form and shows an alert.

Approach 3: Modifying the Email Client UI Action

Another option is to modify or create a new UI Action that overrides the default Email Client behavior and includes a warning message.

  • Navigate to System Definition > UI Actions.
  • Find the Email Client UI Action (or create a new one if needed).
  • Modify the script to include:
     
    if (confirm("Warning: Do not include confidential information in emails. Proceed?")) { gsftSubmit(null, gForm.getFormElement(), 'email_client'); }

This prompt users before they proceed.

A UI Action would be preferable. There is no Email Client UI Action. I picked table sys_email_client_template per other replies for the UI action and it did not work.