How to populate date in a field based on a another field value on catalog form.

Shaik nabi khaj
Tera Expert

Hi,

I have a catalog form.In which i have two fields.

Field one-- is a single line text type.

Field two--is a date type.

So now my requirement is whenever we enter 1 value in field one  then field two must populate todays date.

And when we enter 2 value in field one then field two must populate tomorrow date.

And when we enter 3 in field one then field two must populate day after tomorrow date....etc.

Kindly provide ur inputs,it is on priority.

 

@Ankur Bawiskar 

 

Best Regards,

Shaik Nabi Khaja.

 

 

 

2 ACCEPTED SOLUTIONS

Hi taha,

Just now i have implemented but is is not working.

Have u tried this code in ur PDI.

Please help me.

Thanks,

Shaik

View solution in original post

Hey Nabi,
Try the following script in your script include, you just have to change the function to use 

"addYearsLocalTime."

 

var ScriptIncludeExampleThree = Class.create();
ScriptIncludeExampleThree.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	helloWorld:function() {
		gs.log("lolatleast");
		//var dtc= this.getParameter('caldate');
		var days= this.getParameter('noofday');
		
		var gdt = new GlideDateTime();
		//gdt.setValue(dtc);
       // gdt.addDaysLocalTime(days);
		//gdt.addDaysLocalTime(-1);      // to implement for 1 value to have today's date and so on
	gdt.addYearsLocalTime(days);
	gdt.addYearsLocalTime(-1);
		
        gs.info(gdt.getLocalDate());
		
		return (gdt.getLocalDate());
	} ,
	type: 'ScriptIncludeExampleThree'
});



View solution in original post

6 REPLIES 6

Hi Taha,

I have another requirement is 

whenever we enter 1  then date must populate next years today date like 2022-12-23 is

2023-12-23 

whenever we enter 2 then date must populate next years tomorrow date like 2022-12-24 is

2023-12-24 ...etc...

please provide ur input.

 

Thanks,

Shaik

Hey Nabi,
Try the following script in your script include, you just have to change the function to use 

"addYearsLocalTime."

 

var ScriptIncludeExampleThree = Class.create();
ScriptIncludeExampleThree.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	helloWorld:function() {
		gs.log("lolatleast");
		//var dtc= this.getParameter('caldate');
		var days= this.getParameter('noofday');
		
		var gdt = new GlideDateTime();
		//gdt.setValue(dtc);
       // gdt.addDaysLocalTime(days);
		//gdt.addDaysLocalTime(-1);      // to implement for 1 value to have today's date and so on
	gdt.addYearsLocalTime(days);
	gdt.addYearsLocalTime(-1);
		
        gs.info(gdt.getLocalDate());
		
		return (gdt.getLocalDate());
	} ,
	type: 'ScriptIncludeExampleThree'
});