Francis Ducharme Francis Ducharme - 1 year ago 73
Javascript Question

Adding filter on subgrid add button dropdown list

I have a 1:N relationship from EntityA to EntityB, I have plopped a subgrid on the form of EntityA showing all related (1:N) EntityB records.

As usual, there is a "+" button for that subgrid, when clicking it, this shows a textbox with an hourglass to the right. When clicking the hourglass, a drop down deploys, showing all EntityB records. At the end of this list, there's a "New +" button, letting users add a new record.

Since this is a 1:N relationsip, adding an EntityB already linked to another EntityA throws an error saying the record is already associated.

Why is it then not filtering or preventing the ability to select other records then ?

If I can't configure the grid so that when the "+" icon is clicked, it goes straight to create form of EntityB, can I at least filter the dropdown so it shows no record at all and reduce likelyhood of users being confused by showing only the "New +" link ?

I know how to filter for simple lookup fields

Xrm.Page.getControl('new_field').addPreSearch(function () {

But for that dropdown list, I'm at a loss.

Answer Source

This is because you have a 1:N relationship between EntityA and EntityB without the relationship field (look up) being a required field. This does not enforce relationship integrity, meaning you could have associations between records which do not have a related record.

Make the lookup field (to Entity A) on EntityB form a required field, which will automatically create a new record when + button is clicked.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download