- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2016 09:13 AM
I have a need to display a date 7 days from the current day in the subject line of a notification in a ServiceNow workflow.
new GlideDateTime(gs.daysAgo(-7)).getDate()
This JS works, but it doesn't work in the subject line of the notification.
How do I put this JS into the subject line of the notification?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2016 10:17 AM
I would strongly suggest not using the Notification workflow activity. The To(script) is used to determine the recipients, it is not used to format the message. I would send an event instead. Here is a wiki article on using events in workflows:
Notification Activities - ServiceNow Wiki
Depending upon how this notification is being used will determine if we actually need this. It sounds like you want a custom subject for tasks that are generated. Is this correct?
You could leverage the task creation workflow activity to set the short description of the task:
Task Activities - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2016 09:23 AM
In your notification, you will need to use the setSubject() method. For more information on this, see the following WIKI article:
Scripting for Email Notifications - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2016 09:38 AM
Also, it is unclear if you are running your notification from within the workflow, or are triggering the notification from an event.
I would suggest creating a notification outside of the workflow and triggering it from an event within the workflow. That way you can pass a parameter of the date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2016 09:54 AM
I am running the notification from within the workflow. I am getting a warning and the notification is not being sent.
Warning | org.mozilla.javascript.EcmaError: "setSubject" is not defined. Caused by error in <refname> at line -1 |
Here is the To(script) from my notification:
// Set the variable 'answer' to a comma-separated list of user or group sys_ids that you want the email sent to.
var duedate = new GlideDateTime(gs.daysAgo(-7)).getDate();
setSubject("[USU: Urgent] Action is required on " + current.u_endpoint_name + " by " + duedate);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2016 10:17 AM
I would strongly suggest not using the Notification workflow activity. The To(script) is used to determine the recipients, it is not used to format the message. I would send an event instead. Here is a wiki article on using events in workflows:
Notification Activities - ServiceNow Wiki
Depending upon how this notification is being used will determine if we actually need this. It sounds like you want a custom subject for tasks that are generated. Is this correct?
You could leverage the task creation workflow activity to set the short description of the task:
Task Activities - ServiceNow Wiki