CoreBOSBB
[SOLVED] Check if a record has siblings on creation - Printable Version

+- CoreBOSBB (https://discussions.corebos.org)
+-- Forum: Support (https://discussions.corebos.org/forumdisplay.php?fid=17)
+--- Forum: Administrator Support (https://discussions.corebos.org/forumdisplay.php?fid=8)
+--- Thread: [SOLVED] Check if a record has siblings on creation (/showthread.php?tid=1541)



[SOLVED] Check if a record has siblings on creation - Guido1982 - 07-12-2019

OK, I'm pretty sure we can do this, just not sure how exactly:

I want to create a workflow that runs when a record of module A is created. Records from module A contain a UI10 type field to module B. I want to check if this record (the new, module A type record) is the only one related to module B through that UI10 field. If that condition is met, a checkbox should be true, otherwise it should be false.

Or would it be better to do this through a businessmap and use some aggregation expression?


RE: Check if a record has siblings on creation - joebordes - 07-14-2019

do you mean that all the other records in module A must not be related to B?
I don't see any way of doing that. I would create an aftersave event handler


RE: Check if a record has siblings on creation - Guido1982 - 07-15-2019

Could be nice to add this to the workflow conditions? Like a condition that says "Is unique through" and then the second dropdown would present you with the UI10 fields you could use the check on? I could create a PR.


RE: Check if a record has siblings on creation - joebordes - 07-15-2019

I would actually see it more useful as a validation, but I guess a condition would be good too. Sure , go ahead


RE: Check if a record has siblings on creation - Guido1982 - 07-15-2019

Yeah I can see how it would work as a validation, but that won't allow actively setting some checkbox (for example) behind the scenes. Maybe just do both.


RE: Check if a record has siblings on creation - Guido1982 - 07-15-2019

OK so here is the PR. I now created it so it only checks if the parent of the current record has children like the child record or if the child record is unique in respect to its parent. We could also alter it so that it returns a count, so you can enter a number in the box.


RE: Check if a record has siblings on creation - joebordes - 07-15-2019

Now that I see the code I understand better what you are trying to do. I think the "EXISTS" condition could fit your needs. If I remember correctly this condition permits you to know if there exists another record with the same value in a field. In this case, if EXISTS returns true there is another record with that value, if not, the record being saved is unique.

Would that be equivalent to the new condition you added?


RE: Check if a record has siblings on creation - Guido1982 - 07-15-2019

Yes it would. I'd like to use the QG to avoid duplicate code, but as I mentioned in the PR, while posting the PR I came upon the thought that it might be nice to expand it beyond a true/false evaluation and let you evaluate against a number so you can tie some action to the nth record. So you could say "change the 5th child's name to John", poor John.


RE: Check if a record has siblings on creation - joebordes - 07-15-2019

I agree, very interesting


RE: Check if a record has siblings on creation - Guido1982 - 09-19-2019

For anyone interested: the workflow system now supports this