Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Clinton Arendt
Tera Contributor

Our company had the need to retain our instance specific theme after cloning / upgrading. I developed a simple fix script to update anyone's custom theme back to 'system', set all themes to inactive and re-activate the instance specific themes.

// Our system property 'instance_name' ends with our instance short name, for example dev or uat.
var prefix = gs.getProperty('instance_name');
//Check to make sure that the script is being executed in non-production environments only
if (prefix.endsWith("dev") || prefix.endsWith("uat")) {

    // Update all users who have set custom themes back to the system theme
    var counter = 0;
    var gr = new GlideRecord('sys_user_preference');
    gr.addQuery('name', 'glide.css.theme.ui16');
    gr.addQuery('user', '!=', '');
    gr.addQuery('value', '!=', 'system');
    gr.query();
    while (gr.next()) {
        gr.value = "system";
        gr.setWorkflow(false);
        gr.update();
        gs.log(gr.user.name + " updated to system theme.");
        counter++;
    }
    gs.log("Total number of users whose themes have been set to system: " + counter);

    // Set all themes to inactive
    var counter2 = 0;
    var gr2 = new GlideRecord('sys_ui_theme');
    gr2.query();
    while (gr2.next()) {
        gr2.active = false;
        gr2.setWorkflow(false);
        gr2.update();
        gs.log(gr2.name + " theme deactivated");
        counter2++;
    }
    gs.log("Total number of themes set to inactive: " + counter2);

    // Set only the instance specific themes to active
    var counter3 = 0;
	
	var instance = "";

    if (prefix.endsWith("dev")) {
        instance = "dev";
    } else {
        instance = "uat";
    }
    gs.log("Instance name is " + instance);

    var gr3 = new GlideRecord('sys_ui_theme');
    gr3.addQuery('name', instance + " Clean")
        .addOrCondition('name', instance + " DarkNOW")
        .addOrCondition('name', instance + " Contrast UI");
    gr3.query();
    while (gr3.next()) {
        gr3.active = true;
        gr3.setWorkflow(false);
        gr3.update();
        gs.log(gr3.name + " activated");
        counter3++;
    }
    gs.log("Total number of " + instance + " themes activated: " + counter3);
}
Version history
Last update:
‎09-14-2021 08:29 PM
Updated by: