Flagging a section for the user

In this recipe, we will take a look at how to bring a section of the form to the attention of the user. We can do this for various reasons, whether we want to let the user know that a section is more important than the others, or simply to decorate our form.

Getting ready

We can either use one of the previously created solutions, or create a new solution. We will need to be either a system administrator or a system customizer.

How to do it...

Perform the following steps to highlight a section to the user by changing the background color of that section. We will be using the Account entity for this customization, and we will create a new section. We could do the same on an existing section.

  1. Open the solution, or create a new one.
  2. Add the Account entity to the solution if not already added.
  3. Open the main Account form for editing.
  4. Add a new section to the form. Configure it as per the following screenshot:
    How to do it...
  5. Add some fields to this section.
  6. Save and Publish this form.
  7. Add to your solution a new web resource named new_JSAccount. Make it of type Script (JScript).
  8. Add the following function to your web resource:
    function HighlightSection()
    {
      document.getElementById("{be295314-4459-5e75-68de-81921170754b}").style.backgroundColor = '#CD0000';
    }
  9. Save and Publish the web resource.
  10. On the main form of the account, attach the function to the OnLoad event of the form.
  11. Save and Publish your solution.
  12. Test it by opening a new account. You should see the section highlighted with a background colored in red as shown in the following screenshot:
    How to do it...

How it works...

While this is an unsupported customization, it's been available since previous versions of Dynamics CRM, and it's still an easy and comfortable way of handling user-interface changes.

The line of code in our function gets a reference to the section, and applies a background-color style formatting. We can easily get the internal ID of the section by using the Internet Explorer Developer Tools console. We have focused on using the Developer Tools in our debugging section in Chapter 6, Debugging.

There's more...

There are some additional ways to interact with the user interface. Some of them involve the use of other external libraries, such as jQuery. We will be looking at how to use jQuery in Chapter 9, Extending CRM Using Community JavaScript Libraries.

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

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