Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to show entity form depending on entity field value?

Posted on by 515

Hello,

I have two different form for one entity. I want to implement such conditional mechanism that will decide which form to show based on some field value. How can I achieve it?

Thanks,

Ashish

*This post is locked for comments

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: How to show entity form depending on entity field value?

    Come on.. ask for a confirmation if it's so important.. those are the details:)

  • ScottDurow Profile Picture
    ScottDurow 50,177 on at
    RE: How to show entity form depending on entity field value?

    Creating the record without the user pressing the save button? Sounds like a hack to me! ;)

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: How to show entity form depending on entity field value?

    #2 can be handled easily.. just call save before navigating to a different form. Also, I don't think the idea of those forms is to give every user access to only one form - in the end, it is still expected that some users may have access to multiple forms either way:

    technet.microsoft.com/.../dn531143.aspx

    I don't like the way it works because of the screen flickering, but, realistically, hiding and displaying all those fields dynamically can end up being very complicated, yet those scripts  can break fields and sections alignment. It's a trade-off.. I had to do it both ways.

  • ScottDurow Profile Picture
    ScottDurow 50,177 on at
    RE: How to show entity form depending on entity field value?

    I would really strongly recommend against these Javascript approaches.

    1. They do not work on the mobile/tablet client

    2. If a user created a new record and then causes the form to reload they will loose any data that they have entered and any mapped fields bases on the record that the record is being created from.

    The reason I call it a hack is that it is using a feature not in the way that it was intended to be used!  

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: How to show entity form depending on entity field value?

    Hi Ashish,

    You could use the following Javascript code to switch forms based on field value. Register this function on the load of the form as well as on change of the field value.

    function switchForm() {
        var lblForm;
        // get the value age field
        var value = Xrm.Page.getAttribute("attributeLogicalName").getValue();
        //check if the field equals value A
        if (value == "A") {
            lblForm = "FormA";
        }
        else {
            lblForm = "FormB";
        }
        //check if the current form is form need to be displayed based on the value
        if (Xrm.Page.ui.formSelector.getCurrentItem().getLabel() != lblForm) {
            var items = Xrm.Page.ui.formSelector.items.get();
            for (var i in items) {
                var item = items[i];
                var itemId = item.getId();
                var itemLabel = item.getLabel();
                if (itemLabel == lblForm) {
                    //navigate to the form
                    item.navigate();
                } 
            } 
        } 
    }

    See: www.magnetismsolutions.com/blog/gayanperera/2013/07/24/how-to-switch-a-dynamics-crm-form-based-on-a-value

    Hope this helps.

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: How to show entity form depending on entity field value?

    Hi Ashish,

     you are probably looking for the "navigate" method:

    msdn.microsoft.com/.../gg309560.aspx

    neilparkhurst.com/.../javascript-form-navigate

     I don't think it's really a hack to use that method, but, at the same time, you are not going to get the best user experience there. You can only use "navigate" once the form has been loaded, so, unless the user is extremely lucky, most of the time what they will see is:

    - Last used form will show up

    - Your script will check the field value and call "navigate"

    - CRM will load another form

     Basically, the user will have to wait twice as long, and, also, they'll see quite a bit of action on the screen before they can start doing anything with the record

  • Suggested answer
    ScottDurow Profile Picture
    ScottDurow 50,177 on at
    RE: How to show entity form depending on entity field value?

    Hi Ashish,

    Entity forms are not designed to be used in this way. They are designed to be used based on the role of the user - so a user in finance may see a different layout to a user in sales.

    To show different fields based on a form value you should use business rules to show/hide fields.

    There are various Javascript hacks to do what you want but they do not work reliably on all clients and can interfere with the form load mechanisms.

    Hope this helps

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans