Add 1 year to the date field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2024 07:01 AM
We have 2 date fields warranty and retire. Based on the value filled in warranty , 1 year should to be added to that and update retire. Please suggest.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2024 07:55 AM - edited ‎06-04-2024 07:56 AM
Hi @DivyaNarayG
You can use client script and script include:
Client script :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var startdate=g_form.getValue('start_date');
var date=new GlideAjax('GetManagerDetailsScript');
date.addParam('sysparm_name','getdatevalue');
date.addParam('sysparm_date',startdate);
date.getXMLAnswer(callback);
function callback(response){
var answer= response;
alert(answer); // use g_form.setValue('field_name',answer);
}
//Type appropriate comment here, and begin script below
}
Script Inlcude:
var GetManagerDetailsScript = Class.create();
GetManagerDetailsScript.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getdatevalue: function(){
var startdatevalue=this.getParameter('sysparm_date');
var year =1;
var gdt = new GlideDateTime(startdatevalue);
gdt.addYearsUTC(year);
gs.info("the date is "+gdt.addYearsUTC(year));
return gdt.getDate();
}
});
Thanks and Regards
Sai Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2024 10:39 PM - edited ‎06-04-2024 10:53 PM
Hi Sai ,
If I enter the start date as 01-05-2024 (mm-dd--yyyy), then end date is getting updated as 05-01-2025. But if start date is 22-11-2024, then end date is updated as 22-11-2025 . So when date and month is less than 12 , it is swapping the values. How can we correct this.