We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Trying to use script include in dictionary override

Ken Berger
Giga Guru

Hi folks,

 

I am trying to limit the assignment groups that are seen by certain users, based on what business unit they are in.  I wrote the following script include:

 

var HideAssignmentGroupsBasedOnUserBusinessUnit = Class.create();
HideAssignmentGroupsBasedOnUserBusinessUnit.prototype = {
    initialize: function HideAssignmentGroupsBasedOnUserBusinessUnit() {
		var r = '';
		var strQuery = 'u_business_unitSTARTSWITHW^ORu_business_unitSTARTSWITHK';
		var gr = new GlideRecord('sys_user');
		gr.addEncodedQuery(strQuery);
		gr.query();
		if(gr.next()) {
			r = 'name!=IT Infrastructure^name!=IT Operations'; 
		} 
		return r; 
    },

    type: 'HideAssignmentGroupsBasedOnUserBusinessUnit'
};

 

 

I am calling it in the assignment group dictionary override reference qualifier as follows:

 

javascript:HideAssignmentGroupsBasedOnUserBusinessUnit();

 

 

But when I impersonate a user that meets the criteria to hide the assignment groups it is not working, and I still see the groups that should be hidden.  Can anyone help?  I have not worked with script includes before and I am not sure if it is an issue with my code or the way I am calling the script.

 

Thanks,

Ken

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@Ken Berger 

you are not querying for logged in user

try this and make script include classless

function HideAssignmentGroupsBasedOnUserBusinessUnit(){
	var r = '';
	var strQuery = 'u_business_unitSTARTSWITHW^ORu_business_unitSTARTSWITHK';
	var gr = new GlideRecord('sys_user');
	gr.addQuery('sys_id', gs.getUserID());
	gr.addEncodedQuery(strQuery);
	gr.query();
	if(gr.hasNext()) {
		r = 'name!=IT Infrastructure^name!=IT Operations'; 
	} 
	return r; 
}

AnkurBawiskar_0-1698762126663.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron

@Ken Berger 

you are not querying for logged in user

try this and make script include classless

function HideAssignmentGroupsBasedOnUserBusinessUnit(){
	var r = '';
	var strQuery = 'u_business_unitSTARTSWITHW^ORu_business_unitSTARTSWITHK';
	var gr = new GlideRecord('sys_user');
	gr.addQuery('sys_id', gs.getUserID());
	gr.addEncodedQuery(strQuery);
	gr.query();
	if(gr.hasNext()) {
		r = 'name!=IT Infrastructure^name!=IT Operations'; 
	} 
	return r; 
}

AnkurBawiskar_0-1698762126663.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Ken Berger
Giga Guru

 you Ankur!  That was it.