Dynamics CRM 2011 – Form CSS with JavaScript

This is very much unsupported and can be completely useless if Microsoft decide to change ID/Class names in CRM. There are a lot better ways to do this (http://mscrmshop.blogspot.co.uk/2012/07/how-to-change-form-header-colour-based.html) but this is just a quick and dirty way to change content colours with JS. Example below is changing the case form header background color based on a dropdown option, all in JavaScript.



  • Open / Create javascript web resource
  • Attach the following code to the web resource (Below)
  • Add the function to the priority on-change and to form onload (Call the function in an existing onload)
  • save and publish
function onchange_priorityCSS()<br />
<p>//get the text value picklist field<br />
var relType = Xrm.Page.getAttribute("prioritycode").getText();<br />
switch (relType) {<br />
case "1 - Business Criticial":<br />
//The ID is taken from Internet Explorers developer tools<br />
document.getElementById("crmFormHeaderTop").style.backgroundColor = "red";<br />
break;<br />

Example of OnLoad:

function onload(){</p>
<p>statusReason();<br />
trackSLA();<br />
onchange_priorityCSS();<br />
}<br />

Once you’ve done this, if the case priority is 1, the header will change to a ghastly red and be red when it’s re-opened.

I do things in the clloouuudddd