Notification Email template

C_S3
Tera Contributor

Hello All,
I have an requirement in which, when a user creates an announcement then email template should pop up at their window in editable format and then it should send to the specified users.
We have created an email template and notification , both on announcement table and its working as expected . The only thing missing is the editable template pop up. Could you please help me on this?
Any help would be appreciated. Thank you!

1 REPLY 1

Community Alums
Not applicable

Hello @C_S3 ,

I found something relevant solution on the internet though have not tried the below solution. Please it once:

To achieve the requirement of displaying an editable email template when creating an announcement in ServiceNow, you can follow these steps:

1. Create an Email Template:
- Navigate to System Notification > Email > Email Templates.
- Click on "New" to create a new email template.
- Configure the email template with the desired content and placeholders for dynamic data.
- Save the email template.

2. Create a UI Action:
- Navigate to System Definition > UI Actions.
- Click on "New" to create a new UI action.
- Set the following properties for the UI action:
- Table: Announcement [u_announcement]
- Name: Open Email Template
- Onclick: openEmailTemplate()
- Save the UI action.

3. Create a Client Script:
- Navigate to System Definition > Client Scripts.
- Click on "New" to create a new client script.
- Set the following properties for the client script:
- Table: Announcement [u_announcement]
- Type: OnLoad
- In the script section, add the following code:

function onLoad() {
if (g_form.isNewRecord()) {
openEmailTemplate();
}
}


- Save the client script.

4. Create a Script Include:
- Navigate to System Definition > Script Includes.
- Click on "New" to create a new script include.
- Set the following properties for the script include:
- Name: EmailTemplateUtils
- Accessible from: All application scopes
- In the script section, add the following code:

var EmailTemplateUtils = Class.create();

EmailTemplateUtils.prototype = {
initialize: function () {},

openEditableEmailTemplate: function (templateSysId) {
var template = new GlideRecord("sys_template");
if (template.get(templateSysId)) {
var editor = new GlideTemplateEditor(template);
editor.setCanEdit(true);
editor.setCanEditSubject(true);
editor.setCanEditBody(true);
editor.setCanEditSender(true);
editor.render();
}
},

type: "EmailTemplateUtils",
};


- Save the script include.

5. Update the UI Action:
- Edit the previously created UI action "Open Email Template".
- In the Onclick field, add the following code:

new EmailTemplateUtils().openEditableEmailTemplate('<template_sys_id>');


Replace `<template_sys_id>` with the sys_id of the email template you created in step 1.
- Save the UI action.

Now, when a user creates an announcement, the email template will pop up in an editable format. The user can make any necessary changes to the template. When the announcement is submitted, the specified users will receive the email using the configured notification.

Note: Ensure that the email template's placeholders match the field names and data available in the Announcement table to populate the dynamic content correctly in the email.

Remember to test the solution thoroughly in a non-production environment before implementing it in your production instance.

Hit the like button if this helps you in any way!

 

Thanks,

Prasad