- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2017 11:39 AM
I've been working with this discussion which was very helpful: Client Script Date/Time Functions .
Here is my dilemma.
I created "ClientDateTimeUtils" as a global script include - it has uses far beyond a single scoped application.
I have a scoped application from which I'd like to call the script include. The end result will be to reset the Expiry Date if the Effective Date changes.
The Expiry Date should be 90 days after the Effective Date.
I've been looking at it so long, I don't really see it anymore. I've been poking around the community but I can't get it to work. I'm only see the first
alert in the Client Script that returns "newValue". It appears that the Script Include isn't being called at all and I don't know why.
My client script, running on change of the Effective Date field:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var cdt = newValue; //Choose the field to add time from <-- was wrong, I have corrected this line as per my reply below
var addtime = 90; //The amount of time to add
var addtype = 'day'; //The time type. Can be day, week, month, year.
var ajax = new GlideAjax('global.ClientDateTimeUtils');
//var ajax = new GlideAjax('x_enig_quote_extrm.ClientDateTimeUtils');
ajax.addParam('sysparm_name', 'addDateAmount');
ajax.addParam('sysparm_fdt', cdt);
ajax.addParam('sysparm_addtime', addtime);
ajax.addParam('sysparm_addtype', addtype);
ajax.getXML(doSomething);
alert(newValue);
function doSomething(response){
alert('into doSomething');
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
}
My global, client callable Script Include:
var ClientDateTimeUtils = Class.create();
ClientDateTimeUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
... <snip> ...
//Takes a glide date field and adds time to it.
//params = sysparm_fdt (the first date/time field), sysparm_addtype (type of time to add - day, week, month, year),sysparm_addtime (amount of time to add based on the type).
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;
Solved! Go to Solution.
- Labels:
-
Scoped App Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2017 12:20 PM
Thanks for the update Sue. Replace script include with below updated code.
var ClientDateTimeUtils = Class.create();
ClientDateTimeUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
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;
},
_privateFunction: function() { // this function is not client callable
}
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2017 12:20 PM
Thanks for the update Sue. Replace script include with below updated code.
var ClientDateTimeUtils = Class.create();
ClientDateTimeUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
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;
},
_privateFunction: function() { // this function is not client callable
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2017 12:24 PM
I'll give that a try too, but first I did find an error in my client script.
var cdt = g_form.getValue(newValue); //Choose the field to add time from
should be
var cdt = newValue; //Choose the field to add time from
Now I'm actually passing in the correct parameter, but I'm still getting a null result to let me try your next suggestion.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2017 12:30 PM
EUREKA!!!
That worked.
It looks like the only difference is the addition of this line outside the 'addDateAmount' function:
_privateFunction: function() { // this function is not client callable
What does this line do?
If I add further functions into this script include should this line be at the very end of the script include or is it repeated with each function?
Thank you SO MUCH for your help.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2017 12:57 PM
Thanks for the update Sue. Function names starting with "_" are considered private and are not callable from the client.
Your code should work even though you remove those lines
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2017 01:08 PM
Perfect. I removed these lines and the code still runs.
_privateFunction: function() { // this function is not client callable
}
Thank you so very much.