If you have added a custom Enable Rule to the Application Ribbon using a custom JavaScript already (Show Global Notification on Load of Model-driven App in Dynamics 365 [Linn’s Power Platform Notebook]), it’s easy to add a function to dynamically change the text at the top based on the URL host name. If a new update of D365 changes the underlying DOM that this affects, you will have to modify the JavaScript to match, so this is an unsupported change.
//call this from an Enable Rule
function dynamicallySetColor() {
//set the NAV bar color - https://www.rapidtables.com/web/color/RGB_Color.html
LZW = LZW || {};
var setColorByEnv = function setColorByEnv(br, bg, bb, fr, fg, fb) {
//Background RGB: br, bg, bb
//Font RGB: fr, fg, fb
//unsupported change
if (fr === null || fg === null || fb === null) {
//just set as white
fr = 255;
fg = 255;
fb = 255;
}
LZW.colorCustomized = true;
console.log("Setting color");
var style = window.parent.document.createElement('style');
style.innerHTML = `.pa-v {
background-color: rgb(` + br + ',' + bg + ',' + bb + `) !important;
}
.pa-k {
color: rgb(` + fr + ',' + fg + ',' + fb + `) !important;
}
`;
window.parent.document.head.appendChild(style);
}
var setTitleBar = function setTitleBar(newText) {
try { //unsupported change
var parentDiv = window.parent.document.getElementById("id-19");
if (parentDiv) {
var spans = parentDiv.getElementsByTagName("span");
if (spans && spans.length === 1) {
var theSpan = spans[0];
if (theSpan.innerHTML.indexOf('SANDBOX') !== -1) { //only replace this on SANDBOX
theSpan.innerHTML = newText;
}
}
}
[0].innerHTML = newText;
} catch (e) {
console.log(e);
}
}
try {
var thisDn = window.parent.location.host;
if (thisDn.indexOf("-dev") !== -1) {
setTitleBar("DEVELOPMENT ENVIRONMENT");
setColorByEnv(0, 100, 0, 0, 0, 0); //dark green with black font
} else if (thisDn.indexOf("-qa") !== -1) {
setTitleBar("QA ENVIRONMENT");
setColorByEnv(128, 0, 0, 255, 255, 255); //maroon/white
} else if (thisDn.indexOf("-int") !== -1) {
setTitleBar("TRAINING ENVIRONMENT");
setColorByEnv(210, 105, 30, 0, 0, 0); //Chocolate/black
} else if (thisDn.indexOf("-preprod") !== -1) {
setTitleBar("PREPRODUCTION ENVIRONMENT");
setColorByEnv(0, 128, 128, 0, 0, 0); //Teal/black
}
} catch (e) {
console.log(e);
}
}