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:25 AM
addDateAmount: function(){
var firstDT = this.getParameter('sysparm_fdt'); //First Date Field
var addTYPE = this.getParameter('sysparm_addtype'); //What to add - day (addDays()), week (addWeeks()), month (addMonths()), year (addYears())
var addTIME = this.getParameter('sysparm_addtime'); //How much time to add
var day = GlideDate();
day.setValue(firstDT);
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;
},
It's working but, not correct. Need in terms of date/time format

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2022 02:11 AM
Hi,
Please try below:
addDateAmount: function(){
var firstDT = this.getParameter('sysparm_fdt'); //If you want to add day/time in current date then no need to pass this parameter
var addTYPE = this.getParameter('sysparm_addtype'); //What to add - day (addDays()), week (addWeeks()), month (addMonths()), year (addYears())
var addTIME = this.getParameter('sysparm_addtime'); //How much time to add
var day = new GlideDateTime(); // this will give you current date and time
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.getDisplayValue(); // return display value
},
Thanks
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2022 03:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2022 02:53 AM
Hello Ashoka,
Please try this solution.
Script Include :
I have hard coded the values of addSeconds(), you can get from your variable.
Client Script :
This is output I get :
Hope this will help you
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2022 03:54 AM