web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

How to limit the number of related records to a given number

(0) ShareShare
ReportReport
Posted on by 38

Dear all,

How can I limit the number of related records?

The use case: 

- Entity "Location" has a field "Can hold multiple items"

- Entity "Item" has a lookup field "Location"

- When an item gets a Location assigned that already has an item assigned to it (in the case "Can hold multiple items" = False), it should be prevented somehow (indicating that the chosen location already has reached its limit)

How can I achieve this? I have tried a custom plugin, but it seems that this does not prevent anything; see code here : OneOrMultipleItemsPerLocation.cs (github.com)

A more general use case would be to have a numeric field "number of maximum items on this location" that would prevent to have more than this number assigned to this location....

Thanks,
Koen

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello Koen,

    Can you please provide the screenshot that demonstrates how you registered the step for this plugin?

    Generally speaking, you chose the proper direction - on create of the child check the number of child records for a particular parent.

    In your case I believe the following line breaks the code:

    if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is cr510_Item item)

    the reason is that "Target" is actually of type Entity - it doesn't come as your late-bound entity.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
11manish Profile Picture

11manish 61 Super User 2026 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 38 Most Valuable Professional

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 22 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans