GlideAjax Request to ClientDateTimeUtils Returns Results for Admins, Returns Null for Non-Admins

J_ T_
Tera Contributor

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.

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

in your script include add this function

   isPublic:function(){return true;},

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

6 REPLIES 6

@Jeremy T. 

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

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.