How to schedule a report twice a day 10 AM and 6 PM IST?

sri83
Tera Guru

Hi Team,

 

I want send to report twice per day like 10 AM and 6 PM. So i have selected the periodically option and added the condition as below in script but it's not working. Please help me on this

Conditions:

sri83_0-1678257686075.png

 

Script:

 

answer = ifScript();

function ifScript() {

var gdt = new GlideDateTime();
var currentTime = gdt.getLocalTime().getByFormat('hh:mm:ss');
if (currentTime == "10:00:00" || currentTime == "18:00:00") {
return true;
} else {
return false;
}
}

 

4 REPLIES 4

SatyakiBose
Mega Sage

Hello @sri83 

Your report needs to configured as below:

SatyakiBose_0-1678260448089.png

 

Starting time = 10am -> sends the report

Repeat interval = 8h - waits 8hours(it will send report at 6pm again)

days = 1 (which means this cycle runs only for 1 day)

The next schedule will be next day at 10am.

AndersBGS
Tera Patron
Tera Patron

Hi @sri83 ,

 

Please see documentation for scheduling a report here: https://docs.servicenow.com/en-US/bundle/utah-platform-administration/page/administer/reference-page...

 

In general you can accomplish this without scripting as you already have created except, then you would also receive the report at 2AM. 

 

If you would like to utilize the script, to not get the third report, what error does your script throw or what is your output?

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

Best regards

Anders 

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

Hi Anders,

 

After execute the job, even single loop also not executing is the script to avoid the 2 AM report

Please help me how to avoid the 2 PM report 

 

Regards,

Sri

Hi @sri83 ,

 

Please utilize this script - this should work:

//Default answer
var answer = false;
//Finds the current time
var now = timenow2(); 
//Get curent time in HH:mm format
currentTime = timenow2();

if (currentTime == "10:00" || currentTime == "18:00") {
answer = true;
}else{
answer = false;
}

function timenow2()
{
  var gdttimeTmp = new GlideDateTime().getDisplayValue(); 
  var gdttime = new GlideDateTime(gdttimeTmp);
  var time = gdttime.getTime();
  var currentTime = time.getByFormat('HH:mm');
  
  return currentTime;
}

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

Best regards

Anders

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/