I am trying to display a date 7 days from current day in the subject line

samallred
Kilo Contributor

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?

1 ACCEPTED SOLUTION

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


View solution in original post

5 REPLIES 5

ccajohnson
Kilo Sage

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


ccajohnson
Kilo Sage

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


samallred
Kilo Contributor

I am running the notification from within the workflow.   I am getting a warning and the notification is not being sent.



Warningorg.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);


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