How to query UI Version for current logged in user in a conditional script

rob125
Tera Contributor

Hello Everyone,

 

   I'm looking at how to query the value for glide.ui.polaris.use on the User Preferences table  based on the current logged in user. 

 

   I have a custom banner that works great in UI16, however I need the banner NOT to run if the user is logged in with Polaris.  where glide.ui.polaris.use under the User Preferences is set to true.

 

    So basically if, glide.ui.polairs.use is false, run the corresponding banner script, and if the value is true, to just terminate the script.

 

     I've tried numerous routes, but nothing has worked so far.  So have a second, third or fourth set of eyes would be greatly appreciated.

 

Thanks all

 

Robert

1 REPLY 1

Chaitanya Redd1
Tera Guru

Hi,

It looks like you're trying to conditionally run a script based on the value of the glide.ui.polaris.use field in the User Preferences table. You want the script to run a custom banner unless the value of glide.ui.polaris.use is set to true. Here's a general approach you can take using GlideRecord and JavaScript in a server script or a business rule:

 

// Check the current user's preferences for glide.ui.polaris.use
var userId = gs.getUser().getID(); // Get the current user's ID
var userPrefGR = new GlideRecord('sys_user_preferences');
userPrefGR.addQuery('user', userId);
userPrefGR.query();

if (userPrefGR.next()) {
    var polarisUse = userPrefGR.getValue('glide.ui.polaris.use');
    
    if (polarisUse !== 'true') {
        // Run your banner script here
        gs.addInfoMessage('Custom banner is displayed.');
    } else {
        // Polaris is being used, terminate the script
        gs.addInfoMessage('Polaris is being used. Banner script terminated.');
    }
} else {
    gs.addErrorMessage('User preferences not found.');
}