I want to limit the number of child objects that a parent can have. So I setup a rule in the Parent Object.
IF LIST_SIZE(Parent.Children) > 1 THEN REPORT ERROR
The parent object is a new unsaved object and then children objects are being added using Add New Reference.
Adding the child object is fine. The problem is when I add more than 1 object (I put it to one just for easy testing), LIST_SIZE doesn't update properly. It stays stuck at 1 in the log. So it never triggers the Error.
Ideally what I'd like to do is prevent the user from even trying to add a new reference if there's x number of children already in the list if anyone has a way of doing that. I figured worse case is I could trigger an error after x number of child objects.
Possible Bug - Parent/Child Object Issues
Re: Possible Bug - Parent/Child Object Issues
You could have an attribute in the parent BO that tracks the number of children. Sounds like you would want the rule that updates the number of children to be dynamic.Ideally what I'd like to do is prevent the user from even trying to add a new reference if there's x number of children already in the list if anyone has a way of doing that. I figured worse case is I could trigger an error after x number of child objects.
Then you can make the operation to add children be conditional ... not available is the number of children is > x.
Tom - V8.8 build 3137 - MySql / PostGres
Re: Possible Bug - Parent/Child Object Issues
This exactly what I want to do. I tried this but couldn't get it to work. I used the rules:You could have an attribute in the parent BO that tracks the number of children. Sounds like you would want the rule that updates the number of children to be dynamic.
Then you can make the operation to add children be conditional ... not available is the number of children is > x.
IF ChildObject WAS ADDED TO ParentObject.Children THEN INCREASE ParentObject.ChildCounter BY 1
IF ChildObject WAS REMOVED FROM ParentObject.Children THEN DECREASE ParentObject.ChildCounter BY 1
But looking at the logs, the WAS ADDED TO/WAS REMOVED FROM clause was never triggered. I tried setting it to work with the UI dynamically and still nothing.
I'm wondering if it had something to do with the ParentObject not being saved.
Re: Possible Bug - Parent/Child Object Issues
One comment on the rule on the parent regarding # of children.kaygee1 wrote:This exactly what I want to do. I tried this but couldn't get it to work. I used the rules:You could have an attribute in the parent BO that tracks the number of children. Sounds like you would want the rule that updates the number of children to be dynamic.
Then you can make the operation to add children be conditional ... not available is the number of children is > x.
IF ChildObject WAS ADDED TO ParentObject.Children THEN INCREASE ParentObject.ChildCounter BY 1
IF ChildObject WAS REMOVED FROM ParentObject.Children THEN DECREASE ParentObject.ChildCounter BY 1
But looking at the logs, the WAS ADDED TO/WAS REMOVED FROM clause was never triggered. I tried setting it to work with the UI dynamically and still nothing.
I'm wondering if it had something to do with the ParentObject not being saved.
just check if ChilObject Was Changed and then use COUNT function of children and store it in parent. This way there is never a mismatch. I use it all the time and works.
Re: Possible Bug - Parent/Child Object Issues
I'm going to give this a go again. This was the first way I tried to do it but the WAS CHANGED event wasn't getting triggered kinda like how the WAS ADDED TO didn't seem to get triggered. But I'll try again.if ChilObject Was Changed and then use COUNT function of children and store it in parent
Re: Possible Bug - Parent/Child Object Issues
Okay just so I don't think I'm seeing things. I've attached a screenshot.
You can see my child table, with three objects in it (scroll down in the attached image). However looking at the LogViewer you see that COUNT in a rule on the parent object Questionnaire, only returns a count of 1. I went to 3 just to see if there was a timing issue in hopes that it would say there were 2 child objects and that it was just doing the count before one of the child objects was being attached.
I'm using Add New Reference to add the child objects. But it's being added to a Parent Object that is initially unsaved. I'm wondering if that has something to do with what I'm seeing.
I'm using version 7.1 build 2223
You can see my child table, with three objects in it (scroll down in the attached image). However looking at the LogViewer you see that COUNT in a rule on the parent object Questionnaire, only returns a count of 1. I went to 3 just to see if there was a timing issue in hopes that it would say there were 2 child objects and that it was just doing the count before one of the child objects was being attached.
I'm using Add New Reference to add the child objects. But it's being added to a Parent Object that is initially unsaved. I'm wondering if that has something to do with what I'm seeing.
I'm using version 7.1 build 2223
- Attachments
-
- countingissue.png (26.51 KiB) Viewed 23350 times
Re: Possible Bug - Parent/Child Object Issues
how about if in the Parent BO you have an attribute called noChildren
In the rules for this BO
IF Parent.om_Children WAS CHANGED or Children FROM Parent.om_Children WAS CHANGED THEN
Parent.noChildren = COUNT Children.ID WHERE (Children in Parent.om_Children)
(I know you only need one of the "WAS CHANGED" clauses, but I never remember which one is triggered if records are added and which is triggered when existing records are changed)
Then, as someone smarter than me suggested, you only enable the button to add children when Parent.noChildren < maxnumber
bruce
In the rules for this BO
IF Parent.om_Children WAS CHANGED or Children FROM Parent.om_Children WAS CHANGED THEN
Parent.noChildren = COUNT Children.ID WHERE (Children in Parent.om_Children)
(I know you only need one of the "WAS CHANGED" clauses, but I never remember which one is triggered if records are added and which is triggered when existing records are changed)
Then, as someone smarter than me suggested, you only enable the button to add children when Parent.noChildren < maxnumber
bruce
Re: Possible Bug - Parent/Child Object Issues
Thanks Bruce,
I'll give it a go, but I don't think that's the problem. The COUNT is off and as long as that is the issue I'm not able to prevent the button from showing/not showing.
That being said, how would you enable/disable the add children feature? I'm digging in the documentation and looking at the available options but don't see how it's possible.
Cheers,
Kevin
I'll give it a go, but I don't think that's the problem. The COUNT is off and as long as that is the issue I'm not able to prevent the button from showing/not showing.
That being said, how would you enable/disable the add children feature? I'm digging in the documentation and looking at the available options but don't see how it's possible.
Cheers,
Kevin
Re: Possible Bug - Parent/Child Object Issues
Kevin,
Attached is a demo BSV that shows how this can work. Note that this BSV is V6 since that is what I had open today.
To use the demo:
1) Click "Set max children" - enter the max number of children in a parent here. This is stored in SystemSettings.
2) Click Edit on the admin user in the Users Query. You'll note that the Add New Child button will appear / disappear at the proper time according to the number in Max Children attribute. You can also delete children which will update the number of children for that user + the Add New Children button may reappear if the user now has less than the Max Children.
Attached is a demo BSV that shows how this can work. Note that this BSV is V6 since that is what I had open today.
To use the demo:
1) Click "Set max children" - enter the max number of children in a parent here. This is stored in SystemSettings.
2) Click Edit on the admin user in the Users Query. You'll note that the Add New Child button will appear / disappear at the proper time according to the number in Max Children attribute. You can also delete children which will update the number of children for that user + the Add New Children button may reappear if the user now has less than the Max Children.
- Attachments
-
- ParentChildDemo.zip
- (34.47 KiB) Downloaded 579 times
Tom - V8.8 build 3137 - MySql / PostGres
Re: Possible Bug - Parent/Child Object Issues
Tom this is excellent, it took me a bit to find how it was setup, but I've learned a lot in just 5 minutes and for that I thank you!
And furthermore, this actually proves that there's something amiss with how AwareIM handles New Objects.
It works perfectly with already stored objects (Edit User).
However, if you click on New Object and create a regular user, it opens the same form to add children, but the Add Children button is not visible!
RegularUser.Nbr_children<SystemSettings.MaxChildren OR RegularUser.Nbr_children IS UNDEFINED
Looking at the log, nbr_children is set to 0, but it still doesn't display the button. I suspect that RegularUser isn't properly defined for new objects and so the criteria above fails. Although I couldn't see the criteria even processed in the log. I'm going to check if it's processed when in edit mode.
And furthermore, this actually proves that there's something amiss with how AwareIM handles New Objects.
It works perfectly with already stored objects (Edit User).
However, if you click on New Object and create a regular user, it opens the same form to add children, but the Add Children button is not visible!
RegularUser.Nbr_children<SystemSettings.MaxChildren OR RegularUser.Nbr_children IS UNDEFINED
Looking at the log, nbr_children is set to 0, but it still doesn't display the button. I suspect that RegularUser isn't properly defined for new objects and so the criteria above fails. Although I couldn't see the criteria even processed in the log. I'm going to check if it's processed when in edit mode.
Re: Possible Bug - Parent/Child Object Issues
Whenever there might be children involved, I reckon it's always best to create a blank parent instance and edit it, when the user initiates creation of a new parent instance.
Doesn't take much to clean up any blank parents which don't convert to real instances by having their data completed.
Doesn't take much to clean up any blank parents which don't convert to real instances by having their data completed.
Re: Possible Bug - Parent/Child Object Issues
Yeah that's a workaround. But then it potentially causes other problems. The ability to set required fields becomes complicated.
Re: Possible Bug - Parent/Child Object Issues
Don't bother setting any required properties. Use NO VALIDATION or NO RULES so you can create a blank new record.
Re: Possible Bug - Parent/Child Object Issues
Ahhhh, that's interesting! Let me see how that goes.