g_form.getReference returns undefined in Client script if user has no ITIL permissions:

tkrishna29
Giga Guru

Hi,

below code works perfect and returns manager sysid if run for users with ITIL license. However, it's returning undefined for normal end users. Any ideas? Thanks.

I'm trying to run this on client script if user selects a requestor, his manager name should write to console for now.

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
     return;
   }
  var usr = g_form.getReference('requestor',callBack);
  function callBack(usr){
     console.log ("hello2:" + usr.manager);
     g_form.setValue('requestor_manager',usr.manager);
   } 
}

 

1 ACCEPTED SOLUTION

tkrishna29
Giga Guru

@Allen : It worked on the portal for end users who have ITIL license and not for other users. They will always access this form through portal to request a service.

Hi,

I tried all the suggested combinations and it still didnt work. To make this work, I'm utilizing one of our existing script includes and called it using glideAjax. Surprisingly, this worked without tweaking any ACLs for the user record.

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
     return;
   }
//  var usr = g_form.getReference('requestor',callBack);
  var ga = new GlideAjax('getUserManager');
  ga.addParam("sysparm_name", "getonBehalfOfManager"); 
  ga.addParam("sysparm_user", g_form.getValue('requestor'));
  ga.getXML(getResponse);
function getResponse(response) {
  var values = response.responseXML.documentElement.getAttribute('answer').toString().split('||');
  g_form.setValue('requestor_manager', values[1]);
} 
} 
/*function callBack(usr){
	   console.log ("hello: " + usr.manager);
	   g_form.setValue('requestor_manager',usr.manager.toString());
   }     */

 

Here is my code on the script include:

var getUserManager = Class.create();
getUserManager.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	getonBehalfOfManager : function(){
		
		var group = this.getParameter('sysparm_user');
		var rel = new GlideRecord("sys_user");
		rel.addQuery("sys_id", group);
		rel.query();
		
		var name_arr = [];
		var sys_id_arr = [];
		
		if(rel.next())
			{
			name_arr.push(rel.manager.name.toString());
			
			sys_id_arr.push(rel.manager.toString());
		}
		return name_arr.toString() + '||' + sys_id_arr.toString();
	},
	type: 'getUserManager'
});

 

Regards,

Krishna

View solution in original post

11 REPLIES 11

Sanket Khabiya
Kilo Sage

Try below : 

 

 function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
     return;
   }
  var usr = g_form.getReference('requestor',callBack);
 }
 function callBack(usr){
     console.log ("hello2:" + usr.manager);
     g_form.setValue('requestor_manager',usr.manager);
   }

Regards,

Sanket

tkrishna29
Giga Guru

Hello Sanket,

I'm sorry, I failed to notice any changes to the code you posted vs mine.

 

Regards,

krishna

Hi,

He closed out the initial function...and opened the callback outside of it...

It'd be recommended to copy and paste the code, since you have your old code here.

Please mark reply as Helpful, if it was. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

tkrishna29
Giga Guru

Thank you @Allen.

Hello Sanket,

Still no luck! It works fine (your code / my code) if user has ITIL access. Doesn't work for normal end users with no roles.

 

Regards,

krishna