One of the new features in CRM 2011 is the ability to finally define multiple forms for a single entity. CRM allows you to determine which form a user sees in two ways:
- Based on the Role of the current user. (The system administrator defines which roles have permission to view each form)
- The user can switch between multiple forms using a dropdown menu. CRM will automatically remember which form the user last selected and show them the same form the next time they open a record.
However, what if you want to determine which form a user sees based on some other criteria? There are a few things you can do…
- Navigate to the URL for a specific form. Forms can be navigated to directly by using a URL in the following format (the part in red is the ID of the form you want to display):
- The previous 2 options will work, but are not without their problems.
- And specifying the formId in the URL only works if you’re opening the form from a custom UI (that is, you can’t specify a formid when the user opens a record from a normal CRM view).
- Also, once a user opens a specific form CRM will remember that as the last selected form and the user will get the same form the next time they open a record, even if the formid is not provided in the URL.
Fortunately, there’s an easy way around these issues. It doesn’t seem to be documented in the SDK yet, but CRM saves the Id of the last form that a user viewed using the UserEntityUISettings entity, and any UserEntityUISettings record can be easily updated to set the Last Viewed form for a specific user:
//retrieve the user UI settings for a specific user and a specified entity:
QueryExpression query = new QueryExpression(UserEntityUISettings.EntityLogicalName);
query.Criteria.AddCondition("ownerid", ConditionOperator.Equal, userId);
query.Criteria.AddCondition("objecttypecode", ConditionOperator.Equal, entityObjectTypeCode);
EntityCollection UISettingsCollection = service.RetrieveMultiple(query);
if (UISettingsCollection.Entities.Count > 0)
//update the last viewed formId:
UserEntityUISettings settings = (UserEntityUISettings)UISettingsCollection;
settings.LastViewedFormXml = "<MRUForm><Form Type=\"Main\" Id=\"f5cfab6a-d4c2-4519-b68f-6e7485432e29\" /></MRUForm>";
This posting is provided "AS IS" with no warranties, and confers no rights.