Add 6 months to a variable date (on change) and display result in another field.

rao_2017
Kilo Contributor

Hi ,

  We have a two variables in a catalog item start and end date if the start date is changed then the changed date should add 6 months and display the output in End date variable.

 

 Does anyone have done idea on this?

 

Done with the catalog client script using the below script this returns an error while the date format is dd-mm-yyy and dd/mm/yyyy

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('DateTimeAjaxFunctions');// DateTimeAjaxFunctions is a script include 
ga.addParam('sysparm_name','nowDateTime');
ga.getXML(callback);
var retdt = g_form.getValue('end_date');
function callback(response){
var now = response.responseXML.documentElement.getAttribute("answer");
ga.addParam('sysparm_name','addMonths');
ga.addParam('startDate',newValue);
ga.addParam('monthsToAdd',6);
ga.getXML(callback1);
}
function callback1(response)
{
var sixMonthsFromNow = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('end_date',sixMonthsFromNow);
}
}

 

6 REPLIES 6

All the things are working fine as expected .There is a problem only when we change the format date got changed to 'DD-MM-YYYY' and DD/MM/YYYY

Hi Rao,

Any update on this?
Can you mark my answer as correct, helpful if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader