Advanced reference qualifier to hide a value of a reference variable based on user's department

xhensilahad
Tera Expert

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:

var getUserDetails = Class.create();
getUserDetails.prototype = {
    initialize: function() {},
    // Method to get department filter based on user ID
    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';
            }
        }
    }
};
 
 
 
How do i call this Script include in my Advanced Reference qualifier script? Thank you
3 ACCEPTED SOLUTIONS

Simon Christens
Kilo Sage

try:

 

 

javascript: new getUserDetails().getFilter(gs.getUserID())

 

 

View solution in original post

Siddhesh2
Giga Guru

Hello @xhensilahad ,

 

You should uncheck the client callable option and use below code to call script include.

Siddhesh2_0-1732276505499.png

 

 

 

View solution in original post

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.

View solution in original post

13 REPLIES 13

Simon Christens
Kilo Sage

try:

 

 

javascript: new getUserDetails().getFilter(gs.getUserID())

 

 

Hi Simon, thank you for your response. 

I can still see the value.  Is there maybe any error in my script include?

Thank you

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'
};

 

 

Hi Simons, I have updated the On Load script, but i can still see the variable. Please see the screenshots attached:

xhensilahad_0-1732262933492.png

xhensilahad_1-1732262960107.pngxhensilahad_2-1732262977994.png

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