In date/time variable,should be selected in PST time zone and should not allow past dates selection

Bhanu_thej
Tera Contributor

Hi @Ankur Bawiskar @Maik Skoddow @Mohith Devatte @SwarnadeepNandy @SANDEEP28 

 

My requirement is,In date/time variable,date should be selected in PST time zone and should not allow users to select past dates.

 

i have already an existing client script which makes users not to select PST time zone.Here is the screenshot below 

 

Bhanu_thej_0-1695265824202.png

Please help me on my requirement.

13 REPLIES 13

Ankur Bawiskar
Tera Patron
Tera Patron

@Bhanu_thej  

to restrict past date you can compare the time

please share the script here and not the screenshot.

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

Hi @Ankur Bawiskar 

 

please find the script which i have using not to select past dates.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {    
if (isLoading || newValue === '') {
        return;
    }
 
 
 
    var currentDate = new Date();
    var refreshDate = new Date(g_form.getValue('start_date'));
    if (refreshDate.valueOf() < currentDate.valueOf()) {
        
         g_form.addErrorMessage('Date shuold be in Future Date');
g_form.clearValue('start_date');
       // g_form.showFieldMsg('revised_refresh_date', "Date Should not a Past Date", 'error');
return false;
    }
    
}

 

@Bhanu_thej  

update as this

function onChange(control, oldValue, newValue, isLoading, isTemplate) {    
	if (isLoading || newValue === '') {
		return;
	}

	var currentDate = new Date().getTime();
	var refreshDate = new Date(g_form.getValue('start_date')).getTime();
	if (refreshDate < currentDate) {
		var message = 'Date shuold be in Future Date';
		g_form.showErrorBox('start_date', message);
		g_form.clearValue('start_date');
		// g_form.showFieldMsg('revised_refresh_date', "Date Should not a Past Date", 'error');
	}

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi @Ankur Bawiskar 

 

tried with the above script provided by you, not working, Any suggestions why this was not working.