Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Set End date should be 90 days from Start date in service caralog

Surendra6
Tera Contributor

Can anyone please provide a script to auto set the end date to 90 days from the start date selection.

 

Thanks in advance.

3 REPLIES 3

RohiniS87886285
Kilo Sage

Hello @Surendra6 ,

Write client script with client callable script include.

var MyDateTimeAjax = Class.create();

 

MyDateTimeAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {

 

calDate: function () {

 

var sdt = new GlideDateTime(this.getParameter('sysparm_date'));

 

sdt.addDaysLocalTime(90);

 

return sdt.getDate();

 

},

 

type: 'MyDateTimeAjax'

 

});

 

Client Script:

 

var gr = new GlideAjax('MyDateTimeAjax');

 

gr.addParam('sysparm_name', 'calDate');

 

gr.addParam('sysparm_date', g_form.getValue('u_date')); //Please update the field name

 

gr.getXML(ajaxResponse);

 

function ajaxResponse(serverResponse) {

 

var answer = serverResponse.responseXML.documentElement.getAttribute("answer");

 

alert(answer);

 

g_form.setValue('field_name', answer);

 

}

 

Please mark helpful.

 

Regards,

Rohini Sane

SaurabhD8867250
Kilo Sage

On change Client script:

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

   //Type appropriate comment here, and begin script below
   var startDate = g_form.getValue('start_date');

   var ga = new GlideAjax('incidentUtil');
    ga.addParam('sysparm_name', 'addNintyDays');
    ga.addParam('sysparm_temp1', startDate);

	ga.getXMLAnswer(getResponse);

	function getResponse(response){
		alert(response);

		if(response){
			g_form.setValue('end_time',response);
		}
	}

}

 

Script include: 

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

	addNintyDays : function(){

		var startDate = this.getParameter('sysparm_temp1')

		var gTime = new GlideDateTime(startDate);

		gTime.addDays(90);

		return gTime.getValue();
	},

    type: 'incidentUtil'
});

 

This will work...

If my solution helps you please mark accept solution and hit the helpful button

 

Thanks and regards,

Saurabh Dubey.

Sumanth16
Mega Patron

Hi @Surendra6 ,

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    if (newValue == 90) {
		//alert(newValue);
        var current_date = new Date();
		//alert('Current Date'+current_date);
        current_date.setDate(current_date.getDate() + 90);
        var added_date = formatDate(current_date, g_user_date_time_format);
		var getAddedDate = added_date.split(' ');
		//alert('Output Date '+getAddedDate[0]);
        g_form.setValue('output_date', getAddedDate[0]+'');
    }
}

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda