- 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 01:13 PM
Awesome. Thanks for participating in the community!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2017 12:57 PM
If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.
If you are viewing this from the community inbox you will not see the correct answer button. If so, please review How to Mark Answers Correct From Inbox View
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2017 04:12 PM
Hi Pradeep/Sue,
I have been having the same issue where I am trying to get the date modified in the script include and calling it using GlideAjax from Client. Both are in scoped application. I have been looking around the community for answers and this is the most closest to the problem I have found.
Below is the snap shot of the client script and Script Include both:
Client Script:
var ajaxUtil = new GlideAjax('VulnerabilityDateUtil');
ajaxUtil.addParam('sysparm_name','nowDateAdjustedByMonths');
ajaxUtil.addParam('sysparm_months','6');
ajaxUtil.getXML(doSomething);
function _doSomething(response){
alert(response);
var answer = response.responseXML.documentElement.getAttribute("result");
alert(answer);
}
Script Include:
var VulnerabilityDateUtil = Class.create();
VulnerabilityDateUtil.prototype = Object.extendsObject(global.AbstractAjaxProcessor,{
nowDateAdjustedByMonths: function() {
var adjustment_months = this.getParameter('sysparm_months');
gs.print("months==>"+adjustment_months);
var result = new GlideDate();
result.addMonths(adjustment_months);
gs.print("result ==> "+result);
return result;
},
_privateFunction: function() { // this function is not client callable
}
});
I get an alert with an XML HttpRequest and null.
when I debug the script include, I could see that the control could not get into the function defined. There must be something I am missing but I am unable to figure out as I've been looking at it for quite some time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2017 05:55 AM
Shilpa,
I don't see anything obvious. Hopefully Pradeep will respond as well.
Have you tried commenting out the line in the script include?
_privateFunction: function() { // this function is not client callable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2017 09:51 AM
Thanks for responding Sue.
I did try that and also tried adding
type:VulnerabilityDateUtil ;
It must be something very obvious I must be missing but I've been looking at it for quite some time and I might be just scrolling through without noticing the mistake.
Will keep trying though and check if pradeepksharma has any inputs on this.