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

Taha Habib
Tera Guru

Hello Shaik nabi khaj,

You can use a combination of catalog client scripts and the client callable script include to fulfill this requirement.
I have created the required scripts for your requirement, please have a look at it. I hope it helps you.
Here date is the backend name of your date field and integer_value is the backend name of your integer.

Catalog Client Script which will run on change of the integer field.

 

 

function onChange()
{
    var datepass= g_form.getValue('date'); 
	var day= g_form.getValue('integer_value');
	var ga = new GlideAjax('global.ScriptIncludeExampleThree');
ga.addParam('sysparm_name', 'helloWorld');	
ga.addParam('noofday', day);	
ga.addParam('caldate', datepass);
ga.getXML(HelloWorldParse);
 
function HelloWorldParse(response) {
  var answer = response.responseXML.documentElement.getAttribute("answer");
  //alert(answer);
  g_form.setValue('date', answer);	
}	

}

 

 


Client Callable script Include:

 

 

var ScriptIncludeExampleThree = Class.create();
ScriptIncludeExampleThree.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	helloWorld:function() {
		//gs.log("lol atleast");
		//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
        gs.info(gdt.getLocalDate());
		
		return (gdt.getLocalDate());
	} ,
	type: 'ScriptIncludeExampleThree'
});

 

 


Catalog client script:

TahaHabib_0-1671787691661.png


Script Include:

TahaHabib_1-1671787736910.png

 

 Result:

 

TahaHabib_2-1671787997158.pngTahaHabib_3-1671788012295.png

 

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

Hi Taha,

Just now i have implemented again.

it is working as expected as.

Thanks alot.

 

Best Regards,

Shaik Nabi Khaja.

If you find the solution helpful mark it as Helpful please, Thank you.