- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2020 10:46 AM
I am trying to add 28 days to a date variable based on date selected in another variable (i.e. both variables are mapped with form fields and the client script should run on employee service center and the HR case form as well). I have written an onChange() catalog client script and a global scope script include. But as soon as I fill first date variable error comes : 'There is a JavaScript error in your browser console'. Can anyone guide me on what I am doing wrong. PFB the client script and the script include :
Type: OnChange()
Variable: u_date_concern_reported
Catalog Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var cdt = g_form.getValue('u_date_concern_reported'); //first date field
var addtime = 28;
var addtype = 'day';
var gr = new GlideAjax('ClientDateTimeUtils');
gr.addParam('sysparm_name', 'addDateTimeAmountt');
gr.addParam('sysparm_fdt', cdt);
gr.addParam('sysparm_addtime', addtime);
gr.addParam('sysparm_addtype', addtype);
gr.getXML(ajaxResponse);
function ajaxResponse(serverResponse){
var answer = serverResponse.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_th_day', answer); //second date field
alert(answer);
}
}
Script Include: ClientDateTimeUtils
Application: Global
Client callable:Checked
Accessible from: All application scopes
var ClientDateTimeUtils = Class.create();
ClientDateTimeUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
addDateAmount: function(){
var firstDT = this.getParameter('sysparm_fdt'); //First Date Field
var addTYPE = this.getParameter('sysparm_addtype');
var addTIME = this.getParameter('sysparm_addtime'); //How much time to add
var day = GlideDate();
day.setDisplayValue(firstDT);
day.addDays(addTIME);
return day.getDisplayValue();
},
type: 'ClientDateTimeUtils'
});
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2020 03:29 AM
Hi neha,
I found some mistakes in your code, I just highlighted that mistake by making those mistakes as Bold. Let me know after correction, are you able to achieve your desire output. If not I can share you some other script as well.
Type: OnChange()
Catalog Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var cdt = g_form.getValue('u_date_concern_reported'); //first date field
var addtime = 28;
var addtype = 'day';
var gr = new GlideAjax('global.ClientDateTimeUtils');
gr.addParam('sysparm_name', 'addDateAmount');
gr.addParam('sysparm_fdt', cdt);
gr.addParam('sysparm_addtime', addtime);
gr.addParam('sysparm_addtype', addtype);
gr.getXML(ajaxResponse);
function ajaxResponse(serverResponse){
var answer = serverResponse.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_th_day', answer); //second date field
alert(answer);
}
}
Script Include: ClientDateTimeUtils
Application: Global
Client callable:Checked
Accessible from: All application scopes
var ClientDateTimeUtils = Class.create();
ClientDateTimeUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
addDateAmount: function(){
var firstDT = this.getParameter('sysparm_fdt'); //First Date Field
var addTYPE = this.getParameter('sysparm_addtype');
var addTIME = this.getParameter('sysparm_addtime'); //How much time to add
var day = new GlideDate();
day.setDisplayValue(firstDT);
day.addDays(addTIME);
return day.getDisplayValue();
},
type: 'ClientDateTimeUtils'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2020 11:16 AM
Hey neha,
Refer the Link Below It may help you:
If it works for you, Mark my answer Correct and Helpful.
Thanks,
Namrata.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2020 11:18 AM
Hi Neha,
Please find how you can add days:-
var gdt = new GlideDateTime("2011-08-31 08:00:00");
gdt.addDays(-1);
gs.print(gdt.getDate());
Output:-
2011-08-30
Please mark answer correct if it helps you.
Thanks
Santosh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2020 03:29 AM
Hi neha,
I found some mistakes in your code, I just highlighted that mistake by making those mistakes as Bold. Let me know after correction, are you able to achieve your desire output. If not I can share you some other script as well.
Type: OnChange()
Catalog Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var cdt = g_form.getValue('u_date_concern_reported'); //first date field
var addtime = 28;
var addtype = 'day';
var gr = new GlideAjax('global.ClientDateTimeUtils');
gr.addParam('sysparm_name', 'addDateAmount');
gr.addParam('sysparm_fdt', cdt);
gr.addParam('sysparm_addtime', addtime);
gr.addParam('sysparm_addtype', addtype);
gr.getXML(ajaxResponse);
function ajaxResponse(serverResponse){
var answer = serverResponse.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_th_day', answer); //second date field
alert(answer);
}
}
Script Include: ClientDateTimeUtils
Application: Global
Client callable:Checked
Accessible from: All application scopes
var ClientDateTimeUtils = Class.create();
ClientDateTimeUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
addDateAmount: function(){
var firstDT = this.getParameter('sysparm_fdt'); //First Date Field
var addTYPE = this.getParameter('sysparm_addtype');
var addTIME = this.getParameter('sysparm_addtime'); //How much time to add
var day = new GlideDate();
day.setDisplayValue(firstDT);
day.addDays(addTIME);
return day.getDisplayValue();
},
type: 'ClientDateTimeUtils'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2020 04:11 AM
Hi Sufiyan,
Thanks a lot. Script works now. But I am getting date in a different format in the second field.
28th Day: 2020-03-30