Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Need logic to look at a subgrid and it needs to contain at least 1 record before form can be saved

Posted on by 2,645

I have a form and in that form is a subgrid.  A request came in saying a user needs to add at least one record into this subgrid before the overall form can be saved.

How can I do this so that the logic looks at the subgrid and sees at lease one record in there and then allows the user to save the form?

Can this be done from a workflow or Business Rule or script?

  • Verified answer
    Nya Profile Picture
    Nya 29,056 on at
    RE: Need logic to look at a subgrid and it needs to contain at least 1 record before form can be saved

    Hi,

    First of all, if the save action you mentioned means creation, the request cannot be achieved because the sub-grid records are based on a relationship between entities.

    If it means updating, you can try to achieve your request with a real-time workflow with importing Dynamics 365 Workflow Tools Solution.

    For example, update Account record only when there is at least one Contact in the Sub-grid.

    1. Import Dynamics 365 Workflow Tools Solution. There is a “Count Child Entity Record” feature which is not an OOTB method in workflow.
    2. Create a real-time workflow targeting at Account entity.

     pastedimage1628227942710v1.png

    1. Trigger the workflow before the record is updated. (Select all fields.)

     pastedimage1628227947375v2.png

    1. Get the count of the child records with the field in their relationship.

     pastedimage1628227952788v3.png

    1. Add a condition: When the count equals 0. The value can be found in the following location.

     pastedimage1628227973070v5.png

    1. Cancel the workflow. You can set the error message in “Set properties”

     pastedimage1628227978130v6.png

    After activating the workflow, when an account without related contacts is updated and the Save button is clicked, an error message will be shown and the updating will be terminated.

    pastedimage1628227989620v7.png

  • Verified answer
    meelamri Profile Picture
    meelamri 13,204 User Group Leader on at
    RE: Need logic to look at a subgrid and it needs to contain at least 1 record before form can be saved

    Hi, 

    You need a JS code that will run when the form is saved. CRM currently supports asynchronous operations for the save event. You can take advantage of this feature to check if the grid contains data by executing a retrieveMultiple. If the result is empty then you cancel the save.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans