Colours per company in Dynamics 365 For Operations

¿Cómo conseguirlo?

In this new version, color combinations shown to the user are grouped under what D365FO calls “Themes”. This means that we cannot choose a concrete colour (by its RGB component, for example), but a colour combination among those predefined, supplied by the system. Standard application allows user to choose one of these Themes, which are applied to any form in any company the user is working on (Options > User options):

A common request from customers is being able to automatically change these colours depending on the company the user is working in. This feature results specially useful when users have to work in several environments (test, production, etc.) and/or several companies. This way, user visually “gets in place” immediately, reducing the risk of commiting errors because of those different environments/companies.

Good news is, it is easy to implement. We’ll need three things:

  1. Permanent storage from which we’ll get the Theme to be applied to each company. In D365FO, we can easily extend any existing setup-per-company table (CompanyInfo is the first and best candidate) to create a new dedicated field. Or we can use a new/custom table. Anyway, we’ll need to provide user interface for this field, to allow an administrator user to change it.In this case, we have created a new custom setup table which, apart from applied Theme, contains a new NoYes field (UseCompanyTheme) which will allow us to activate/deactivate company theme it without blanking it:

    Along with the user interace necessary, which we have placed at Legal Entities form (OMLegalEntity):

    Theme applied must be one of the values from SysUserInfoTheme Base Enum. Depending on our needs, storage for this value can be more or less complicated (e.g., as part of a container field), but creating a dedicated field this is the easiest way to store (and use) it:

  2. Effective code which will change current theme. For doing so, we use Chain of Command on method GetThemeDensityForCurrentUser() from class SysFormUtil. In this case, we have decided to centralize almost all functionality in public, static methods in our (new) parameters table. Also, we prioritize Company Theme on user-selected theme: if no company theme is applied, user theme will be the one which will be applied, to follow standard behaviour as far as possible. The line which “does the magic” is the one which calls appl.setTheme():

  3. Entry points, which will call logic implemented above (in our case, a static method at parameters table). We’ll need two:
    1. Implement a delegate subscriptor method for onSetDefaultCompany at class Application:

    2. Implement a subscriptor method for post-modified event from DataArea_id control from system form SysCompanyChooser:

We could say this entry point is the “fireworks” (in the sense of “immediately visible for the user”) for this functinality. This system form is the one used for changing current company in any user interface form. Visual effect for this change is that, immediately after changing working company, browser screen will be refreshed accorgint to chosen Theme for new company.



Functionality “at work”

As commented above, this time we have chosen to centralize funcitonality (entry points + effective logic) at new parameters table, and prioritize company Theme over user-selected theme:

But as far as described above directions are followed, it should also work.
Enjoy 😉 !

J.M. Guisado

Recommended Posts