Marking accounts for review

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.

Getting ready

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.

How to do it...

Open the solution and perform the following tasks:

  1. Add the Account entity to your solution if not already added.
  2. If asked to add related entities, click on Yes.
  3. Open the main Account form for editing.
  4. Add a new text field named new_opencases with a label of Open Cases. Place the field on the form.
  5. Save and Publish the form.
  6. Add the jQuery resource as described in previous recipes.
  7. Add a new web resource of type JScript. Name it new_JSAccount.
  8. Add the following script to your resource:
    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");
      }
    }
  9. Associate the script to the form's OnLoad and the new_opencases field's OnChange events.
  10. Save and Publish the solution.
  11. Test your customization by loading an account. Modify the value of open cases in the field.

    Note

    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.

    How to do it...

How it works...

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.

See also

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.192.247