- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 07:15 AM - edited 10-31-2023 07:16 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 07:22 AM
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;
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 07:22 AM
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;
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 07:38 AM
you Ankur! That was it.