Dynamics 365 sub-grid add new and add existing

In Dynamics 365, if you put a sub-grid to display related records in a parent, there is always a plus (+) sign to allow user either adding a new child record or an existing record.

The default behavior when user clicks the plus (+) sign is to display a lookup box, user can then click the lookup to drop down a list of child records or click the New button at the bottom of the drop down list.


However, sometimes we may want to force the plus (+) sign to open the new record form straight away without displaying the lookup drop down to users.

For example, we have a parent entity called Project, which is a custom entity. And we create a second custom entity called Service Contract, which has N to 1 relationship to Project. The project form looks like below.

For the purpose of the demo, we say the requirement is to always open the new service contract form when user clicks the plus (+) sign.

The easiest way to do this is to change the Project lookup field in the Service Contract entity, and make the Field Requirement to Business Required.


This will force the plus (+) sign to open the new service contract form and it will not display the lookup box.

However, what if we don't want the project lookup field to be mandatory when creating a contract? The service contract entity can be design to store other types of contracts, such as support contract, master agreement, and other types of contracts.

In this case, we will need to leave the project lookup field as optional, and use a different method. It can be done by customizing the Ribbon client extension.

In this demo, I will be using Ribbon Workbench 2016. If you don't have this, you can download it from https://www.develop1.net/public/rwb/ribbonworkbench.aspx and import the managed solution into your Dynamics 365 instance.

Open the workbench, and use a solution that contains the entities you need to customize the ribbon. In our example, it will be an unmanaged solution that contains the service contract entity.

The button to be customized is the ADD EXISTING ribbon button's command of the service contract entity.


There are two ADD EXISTING buttons in the SubGrid, you need to customize the one with Id "Mscrm.SubGrid.entityname.AddExistingStandard". And you should select Customize Command.

Then you need to create a new Display Rule like below.


Basically the display rule is saying: if the current form that contains the sub-grid is the Project entity form, then return False to not display the ADD EXISTING button.

Then you need to add the above display rule to the command.


Publish the ribbon changes, and you are all done!

Now, if you fresh your project record form, and try clicking the plus (+) sign, it will open the new service contract form instead of displaying the lookup box.

In addition, enable rule also works! The behavior of should Dynamics 365 display the lookup drop down when user clicks the plus (+) sign is controlled by if the ADD EXISTING button is enabled or displayed or not.

Using enable rule can give us a lot more flexibility to control this behavior, because a developer can write a JavaScript that can be used in the enable rule.

You just need to consider all your use cases before implementing it.





Comments

Popular posts from this blog

Dynamics 365 Web API get entity using alternate key value that has apostrophe/single quote in it

TLS 1.2 and PowerShell