Restrict time on schedule Report

Community Alums
Not applicable

Hello Experts,

I want to acheive the below requirement

Restrict the slot 5am to 11am on creating a schedule report. How can i acheive this?

Thanks,
Nithya.

13 REPLIES 13

Hello @Community Alums

 

Just change the type of the client script to Onsubmit and you can reuse the script like below.

 

This works fine. I have tested it.

function onSubmit() {
   //Type appropriate comment here, and begin script below
	var start = "05:00:00";
    var end = "11:00:00";
	var actual = g_form.getValue('run_time');
    if ( actual >= start && actual <= end){
	//if(actual <= end) {
        g_form.addErrorMessage("Time not allowed between 5 -11");
		g_form.clearValue('run_time');}
   
}

Please mark it Correct and Hit Like if you find this helpful!

 

Regards,

Karthiga

 

Community Alums
Not applicable

Hi Karthiga,

Issue am facing while changing the existing schedule Report after submitting Time value set to before what they are mentioned. But for below script is working for new creation of schedule report but not for existing one.

 
var start = "05:00:00";
var end = "11:00:00";
var actual = g_form.getValue('run_time');

 

if ( actual >= start && actual <= end){
// Show an error message to the user
g_form.addErrorMessage("Report creation is not allowed between 5 AM to 11 AM.");
//g_form.clearValue('run_time');
//g_form.setValue('run_time',"02:00:00");
 
// Return false to cancel the submit event
return false;
}
// If the form should not be rejected, return true to allow the submission
return true;
}

Thanks,
Nithya.

Ankur Bawiskar
Tera Patron
Tera Patron

@Community Alums 

there is no OOB slot selection on scheduled report form

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

SwarnadeepNandy
Mega Sage

Hello Nithya,

 

To restrict the slot 5am to 11am on creating a schedule report in ServiceNow, you can use the Conditional and Condition fields in the Scheduled Reports form. These fields allow you to specify a script that evaluates whether the report should run or not. For example, if you want to run a report only between 5am and 11am on weekdays, you can use this script in the Condition field:

var s = new GlideSchedule("08fcd0830a0a0b2600079f56b1adb9ae"); //sys_id of the OOB 8-5 weekdays schedule
var gdt = new GlideDateTime();
var hour = gdt.getNumericValue().substring(8,10); //get the hour part of the current date/time
s.isInSchedule(gdt, "US/Pacific") && hour >= 5 && hour < 11; //check if the current date/time is in the schedule and the hour is between 5 and 11

This script will return true if the current date/time is in the 8-5 weekdays schedule and the hour is between 5 and 11, and false otherwise. You can change the schedule sys_id and the timezone according to your needs.

 

I hope this helps.

 

Kind Regards,

Swarnadeep Nandy