Sandeep Rajput
Tera Patron
Tera Patron

Recently, I came across an interesting question, where the questioner asked if it is possible to check whether logged in user is using Dark mode in their preference. Accordingly, questioner wanted to set some styles in the client script. 

 

Here is the suggested solution.

 

Solution: In the Polaris UI, if the dark theme is selected by the User, it usually gets record in the User Preference.

 

The name against which this entry gets record is glide.ui.polaris.theme.variant.

 

This is how it looks when the default white theme is selected.

Screenshot 2024-01-17 at 5.26.42 PM.png

This is how the preference entry looks when the dark theme is selected.

Screenshot 2024-01-17 at 5.27.11 PM.png

Here sys_id in value is the sys_id of dark theme e09ef7ae07103010e03948f78ad3002c (this is consistent for Dark theme across all the instances.)

 

To check how many users are using Dark theme, we can simply use the following query.

 

 

 

 

var glidePreference = new GlideRecord('sys_user_preference');
glidePreference.addEncodedQuery('name=glide.ui.polaris.theme.variant^value=e09ef7ae07103010e03948f78ad3002c^userDYNAMIC90d1921e5f510100a9ad2572f2b477fe'); //Fetch prefernce for the logged in user.
glidePreference.query();
var darkTheme=false;
if(glidePreference.next()){
    darkTheme=true;
}
else{
    darkTheme=false;
}

gs.info(darkTheme);

 

 

 

 

This script can be put inside a method in a client callable script  and can be called inside a client script to check if the logged in user is using darkTheme or not.

 

Hope this helps.

Version history
Last update:
‎01-17-2024 06:29 AM
Updated by:
Contributors