If summary field for child records equals zero is there a way to prevent the form from saving? Either editing or adding?

  • 0
  • 1
  • Question
  • Updated 3 years ago
  • Answered
I want to require at least one child record to be created/attached to parent for each parent record.
Photo of David

David

  • 10 Points

Posted 3 years ago

  • 0
  • 1
Photo of Xavier Fan

Xavier Fan, Champion

  • 410 Points 250 badge 2x thumb
You can use form rules for this (form rules are available for Premier plan and above, not Essentials).

Say you have a summary field called [# of Children] - which is the number of children related to the parent record.

Then set a form rule as follows:

When The Record is saved

and all of the following conditions are true

[# of Children] is equal to 0

[Date Created] is not equal to [leave blank]

abort the Save - "[Put message here] This parent record needs to have at least one child record."



EDIT:  Added condition for [Date Created] is not equal to [leave blank] - to allow the initial add of the parent to happen
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 65,806 Points 50k badge 2x thumb
Xavier,  I have not tested, but i would be surprised if the form can know the # of children until it has saved the record and the summary field has a chance to count.  So that Parent will never be able to save as it will not pass the form rule test.
Photo of Xavier Fan

Xavier Fan, Champion

  • 410 Points 250 badge 2x thumb
Hmm - you're right.  I added a condition to check for [Dated Created] is not blank - so that at least an add of the parent (with no children) can happen.  

Then when you edit the Parent, you'd need to add a Child record.  When the child record is saved, then it refreshes back to the parent, where the summary field has updated now to include the new child.  So at least that part should work.  I just tried it on a test app.

In any case, the "add Parent" part won't work - just because you need to save the Parent record first, for the child record to have something to attach to.
Photo of David

David

  • 10 Points
This solution works for what I needed to accomplish.  I appreciate the insight.  Still new to this system so figuring out these nuances really helps me out.  Thanks again!
Photo of Xavier Fan

Xavier Fan, Champion

  • 410 Points 250 badge 2x thumb
Ok great!
Photo of Arshad Khwaja

Arshad Khwaja

  • 3,152 Points 3k badge 2x thumb
For some reason this solution does not work for me as I tried to put the same tests before user moved to add child record.  Also, what is the difference between 'when the record is saved and saved after checking?
Photo of Xavier Fan

Xavier Fan, Champion

  • 410 Points 250 badge 2x thumb
Can you post this in a new question - and please describe the details of your setup.  Thanks!