- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2022 06:08 AM
We are attempting to provide validation around a Service Catalog Item request form for two date fields and have implemented two Catalog Client Scripts to perform these tasks.
Here is the first of the scripts
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var cdt = g_form.getValue('event_start_date_time'); //Start Date/Time field
var dttype = 'day'; //this can be day, hour, minute, second. By default it will return seconds.
//Make ajax call to the script include clientdatetimeutils
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name','getNowDateTimeDiff');
ajax.addParam('sysparm_fdt', cdt);
ajax.addParam('sysparm_difftype', dttype);
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
console.log(answer); // Null for non-admin users
if(parseInt(answer) < 3) {
alert('Online requests may not be submitted via this form with less than three (3) business days prior to the requested event date.');
g_form.setValue('event_start_date_time','');
}
}
}
The answer from XML requuest to ClientDateTimeUtils is returned when we are testing the Catalog item request as an admin/itil user but when we test it as any other logged in user the answer variable is always null.
We have tried isolating the script and have tried creating the client script in both the global and app specific scopes
We have also tried creating a client_callable_script_include ACL and attaching it to the role that the end user would have with no success.
Thanks for your assistance.
Solved! Go to Solution.
- Labels:
-
Scoped App Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2022 06:42 AM
Hi,
in your script include add this function
isPublic:function(){return true;},
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2022 08:20 AM
Glad to work.
it allows the script include to be accessible as public user
Please mark my response as correct and close the thread.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2022 10:19 AM
Well, that was confusing! It looks like you accidentally tagged me in the reply here, but I'm not the OP. We're both "Jeremy T." I guess.