Accessing user attributes from Catalog Client Script??

jMarshal
Mega Sage
Mega Sage

Hello! 

I'm working in the post-sec education sector and we have a series of user attributes that qualify user type classifications (boolean values of "student true/false", "faculty true/false", "alumni true/false", "employee true/false") and I'm trying to use that information to hide options from a select list on a catalog item using a catalog client script.

...but I'm having trouble getting access to the user table attributes in the script.

I found a forum posting that was suggesting to use gs.getUser().getRecord().getValue('u_is_student');...but I can't use gs in this scope, apparently.

Basically, I am defining the variable of "user" and then trying to say IF "user.u_is_student == true" THEN g_form.removeOption('field_name', field_value);

...any help would be appreciated!!!

1 ACCEPTED SOLUTION

Mike Patel
Tera Sage

You can also have onChange client script on user variables

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}
	var user = g_form.getReference('user', populateReqForDetails);
	function populateReqForDetails(user) {
		var student = user.u_is_student;
		if(student){
			g_form.removeOption('field_name', field_value);
		}
	}	
}

View solution in original post

4 REPLIES 4

Mike Patel
Tera Sage

Below will help. g_user user object

https://www.servicenowguru.com/scripting/user-object-cheat-sheet/

Matthew Glenn
Kilo Sage

gs (GlideSystem) is a server-side API, so you won't be able to access it directly within a Catalog Client Script. 

I'd go with an GlideAJAX call. This should help out if you're unfamiliar. 

Mike Patel
Tera Sage

You can also have onChange client script on user variables

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}
	var user = g_form.getReference('user', populateReqForDetails);
	function populateReqForDetails(user) {
		var student = user.u_is_student;
		if(student){
			g_form.removeOption('field_name', field_value);
		}
	}	
}

I think this is perfect, thanks!