Hide a reference variable option based on Users department

xhensilahad
Tera Expert

Good afternoon,

I have a requirement to hide an option (in a reference variable), if the users department starts with BT.

I have created this script Include and On Load script, but I am not sure how to progress with hiding the value now.

The variable's name is 'u_application', it is referencing to 'u_emergency_incident' table, and the option I want to hide is named  'IT'.

 

Script Include

var getUserDetails = Class.create();
getUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getDetails: function() {
        var user_sysid = this.getParameter('sysparm_caller');
        var user = new GlideRecord('sys_user');
        user.addQuery('sys_id', user_sysid);
        user.query();
        if (user.next()) {
            var userDepartment = user.department.getDisplayValue();
            return userDepartment;
        }
    },
    type: 'getUserDetails'
});
 
On Load Client Script:
function onLoad() {
    //Type appropriate comment here, and begin script below
    var userID = g_user.userID;
    var user = new GlideAjax("getUserDetails");
    user.addParam('sysparm_name', 'getDetails');
    user.addParam('sysparm_caller', userID);
    user.getXML(getResources);

    function getResources(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        if (answer.substring(0, 2) === "BT") {
         alert("The string starts with 'BT'");
}      
    }
}
 
 
 
Thank you
7 REPLIES 7

Zach Koch
Giga Sage
Giga Sage

Replace the line
alert("The string starts with 'BT'");

with

g_form.removeOption('yourField', 'choiceValue')

here is the screenshot of the docs for this method

ZachKoch_0-1732208385855.png

 

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

Hi Zach, thank you for your response, unfortunately the removeOption is no longer supported, as per this KB : removeOption does not worth through client script access to variable fields on task records - Known ...

Gaspy
Tera Contributor

You're on the right track but I might suggest tackling it a different way. You can still use your Script Include but i'd then add it as an Advanced Reference Qualifier on the field you're looking to filter

Hi, would you please share an example of the Advanced Reference Qualifier? Thank you