- 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-25-2020 04:39 AM
You can set formate by getByFormat("MM/dd/yyyy"). Just update following code at the end of you script include
var day = new GlideDate();
day.setDisplayValue('03-03-2020');
day.addDays(28);
retrun day.getByFormat("MM/dd/yyyy"))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2021 03:06 PM
Thank you so much for idiot proofing this for me/the community.
Worked perfectly the first time.
Who's awesome? You're awesome!
- Brett
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2024 11:36 AM - edited ‎05-30-2024 11:57 AM
Thank you for providing this. This helped a great deal!
I used this script for my purpose. I get the alert with the correct date, however the field I'm setting is not populating with the answer (or anything).
function ajaxResponse(serverResponse){
var answer = serverResponse.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_sun_date', answer); //second date field
alert(answer);
Here is the format of the field to be populated
Any thoughts as to why?
Thank you in advance
Scott
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2024 12:27 PM
You can disregard. My error was there were 2 variables of the same name.
Once I corrected the names - this worked like a charm!!!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2020 04:49 AM
Hi neha ,
try this script :
you can achieve this with the help of catalog client script and script include :
Client script :
var date= g_form.getVlaue('u_date_concern_reported');
var ga = new GlideAjax('getdate');
ga.addParm("sysparm_name","getDetails");
ga.getXML(newdate);
function newdate(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
g_form.setValue('u_th_day',answer);
}
var ed = gr.addDays(28);
return ed;