Sometimes we need to flag an account to make it obvious to the user that some action needs to take place. This recipe will show you two ways to do that. First off, we will put a different border color around the form. Secondly, we will add a colored title to the form, including a message to the user.
For the purpose of this exercise, we can reuse an existing solution. If none exists, create one. Make sure that you have at least the system customizer permission.
Open the solution and perform the following tasks:
new_opencases
with a label of Open Cases
. Place the field on the form.new_JSAccount
.function ChangeBorderColor() { var _cases; try { _cases = parseInt(Xrm.Page.getAttribute("new_opencases").getValue()); } catch(err) { _cases = 9999; } if(_cases < 10) { // set border green $(".ms-crm-Form-Page-Main-cell").css("background-color","#00FF00"); } elseif(_cases < 20 && _cases >= 10) { // set border yellow $(".ms-crm-Form-Page-Main-cell").css("background-color","#FFFF00"); } else { // set border red $(".ms-crm-Form-Page-Main-cell").css("background-color","#FF0000"); } }
OnLoad
and the new_opencases
field's OnChange
events.In Chapter 9, Extending CRM Using Community JavaScript Libraries, we will demonstrate how to populate the Open Cases field automatically, taking advantage of external libraries.
Based on the value stored in our Open Cases field, we determine specific thresholds on number of open cases per account. This way we flag an account status to the user by providing a different color to the form border. In this example we are taking advantage of the jQuery library to select the form border, and to set the background-colour
CSS property.
The following chapter will delve deeper into using the jQuery library for various form element selections, as well as other nifty tricks.
18.117.192.247