If you use 2 languages in your CRM instance you may face a requirement to display main attributes in lookup fields using the language of a current user. Standard functionality does not provide us with such a feature and we need to create a custom plugin.

The main idea is to add extra fields to the necessary object and the number of these fields should be equal to the number of languages. And filling them in we should concatenate all of them into a standard main attribute. When running ‘Retrieve’ or ‘Retrieve-Multiple’ methods we need to parse it and to keep the value in necessary language.

Let’s see an example on Products.

First let’s get prepared:

  • Add the attribute “new_name_en” “new_name_ru” to the Product object (you should have both English and Russian languages).
  • When a product is created or updated, each language is being concatenated into the field Name. Each time requesting Name we will parse it, identify the name in necessary language and to rewrite it into Name field. So you need to extend Name length to 4000 symbols.

We are ready to go now.

Create the plugin using the following code.

Here we have several functions – 5 useful and 2 auxiliary ones. Useful functions are registered to different system events and to different objects, they also do parsing. Auxiliary functions detect the language of a current user and get the value from Entity.

Register the plugin:

PackNameTranslations: Event: Create, Update; Stage: Pre; Object: product

UnpackNameOnRetrieve: Event: Retrieve; Stage: Post; Object: product

UnpackNameOnRetrieveMultiple: Event: RetrieveMultiple; Stage: Post; Object: product

UnpackNameOnRetrieveRelated: Event: Retrieve; Stage: Post; Object: opportunityproduct

UnpackNameOnRetrieveMultipleRelated: Event: RetrieveMultiple; Stage: Post; Object: opportunityproduct

All done now.