If your date isn't showing in the preview notification, it’s possible that there might be an issue with the mail script or the way it's being called. Let’s troubleshoot and make sure everything is set up correctly:
1. Verify the Mail Script
First, double-check the mail script to ensure it’s correct and active:
- Navigate to
System Notification > Email > Notification Email Scripts.
- Find and open your script
CalculateTenDaysFromNow.
- Verify the script:
(function() {
// Get the current date
var currentDate = new GlideDateTime();
// Add 10 days to the current date
currentDate.addDays(10);
// Format the date as per your requirement, e.g., 'yyyy-MM-dd'
var tenDaysFromNow = currentDate.getLocalDate().toString(); // Ensure it is a string
// Return the formatted date
return tenDaysFromNow;
})();
Ensure there are no syntax errors and the script is active.
2. Check the Notification
Ensure that the notification is correctly using the mail script. Here’s how:
- Navigate to
System Notification > Email > Notifications.
- Open the relevant notification.
- In the
Message field, ensure the syntax is correct. Proper use of ${mail_script} should be:
Please approve this task before ${mail_script:CalculateTenDaysFromNow} via ${URI}
3. Test the Mail Script
To confirm the mail script works correctly, you can test it directly:
- Use the Script Editor:
- Navigate to
System Definition > Scripts - Background.
- Run the following script to test:
var currentDate = new GlideDateTime();
currentDate.addDays(10);
var tenDaysFromNow = currentDate.getLocalDate().toString();
gs.print(tenDaysFromNow);
Check the output to ensure it returns the expected date 10 days from now.
4. Enable Logging in Mail Script
You can add logging to the mail script to see if it’s being executed and what value it’s returning.
- Modify the mail script to include logging:
(function() {
// Get the current date
var currentDate = new GlideDateTime();
// Add 10 days to the current date
currentDate.addDays(10);
// Format the date as per your requirement, e.g., 'yyyy-MM-dd'
var tenDaysFromNow = currentDate.getLocalDate().toString(); // Ensure it is a string
// Log the value to the system log
gs.log('Calculated ten days from now: ' + tenDaysFromNow);
// Return the formatted date
return tenDaysFromNow;
})();
Check the system logs to see if the script is running and what value it’s returning:
- Navigate to
System Logs > System Log > All and look for your log entry.
5. Check Script Include Permissions (Advanced)
If the script still isn’t functioning, verify that script includes and mail scripts have the necessary permissions and visibility:
- Navigate to
System Definition > Script Includes.
- Look for any dependencies that might affect your script.
6. Ensure Correct Notifications Configuration
Ensure the notification conditions are met and the notification is triggered under the right circumstances. Use the Send Test Notification functionality to see a preview.
Conclusion
If, after all these steps, the date still doesn’t appear, consider reaching out to the ServiceNow community or your internal developers for further assistance. Sometimes, issues can stem from instance-specific configurations or constraints needing a deeper investigation.