Trying to call script include from reference qualifier but not getting the correct groups in the catalog item

Afsar Hussain
Kilo Guru

Hi,

I have requirement that there is one catalog item with two variables User and Group. User is of single line text variable and group is reference type variable.

When I click on group search icon, it should display list of only those groups of which currently logged in user is a part but I am getting all groups in the list.

I have created script include for this and calling this script include in the reference qualifier field of group variable of the Catalog item.  

I have attached the required screenshots.

Pls help me to find what is wrong with my code.

Below is the script include I have written-

var GetUserGroups = Class.create();
GetUserGroups.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getGroups:function(){
var arr=[];
var grp=new GlideRecord('sys_user_group');
grp.addQuery('active',true);
grp.query();
while(grp.next())
{
if(gs.getUser().isMemberOf(grp.name)== true)
{

arr.push(grp.name);
}

}

return arr;

},

type: 'GetUserGroups'
});

 

Regards,

Afsar

1 ACCEPTED SOLUTION

Hi @Afsar 

 

Finally, this will solve your issue:


Update Script Include:

var GetGroupMembers = Class.create();
GetGroupMembers.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getMembers: function(userId) {
		var groups = [];
		var getMyGroup = new GlideRecord('sys_user_grmember');
		getMyGroup.addEncodedQuery('user.user_name=' + userId + '');
		getMyGroup.query();
		while(getMyGroup.next()) {
			groups.push(getMyGroup.getValue('group'));
		}
		
		//Added log to see what data is generated
		//gs.log('[DEBUG] Groups for User ID: ' + userId + '\n' + groups);
		if(JSUtil.notNil(groups)) {
			return groups.join(',');
		} else
			return '-1';
	},
	
    type: 'GetGroupMembers'
});

Reference Qualifier:

javascript: 'sys_idIN' + new GetGroupMembers().getMembers(current.variables.<backend_name_of_user_variable>);

 

Check the screenshot as well:

find_real_file.png

 


Please mark my answer as correct if this solves your issues!

If it helped you in any way then please mark helpful!

 

Thanks and regards,

Kartik

View solution in original post

17 REPLIES 17

Kartik,

still it is not working.

Hi @Afsar 

 

Did you make changes to the Reference Qualifier as well?

Also please add the log message as provided below:

var GetGroupMembers = Class.create();
GetGroupMembers.prototype = {
	
	getMembers: function(userId) {
		var groups = [];
		var getMyGroup = new GlideRecord('sys_user_grmember');
		getMyGroup.addEncodedQuery('user.user_name=' + userId);
		getMyGroup.query();
		while(getMyGroup.next()) {
			groups.push(getMyGroup.getValue('sys_id'));
		}
		
		//Added log to see what data is generated
		gs.log('[DEBUG] Groups for User ID: ' + userId + '\n' + groups);
		if(groups) {
			return groups.join(',');
		} else
			return '-1';
	},

    type: 'GetGroupMembers'
};

Please let me know what results you are getting.

Thanks and regards,

Kartik Sethi

NO Logs generated.

And added the reference qualifier field as following:

javascript: new GetGroupMembers().getMember(current.u_user)

 

See the screenshot as well for the updated script include and reference qualifier.find_real_file.png

Hi @Afsar 

 

Finally, this will solve your issue:


Update Script Include:

var GetGroupMembers = Class.create();
GetGroupMembers.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getMembers: function(userId) {
		var groups = [];
		var getMyGroup = new GlideRecord('sys_user_grmember');
		getMyGroup.addEncodedQuery('user.user_name=' + userId + '');
		getMyGroup.query();
		while(getMyGroup.next()) {
			groups.push(getMyGroup.getValue('group'));
		}
		
		//Added log to see what data is generated
		//gs.log('[DEBUG] Groups for User ID: ' + userId + '\n' + groups);
		if(JSUtil.notNil(groups)) {
			return groups.join(',');
		} else
			return '-1';
	},
	
    type: 'GetGroupMembers'
});

Reference Qualifier:

javascript: 'sys_idIN' + new GetGroupMembers().getMembers(current.variables.<backend_name_of_user_variable>);

 

Check the screenshot as well:

find_real_file.png

 


Please mark my answer as correct if this solves your issues!

If it helped you in any way then please mark helpful!

 

Thanks and regards,

Kartik

Thanks a lot Kartik....

It is working now..