Skip to main content

Notifications

Announcements

No record found.

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 36

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
    a33ik 84,325 Most Valuable Professional on at
    RE: How to limit the number of related records to a given number

    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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,759 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,468 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans