The CreatorCon Call for Content is officially open! Get started here.

user should not able to select 7 days in date/time field

suuriya
Tera Contributor

Hi

I have a requirement, in catalog form there is date/time field while entering the date, next 7 days user should not able to enter it for example today is NOV 23 and user is raising the request today means user should not able to select nov 23 24 25 26 27 28 29 from nov 30 only he can able to select in the field. Similarly, if today is nov 24 then 24 25 26 27 28 29 30 shouldnot be selectable

Please help me with the full script 

Thanks & Regards,

Suuriya

1 ACCEPTED SOLUTION

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @suuriya ,

Use catalog client script : Type Onchange , Select proper catalog and variable name

GunjanKiratkar_0-1669224691380.png

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

   //Type appropriate comment here, and begin script below
	var ga=new GlideAjax("getCallerDetails");
	ga.addParam('sysparm_name',"getDetails");
	ga.addParam('sysparm_date',newValue);
	ga.getXMLAnswer(getResult);
	
	function getResult(response){
		if(response =='false'){
			alert("Please select date after 7 days from now");
			g_form.clearValue('date');
		}
	}
   
}

 

Script Include:-

var getCallerDetails = Class.create();
getCallerDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getDetails: function() {
        var currentDate = this.getParameter('sysparm_date');
        var gdt = new GlideDateTime();
        gdt.addDays(6);
		if(currentDate>gdt.getDisplayValue()){
			return true;
		}else{
			return false;
		}
    },


    type: 'getCallerDetails'
});

GunjanKiratkar_1-1669224747367.png

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

View solution in original post

2 REPLIES 2

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

You can use an UI policy to do this.

 

Please check the below article for the same:-

 

https://www.servicenow.com/community/developer-articles/no-code-date-validations-through-catalog-ui-...

 

Please mark my answer as correct based on Impact.

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @suuriya ,

Use catalog client script : Type Onchange , Select proper catalog and variable name

GunjanKiratkar_0-1669224691380.png

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

   //Type appropriate comment here, and begin script below
	var ga=new GlideAjax("getCallerDetails");
	ga.addParam('sysparm_name',"getDetails");
	ga.addParam('sysparm_date',newValue);
	ga.getXMLAnswer(getResult);
	
	function getResult(response){
		if(response =='false'){
			alert("Please select date after 7 days from now");
			g_form.clearValue('date');
		}
	}
   
}

 

Script Include:-

var getCallerDetails = Class.create();
getCallerDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getDetails: function() {
        var currentDate = this.getParameter('sysparm_date');
        var gdt = new GlideDateTime();
        gdt.addDays(6);
		if(currentDate>gdt.getDisplayValue()){
			return true;
		}else{
			return false;
		}
    },


    type: 'getCallerDetails'
});

GunjanKiratkar_1-1669224747367.png

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy