Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Dynamics CRM 2011 from using last used form

By default dynamics saves the last form used by a user for a certain entity. If the user later opens an entity of the same type dynamics uses the last used form.

Is there a way to force dynamics to always use a certain form?

like image 702
Geaz Avatar asked Nov 23 '25 01:11

Geaz


2 Answers

According to this MVP's blog you can update UserEntityUISettings record for the specific owner and entity in a Post-Retrieve plugin to set the form to show.

You'll have to fetch and update the UserEntityUISettings which respects the following conditions:

  • ownerid equals plugin context's UserId
  • 'objecttypecode' equals the entity's type code (the number, not the string)

You need to update the lastviewedformxml attribute to set the form you want users to see. The attribute is a string which should have this format:

"<MRUForm><Form Type=\"Main\" Id=\"FORM_GUID_HERE\" /></MRUForm>"

Form GUIDs can be grabbed from any exported solution's customization.xml which includes the entity.

There are some gotchas to be aware of:

  • This plugin is sandbox-able (so it's ok) but it's interacting with an undocumented attribute so make sure it works after any update (it should, but you never know...)
  • "Special" users like SYSTEM don't have any record in UserEntityUISettings so if the query returns 0 records you shouldn't throw.
  • I suspect that users would no longer be able to switch forms manually...
  • This being a plugin on retrieve, it might slow down lookups
like image 54
Alex Avatar answered Nov 25 '25 17:11

Alex


You need to Write JavaScript to Switch form to default (or any other) form on load.

function switchForm() {

// Get current form's Label
var item = Xrm.Page.ui.formSelector.getCurrentItem();
itemLabel = item.getLabel();

if (itemLabel != "Information")
{
  //load Information form
  var items = Xrm.Page.ui.formSelector.items.get();
  for (var i in items)
  {
    var form= items[i];
    var formId = form.getId();
    var formLabel = form.getLabel();

    //Check condition either on ID or Label from Form
    if (formLabel == "Information")
    {     
      form.navigate();
    } 
  }
} 

Please check these:

Xrm.Page.ui.formSelector item (client-side reference)

like image 22
Scorpion Avatar answered Nov 25 '25 15:11

Scorpion