- 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-22-2024 12:12 AM
I have updated the *Script Include*
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 12:33 AM
You can add gs.addInfoMessage() in your script include so that you can see that it gets called.
Then you can make some messages in your script to see where it goes wrong.
When you then click on the search icon on the field then you should see those messages
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 02:36 AM
Your Reference qualifier should look like this:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 02:43 AM
Hi Brad, thank you for your response.
Can you please review my Script Include as I can still see the variable in the Portal:
Script Include: (Client callable has been checked)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 04:11 AM
In this case Client callable is not required, but it doesn't hurt anything to have it checked. Checking this box after a script exists does not add the extended object to the script, but even if it did it would still work with a qualifier. You can temporarily add some lines like this to confirm the script is running, the value passed in from the qualifier, and the substring, then you should see where it is going wrong:
var getUserDetails = Class.create();
getUserDetails.prototype = {
initialize: function() {},
getFilter: function(userID) {
gs.addInfoMessage('SI running ' + userID);
var userGR = new GlideRecord('sys_user');
if (userGR.get(userID)) {
var department = userGR.department.name.toString();
gs.addInfoMessage('SI dept ' + department);
gs.addInfoMessage('si dept substring ' + department.substring(0, 2));
if (department && department.substring(0, 2) === 'BT') {
return 'active=true';
} else {
return 'active=true^name!=IT Infrastuktur';
}
}
}
};