How to schedule a report 6 times a day?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2025 12:28 AM
Hi,
I wanted script on this please.
reports be triggered six times daily (including weekends) at the specific time slots listed below:
- 4 PM IST (6:30 AM EST)
- 7 PM IST (9:30 AM EST)
- 10 PM IST (12:30 PM EST)
- 1 AM IST (3:30 AM EST)
- 4 AM IST (6:30 PM EST)
- 7 AM IST (9:30 AM EST)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2025 12:40 AM - edited 07-01-2025 12:41 AM
Hi @nitin51,
and what issue do you face, can you share your script or do you expect that somebody will do it all for you?
It is important to give some more details, because "script" is very abstract, there are several types of it and each have a little bit different usage and procedures. So what exactly is the purpose of the whole thing?
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2025 12:43 AM
hi @nitin51 ,
1. Create a Script Include (reusable report logic)
Create a Script Include named, for example, GenerateMyCustomReport. This will hold your actual logic to run the report (you can modify this to generate PDF, send email, etc.).
var GenerateMyCustomReport = Class.create();
GenerateMyCustomReport.prototype = {
initialize: function() {},
run: function() {
// Example: Count all timecards created today
var gr = new GlideAggregate('time_card');
gr.addAggregate('SUM', 'hours');
gr.addEncodedQuery('start_dateONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()');
gr.query();
if (gr.next()) {
var total = gr.getAggregate('SUM', 'hours');
gs.info('⏱️ Total timecard hours today: ' + total);
}
// You can replace this with logic to generate/export a report, notify users, etc.
},
type: 'GenerateMyCustomReport'
};
Create 6 Scheduled Jobs
Go to System Definition > Scheduled Jobs > New and create 6 separate Scheduled Script Executions:
For each job:
Name: Run Report - 4 PM IST (and so on)
Run: Daily
Time: Set according to your IST schedule
Script
new GenerateMyCustomReport().run();
If you want the script to generate a report and email it, I can include the logic to:
Generate a report PDF
Attach to email
Send to defined recipients
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2025 12:45 AM
Hi @nitin51
Check out the below script sample and modify as required.
var answer;
var date = new GlideDateTime();
var time = date.getTime().getDisplayValue();
var hour = time.split(':')[0];
if ((hour == '01') || (hour == '04') || (hour == '07') || (hour == '13') || (hour == '19') || (hour == '22')) {
answer = true;
} else {
answer = false;
}
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2025 12:47 AM
Hi @nitin51 ,
You don't need to really create a script to achieve this.
My solution is:
1. Create 6 scheduled email reports ( 1 for each time means one for 4 PM IST and one for 7 PM IST like this).
2. Run->daily and time will be different for each of the schedule job as you required.
refer this screenshot:
Another alternative is:
You can use a Scheduled Script Execution in ServiceNow that runs every minute and checks if the current IST time matches one of your six predefined trigger times. If it matches, the script executes your report logic. This ensures precise control over report timing, even across weekends.
Downsides:
- Running the script every minute may slightly impact performance, especially in high-load environments.
Please mark this as helpful and correct, if this solves your question.
Thanks