Script to determine if user has Dark Mode selected

Patrick Logan
Tera Contributor

Hi -- we have a script that will change the color of fields we recommend a user populate but we don't want to make mandatory. It's worked great until more users have started utilizing Dark Mode. Now the text is white and is hard to read on the highlighted color (#fff8b8). 

I want to change the field highlight color we use *if* the user is utilizing dark mode. I'm hoping theres a way to determine if dark mode is enabled in a client script but I haven't found anything about it online. 

My pseudo code is something like this
if (darkmode == "true") {

     highlightColor = "#b3a100";

} else {
     highlightColor = "#fff8b8";
}

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@Patrick Logan 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, you 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);

Since you would like to check this inside a client script, you can simply create a client callable script include and put this script inside it. Call this script include method from the client script and you will get to know if the logged in user is using Dark or Light mode. 

 

Hope this helps.

View solution in original post

1 REPLY 1

Sandeep Rajput
Tera Patron
Tera Patron

@Patrick Logan 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, you 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);

Since you would like to check this inside a client script, you can simply create a client callable script include and put this script inside it. Call this script include method from the client script and you will get to know if the logged in user is using Dark or Light mode. 

 

Hope this helps.