GlideDate() is working in client Script, however the requirements should be in GlideDateTime (). Is there anyone who can assist me with this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2022 12:12 AM
var recPriority = g_form.getValue('u_rec_rating');
var cdt = new Date(); // When I use GlideDateTime() it's showing error.
var addtime;
var addtype = 'day';
if (recPriority == '2') {
addtime = 7; //The amount of time to add
}
if (recPriority == '3' || recPriority == '4') {
addtime = 90; //The amount of time to add
}
var ajax = new GlideAjax('global.ClientDateTimeUtils');
ajax.addParam('sysparm_name', 'addDateAmount');
ajax.addParam('sysparm_fdt', cdt);
ajax.addParam('sysparm_addtime', addtime);
ajax.addParam('sysparm_addtype', addtype);
ajax.getXML(doSomething); //Need callback function
function doSomething(response) {
//Sets field
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('due_date', answer);
Current Result:
Expected : DateTime
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2022 01:21 AM
addDateTimeAmount: function(){
var firstDT = this.getParameter('sysparm_fdt'); //First Date-Time Field
var addTYPE = this.getParameter('sysparm_addtype'); //What to add - second (addSeconds()), minute (need to add conversion), hour (need to add conversion), day (addDays()), week (addWeeks()), month (addMonths()), year (addYears())
var addTIME = this.getParameter('sysparm_addtime'); //How much time to add
var day = GlideDateTime(firstDT);
if(addTYPE == 'second'){day.addSeconds(addTIME);}
else if (addTYPE == 'minute'){day.addSeconds(addTIME*60);}
else if (addTYPE == 'hour'){day.addSeconds(addTIME*(60*60));}
else if (addTYPE == 'day'){day.addDays(addTIME);}
else if (addTYPE == 'week'){day.addWeeks(addTIME);}
else if (addTYPE == 'month'){day.addMonths(addTIME);}
else if (addTYPE == 'year'){day.addYears(addTIME);}
else {day.addDays(addTIME);}
//return "First Date: " + firstDT + " -Time to Add: " + addTIME + " -Add Type: " + addTYPE + " -Added Time: " + day;
return day;
},
I've used this one, it is not working

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2022 02:31 AM
Hi Ashoka,
Check below code i have tested in background script, it's working fine for me, you can remove testing code lines and try in your script include
var firstDT = this.getParameter('sysparm_fdt'); //Ensure this is datetime variable
var addTYPE = this.getParameter('sysparm_addtype'); // it should be string
var addTIME = this.getParameter('sysparm_addtime'); // it should be integer value
var day = GlideDateTime(firstDT);
// for testing purpose in backgorund script
//var addTYPE ='year'; // for test
//var addTIME = 2; // for test
//var day = GlideDateTime(); // for test adding values in todays date
var days = addTIME;
var week = days * 7;
var month = days * 30;
var year = days * 365;
if (addTYPE == 'day') {
day.addDays(days);
} else if (addTYPE == 'week') {
day.addDays(week);
} else if (addTYPE == 'month') {
day.addDays(month);
} else if (addTYPE == 'year') {
day.addDays(year);
} else {
day.addDays(days);
}
// gs.print('Check-5 Type is :' + addTYPE + " Add Time : "+ addTIME + " Date after adding addTime :" + day);
return day.getDisplayValue();
Result :

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2022 04:22 AM
Hi Have you tried above script ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2022 04:39 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2022 05:02 AM
Hi
where ever you have used GlideDateTime make sure syntax should be like this
var day = new GlideDateTime();
and make sure it is Server-side code, don't use it in Client script.
Check these 2 things and let me know