The CreatorCon Call for Content is officially open! Get started here.

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

In that case, you would have to edit the read ACL's on sys_user table for your end users to see data

 


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Hi Krishna,

Any update on this?
Can you mark my answer as Correct, Helpful if you were able to achieve the requirement & then close the thread.

Thanks in advance.

Sanket

We're unsure where the no role users are accessing this...do you mean they use the portal and it's not working there, but is working for the back-end users? If so, as Sanket mentions below, please set the UI type to "All" instead of "Desktop" within this client script settings.

Also, please mark my reply above as Helpful (and this one), if it was, as explaining things helps everyone.

Thanks!


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

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,

 

Not sure but please try doing this usr.manager.toString()

 

and also check ACLs on user table and specially on manager field if there is any specific field ACL.


Thanks,
Ashutosh

Sanket Khabiya
Kilo Sage

Hi Krishna,

In your client Script please make sure the filed "UI Type" is marked as "ALL".

 

Regards,

Sanket