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
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
Come on.. ask for a confirmation if it's so important.. those are the details:)
Creating the record without the user pressing the save button? Sounds like a hack to me! ;)
#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.
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!
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(); } } } }
Hope this helps.
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
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
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,214 Most Valuable Professional
nmaenpaa 101,156