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:
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…
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[0]; settings.LastViewedFormXml = "<MRUForm><Form Type=\"Main\" Id=\"f5cfab6a-d4c2-4519-b68f-6e7485432e29\" /></MRUForm>"; service.Update(settings); }
The next time the user opens any record for the specified entity, they will view the form that is specified in the LastViewedFormXml. No need to specify a formId in the URL, and no need to redirect the user to a different form in JavaScript.
~Erik Pool
This posting is provided "AS IS" with no warranties, and confers no rights.
//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[0];
settings.LastViewedFormXml = "<MRUForm><Form Type=\"Main\" Id=\"f5cfab6a-d4c2-4519-b68f-6e7485432e29\" /></MRUForm>";
service.Update(settings);
}