Blog, Development

Open proper form based on record’s data – UCI way

A cool feature of the 2011 CRM version was the possibility to have multiple forms for the same entity. That feature is awesome but it has one drawback – it’s not possible to create some kind of dependency between the form to use in the context of data. Among developers, there were a few ways to address this scenario.

The first way I knew of was JavaScript that was executed during the form load. This method checked a record’s data and switched the form using formSelector – example from Magnetism Solution. That approach worked, but it was a bit confusing because of form “blink” that was caused with the reload.

The second way I knew is the “Plugin” way – the form to be shown is set in the code behind (the scenes? In the background?). All credit goes to Gonzalo Ruiz, who came up with this wonderful post.  Unfortunately, this way doesn’t work for 2015 and any later version.

So how should one address this requirement nowadays? I recalled this post from my friend and former (hopefully short-term) MVP Artem Grunin. Btw – if you haven’t subscribed to his blog and twitter do it now because he rocks. I decided to take and implement that idea.



There are 3 forms configured for the “Account” entity in CE – “Default”, “Customer” and “Partner”. When a user opens an account with “Relationship Type” that is equal to “Customer”, he should be navigated to the “Customer” form. When a user opens an account with “Relationship Type” that is equal to “Partner” he should be navigated to the “Partner” form. In all other situations the “Default” form should be presented.


Let’s start from JavaScript. It’s self explanatory:

Ribbon Changes

Create a solution and add the “Account” entity. Open “Ribbon Workbench” and load your solution. Add the following command to the ribbon:

The Id of the command has to be exactly “Mscrm.OpenRecordItem”. As an action, choose JavaScript and point to the WebResource you created on the previous step, point to the proper function and add “FirstSelectedItemId” as a parameter for the function.

Functionality will not work as expected without button to be added to the ribbon but I don’t want this button to be visible on the ribbon so I add “Enable Rule” that will always return false and button will not be shown. Here is screenshot of “Enable Rule”:

Once command is added – add the button with the same id – exactly “Mscrm.OpenRecordItem” and use command you created on the previous step as a command for this button:

Click the “Publish” button to import changes to the instance. Now you can open CE, navigate to accounts grid and test how it works. If you completed everything the right way you will get everything working fine.


  1. Great Approach, thanks.
    You mention the old javascript blink of web client.
    It didn’t look like the UCI solution suffered from that issue in the video?
    Does the above present a form switcher that doesn’t suffer from the reload blink now?

    1. David,
      The trick is that this approach doesn’t use “FormSwitcher” approach at all so the form doesn’t blink. Script navigates user to the proper form in the first place.

  2. Very nice article Andrew.I really like your ideas.

    I have one question here .Is the supported to override Mscrm.AddNewRecordFromSubGridStandard command also to open new record in modal form.

    1. Bhuvita,
      I haven’t tried that but I believe if you add that command and command to the subgrid of the entity with the same Mscrm.OpenRecordItem id it should override the standard way and you will be able to open the record in the modal form.

  3. Hi Andrew, When I tried with adding the button in either Home or Subgrid, it worked great but as soon as its added for both, it works for one and not for the other. Have you tried adding it for both? My requirement is that I need to open it from the main view as well as from the subgrid. Any help would be greatly appreciated. Cheers, Krutika

    1. Krutika,
      I can confirm that I can replicate your behavior. I would recommend to get in touch with Microsoft and ask for help.

      1. I believe it’s due to the Ribbon Workbench using the same value for CustomUIAction ID and Button ID. If you manually edit the RibbonDiffXml in the customizations.xml according to the Microsoft article here, you can make it work for both instances. I added a console.log() line to alert when the custom method is called and it fired from both the HomepageGrid and the SubGrid contexts.

  4. var RN = RN || {};
    RN.ActionRibbon = (function(){

    function openRecord(recordId) {
    //Setting formId to “Default”
    var formId = “0A706BAB-B2B0-EA11-A812-001DD83096F2”; //main form

    //Get the record
    Xrm.WebApi.retrieveRecord(“brm_action”, recordId).then(

    var Id = result.RecordId

    var pageInput = {
    pageType: “entityrecord”,
    entityName: “brm_action”,
    entityId: recordId
    var navigationOptions = {
    target: 2,
    height: { value: 100, unit: “%” },
    width: { value: 50, unit: “%” },
    position: 1

    Xrm.Navigation.navigateTo(pageInput, navigationOptions).then(
    function success() {
    // Run code on success
    function error() {
    // Handle errors


    //If anything goes wrong log the error

    //and open “by default” form
    entityName: “brm_action”,
    entityId: recordId,
    formId: formId

    return {
    OpenRecord: openRecord,


      1. Sorry Andrew, I think some of my message was cut off.

        I was able to modify your directions above to use the navigateTo function instead of OpenForm so that the new modal forms could be used. The button I added was on the subgrid instead of the home page. It worked great!

        However, I did notice that when the modal form window closes, the subgrid doesn’t update until the user manually clicks refresh on the main form ribbon.

        Do you know of or recommend a way to wire a refresh command to avoid the user having to manually refresh the page?

        1. Open form
        2. On the form, there is a subgrid
        3. Click a record in the subgrid to open the modal form (this works great using your modified code)
        4. The user makes a change to the record in the modal form, and then closes the form (“e.g. save and close”)

        What is happening:
        a) The user doesn’t see the changes he made reflected in the subgrid until he hits refresh

        What I’m trying to do:
        b) After the dialog closes the form, the subgrid and/or the parent form refreshes so that the update can be seen.

  5. Andrew, beautiful article. I like all your ideas present on you tube.
    Sorry, but I am bit confused with the way your logic works? From where script behind button is getting called and how? I have written it on form load but as you said this approach has “blink” issue. Please explain.

    1. Hello,
      When you register command this way platform uses it instead of the standard code used to open the form.

      1. Thanks for above explanation.
        I have implemented in my instance. I am able to navigate to correct form, but once I am on any form, I am not able to see option to navigate to other records directly from forms. Even in your you tube video, I am not able to see the button to navigate to other records. Is this a bug?

        1. Hello,
          What do you mean with the button to navigate to other records? Can you please be more specific?

  6. Hi Andrew,

    I don’t know how to attach images here.
    If you navigate to any record from home page view, form will have button on command ribbon before standard buttons which is used to navigate to other records directly from form.

    1. Ok. You meant the quick navigation between records that are available in the grid. I don’t know what it’s not there but it seems that this is the side affect of this enhancement.

  7. It might be important to note that there are other ways to navigate to a record (such as from a lookup link), and you’ll probably want to include the “old” way of navigating to the correct form onLoad in case one of these other methods is used.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.