- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2024 11:45 PM
Hi everyone,
I have a requirement to hide a value of a reference field, if the users department starts with BT.
I have written the Script Include below:
Script Include:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2024 11:50 PM - edited 11-21-2024 11:54 PM
try:
javascript: new getUserDetails().getFilter(gs.getUserID())
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 03:53 AM - edited 11-22-2024 03:55 AM
Hello @xhensilahad ,
You should uncheck the client callable option and use below code to call script include.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 07:09 AM
I wouldn't worry too much about other system logs - you can drive yourself mad reading through all of that and it's likely unrelated. You're getting the correct substring, so I guess we need to take this one step further to confirm what is being returned to the qualifier. And be sure to test both cases - so you should see this department name with this test case
var getUserDetails = Class.create();
getUserDetails.prototype = {
initialize: function() {},
getFilter: function(userID) {
var userGR = new GlideRecord('sys_user');
if (userGR.get(userID)) {
var department = userGR.department.name.toString();
if (department && department.substring(0, 2) === 'BT') {
gs.addInfoMessage('SI inside if');
return 'active=true';
} else {
gs.addInfoMessage('SI else');
return 'active=true^name!=IT Infrastuktur';
}
}
}
};
Then, if a non-BT... department user logs correctly in the else block, but still sees the department, hard-code the qualifier
active=true^name!=IT Infrastuktur
to see if this is correct. You can manually filter a list view by this criteria to view the correct records, then right-click to copy the query and paste that into the qualifier/script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2024 11:50 PM - edited 11-21-2024 11:54 PM
try:
javascript: new getUserDetails().getFilter(gs.getUserID())
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2024 11:55 PM
Hi Simon, thank you for your response.
I can still see the value. Is there maybe any error in my script include?
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2024 11:59 PM - edited 11-22-2024 12:00 AM
Your script include is wrong 🙂
Try this:
var getUserDetails = Class.create();
getUserDetails.prototype = {
initialize: function() {},
getFilter: function(userID) {
var userGR = new GlideRecord('sys_user');
if (userGR.get(userID)) {
var department = userGR.department.name;
if (department && department.substring(0, 2) !== 'BT') {
return 'active=true^name!=IT Infrastuktur';
}
}
},
type: 'getUserDetails'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 12:10 AM
Hi Simons, I have updated the On Load script, but i can still see the variable. Please see the screenshots attached:
My department starts with BT. I have updated the department and can still see it. I have impersonated another user with a department that does not start with BT, but can still see the value.
Thank you