How can I write a Email script to use a system property in email notification content?

Pritam_Pawar225
Tera Contributor

I have one system property "change_request.autoclose.time" which states that Number of days (integer) after which Reviewed change request are automatically closed. Zero (0) disable this feature. How the  Email script will be to use this in my email body content 

1 ACCEPTED SOLUTION

Kiranmai_KVL
Kilo Sage

Hello Pritam,

 

1) Call the email script from the Message HTML in your notification using the below syntax : 

E.G : ${mail_script:change_request_details}

 

Kiranmai_KVL_0-1687328207803.png

 

2) Now go to left navigation -> Type email script & open 'Notification email script' & either create new script if it's not available or open existing script.

In the email script, you can get & check the system property value using the below syntax 

EG : var days = parseInt(gs.getProperty("glide.ui.autoclose.time"));

 

You can refer to OOB email scripts such as 'incident_resolved_incident' or 'incident_body ' & see how its implemented.

Kiranmai_KVL_1-1687328475723.png

 

Let me know if that helps or if you have any further questions.

 

 

View solution in original post

7 REPLIES 7

Kiranmai_KVL
Kilo Sage

Hello Pritam,

 

1) Call the email script from the Message HTML in your notification using the below syntax : 

E.G : ${mail_script:change_request_details}

 

Kiranmai_KVL_0-1687328207803.png

 

2) Now go to left navigation -> Type email script & open 'Notification email script' & either create new script if it's not available or open existing script.

In the email script, you can get & check the system property value using the below syntax 

EG : var days = parseInt(gs.getProperty("glide.ui.autoclose.time"));

 

You can refer to OOB email scripts such as 'incident_resolved_incident' or 'incident_body ' & see how its implemented.

Kiranmai_KVL_1-1687328475723.png

 

Let me know if that helps or if you have any further questions.

 

 

Community Alums
Not applicable

Hi @Pritam_Pawar225 ,

In the "Message HTML", usually I call a default stylesheet just in case of I need to change any HTML tag (font, size, etc).
  • Add <p>${mail_script:notification_email.styles}</p>.
To use a mail script, 
  • Navigate to System Notification > Email > Notifications Email Scripts
  • Click New: "Notification_email.styles"
  • On the your email script:
    var stylesheet = new GlideRecord ('sp_css');
    stylesheet.get('name','company_email_notifications.css'); //Stylesheet for email styling
    template.print('<div><style>' + stylesheet.css + '</style></div>');

3. Navigate to System Notification > Email > Notifications.
4. Open the email notification record that should use the template.
5. Navigate to the What it will contain section.
6. From the Email Template field, select the appropriate template.
7. Click Update.

 

From :https://www.servicenow.com/community/now-platform-forum/using-system-properties-in-email-layouts/m-p...

 

Pritam_Pawar225
Tera Contributor

Thanks guys for your the response Ankur Bawiskar Kiranmai_KVL and Sandeep Dutta 

actually I just have to return the value of system property in Email script(refer capture 2jpg) and access it in email Notification's what it will contain MessageHTML(refer capture 3jpg)