Fooksie
Fooksie

Reputation: 480

How can I intercept/replace the New button click on the sub-grid?

Let's start by establishing that some of the D365 out-of-the-box functionality can be a little clunky at times.

For 1:N relationships, when you press the "+ New" button on the sub-grid the behavior changes depending on whether the relationship is configured as either "Optional" or "Business Required". It either lets you search and add an existing record (optional) or it always makes you create a new record (business required).

This is fine. I can control that.

For N:N relationships that "+ New" button on the sub-grid only ever lets me search for an existing record. In this instance I only ever want to create a new record each time.

The scenario is relating the systemuser entity to a custom entity (via N:N relationship) to indicate their "specialization" in a field, it's called. I have another lookup entity that indicates the field and my custom specialization entity has the following fields:

  1. Name (text)
  2. Field (lookup to the specialization field)
  3. Level (to gauge their degree of specialization)

If I was to reuse an existing record it would also be associated with another user's specialization. If I was to change the level of ability they have in that field it would impact any other users connected with that record.

I need to create a new record each time. If I can replace that click functionality I can just pop up a new dialog and then create the records myself.

Failing this, I need to replace the entire sub-grid control as a custom web resource, please don't make me do that!

Upvotes: 1

Views: 1764

Answers (1)

I have a similar implementation called Banker Skillset in my project. You can search & add the existing record but error will be thrown saying “already record is associated with another record”. I don’t understand that then why “Add existing” button is allowed using inline search lookup in this N:N scenario. Like you said who’ll remap (take out & give it to) someone else record like this.

  1. You can still make systemuser & specialization lookups as mandatory in that Manual N:N entity - user specialization. If you enable Quick create of that N:N intersect entity, QC form will drop on top when you click (+) in subgrid

  2. Another option is using Xrm.Utility.lookupObjects to allow users to choose multiple specialization and then add the N:N with default level (degree of specialization) for all the selected records. Then user can choose the individual level using editable grid. For this you have to hide the existing (+) buttons & start creating a new ribbon button using Ribbon workbench

Read more

Upvotes: 2

Related Questions