- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2025 12:00 PM
Hello,
I want to dynamically set the report subject as The generated week report - 10/02/2025-19/02/2025.
I tried setting up javascript:new myscriptinclude().getSubject();, on the subject field, but no luck. I set the calculated date on the Subject field, but that's not a good idea as it will be global subject. I have a script which give me dates for the current date and the date of the last week's monday.
But I need to dynamically populate that subject. How can I approach this??
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 11:19 PM
@priyamkh199 You can create an email notification script and use APIs such as email.setSubject,email.setBody etc and have that script called in the message body part like ${mail_script:"name_of_your_script'}.
Mark my response as helpful if it worked for you.
Thanks,
Mahesh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 11:19 PM
@priyamkh199 You can create an email notification script and use APIs such as email.setSubject,email.setBody etc and have that script called in the message body part like ${mail_script:"name_of_your_script'}.
Mark my response as helpful if it worked for you.
Thanks,
Mahesh.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 11:44 PM
Hello @priyamkh199 ,
First of all create one script include which will create the subject dynamically
Second create one email script and in the email script call the script include
Script include :
var DynamicSubjectGenerator = Class.create();
DynamicSubjectGenerator.prototype = {
initialize: function() {
},
// Method to get the report subject dynamically
getSubject: function() {
var today = new GlideDateTime(); // Current date and time
var currentDate = today.getDate(); // Get current date in MM/DD/YYYY format
// Calculate previous week's Monday
var previousMonday = this.getPreviousMonday(today);
var formattedPreviousMonday = previousMonday.getDate(); // Get date in MM/DD/YYYY format
// Format the subject string
return "The generated week report - " + formattedPreviousMonday + " - " + currentDate;
},
// Method to calculate the date of last week's Monday
getPreviousMonday: function(currentDate) {
var dayOfWeek = currentDate.getDayOfWeek();
var daysToSubtract = (dayOfWeek == 1) ? 7 : dayOfWeek - 1; // If today is Monday, subtract 7 days
var previousMonday = new GlideDateTime(currentDate);
previousMonday.addDaysUTC(-daysToSubtract); // Subtract to get previous Monday
return previousMonday;
},
type: 'DynamicSubjectGenerator'
};
Calling script include from email script:
var reportSubject = new DynamicSubjectGenerator().getSubject();
current.subject = reportSubject; // Assign the dynamic subject to the report
current.update(); // Save the report record with the new subject
calling email script from scheduled report:
${mail_script:"name_of_your_script'}.
Please mark this as correct/helpful if this helps you.
Regards,
Debasis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 11:57 PM
Create Script inlcude:
var ReportUtils = Class.create();
ReportUtils.prototype = {
initialize: function() {},
getSubject: function() {
var today = new GlideDateTime();
var lastMonday = new GlideDateTime();
lastMonday.addDaysUTC(-today.getDay() + 1 - 7); // Last week's Monday
var startDate = lastMonday.getLocalDate();
var endDate = today.getLocalDate();
return "The generated week report - " + startDate + " - " + endDate;
},
type: 'ReportUtils'
};
Create mail script:
(function runMailScript(current, template, email, email_action, event) {
var subject = new ReportUtils().getSubject();
email.setSubject(subject);
})(current, template, email, email_action, event);
In your report subject call this mail script:
${mail_script:"name_of_your_script'}
Please mark/corrcet helpful if this helps you!