How can I add 27 months to a date field in a task

John H1
Tera Guru

I currently have a need to populate a date field within a SCTask.

Issue Date - manually entered

Expire Date - Issue Date + 27 months

1 ACCEPTED SOLUTION

Hi,

Below is the script include code (attached the xml as well)

var myDateUtil = Class.create();
myDateUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	getEndDate:function()
	{
		var dt1=this.getParameter('sys_parm_issue_dt');
		var how_many_months=this.getParameter('sys_parm_how_many_months');
		var dt=new GlideDateTime(dt1);
		dt.addMonthsLocalTime(parseInt(how_many_months));
		return dt.getDate();
	},

    type: 'myDateUtil'
});

Below is the onChange client script on the variable issue date

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading) {
		return;
	}
	if(newValue === '')
	{
		g_form.clearValue('end_date');
	}
	var ga = new GlideAjax('myDateUtil'); 
	ga.addParam('sysparm_name','getEndDate'); 
	ga.addParam('sys_parm_issue_dt',newValue); 
	ga.addParam('sys_parm_how_many_months',27); 
	ga.getXML(cb);  

	// the callback function for returning the result from the server-side code
	function cb(response) {  
		var answer = response.responseXML.documentElement.getAttribute("answer"); 
		if(answer)
		g_form.setValue('end_date',answer);
	}


	//Type appropriate comment here, and begin script below

}

If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.

Regards,
Saurabh


Thanks and Regards,

Saurabh Gupta

View solution in original post

7 REPLIES 7

Date Operation you can from Server script.

If you want this from client side you should be using GlideAjax.

Let me know the complete requirement with all variables/fields name will help you in write script. 

If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.

Regards,
Saurabh


Thanks and Regards,

Saurabh Gupta

Thanks, 

I have a Catalog Item and this would involve two (2) date fields, 

Issue Date (let call it issue_date)

End Date (let call it end_date)

What I need is when the users enters an Issue Date it will add 27 months and populate the End Date.

 

Hi,

Below is the script include code (attached the xml as well)

var myDateUtil = Class.create();
myDateUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	getEndDate:function()
	{
		var dt1=this.getParameter('sys_parm_issue_dt');
		var how_many_months=this.getParameter('sys_parm_how_many_months');
		var dt=new GlideDateTime(dt1);
		dt.addMonthsLocalTime(parseInt(how_many_months));
		return dt.getDate();
	},

    type: 'myDateUtil'
});

Below is the onChange client script on the variable issue date

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading) {
		return;
	}
	if(newValue === '')
	{
		g_form.clearValue('end_date');
	}
	var ga = new GlideAjax('myDateUtil'); 
	ga.addParam('sysparm_name','getEndDate'); 
	ga.addParam('sys_parm_issue_dt',newValue); 
	ga.addParam('sys_parm_how_many_months',27); 
	ga.getXML(cb);  

	// the callback function for returning the result from the server-side code
	function cb(response) {  
		var answer = response.responseXML.documentElement.getAttribute("answer"); 
		if(answer)
		g_form.setValue('end_date',answer);
	}


	//Type appropriate comment here, and begin script below

}

If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.

Regards,
Saurabh


Thanks and Regards,

Saurabh Gupta