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

Hi Nithya,

Here you go..

Create a onChange client script on "run_time" field. Use the below Script.

Alter error message as required.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var start = "05:00:00";
    var end = "11:00:00";
    if (g_form.getValue('run_time') >= 'start' && g_form.getValue('run_time') <= 'end') {
        g_form.addErrorMessage("Time not allowed between 5 -11");
		g_form.clearValue('run_time');
    }

}

KarthigaS_0-1691752129904.png

 

Please mark it correct if you find this useful!

 

Regards,

Karthiga

 

 

 

Community Alums
Not applicable

Hi Karthiga,

The script you mentioned below, if condition is not satisfied ,
 g_form.getValue('run_time') >= 'start' is coming true but
g_form.getValue('run_time') <= 'end' is coming false

if (g_form.getValue('run_time') >= 'start' && g_form.getValue('run_time') <= 'end') {
        g_form.addErrorMessage("Time not allowed between 5 -11");
		g_form.clearValue('run_time');
    }

 

Thanks,
Nithya.

 

Hi @Community Alums ,

Try this, I have tested it.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    
    var start = new Date();
    start.setHours(5, 0, 0, 0); 

    var end = new Date();
    end.setHours(11, 0, 0, 0);

    var runTimeValue = g_form.getValue('run_time');
    var time_separated = runTimeValue.split(":");
    
    if (time_separated.length === 3) {
        var currentHour = parseInt(time_separated[0]);
        
        if (!g_user.hasRole('admin') && !isNaN(currentHour) && currentHour >= 5 && currentHour < 11) {
            g_form.addErrorMessage("Report creation is not allowed between 5 AM and 11 AM.");
            g_form.clearValue('run_time');
        } else {
          //allowed
        }
    }
}

 

Hello Nithya,

 

Adding with Variable works!

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var start = "05:00:00";
    var end = "11:00:00";
	var actual = g_form.getValue('run_time');
    if ( actual >= start && actual <= end){
        g_form.addErrorMessage("Time not allowed between 5 -11");
		g_form.clearValue('run_time');
    }}

 

Please mark it correct & helpful if you find this useful!

 Thanks,

Nithya

Community Alums
Not applicable

Hi Karthiga,

want the script for onSubmit because, the record should not be saved. while we using client script validation is happened but record is saved 

Used the same validation for onSubmit but it is not worked

Can i have the script for onsubmit

 

Thanks,

Nithya.