To register for the forums, please contact your Digital-Clay representative.

Running checks

Community-oriented help and tech-support for the Digital-Clay platform.
Post Reply
NewAspeqt
Posts: 9
Joined: Tue Jun 07, 2011 10:21 am

Running checks

Post by NewAspeqt »

How can we write a check which runs on a tree of hierarchies to identify an hierarchical loop?
ZevToledano
Posts: 722
Joined: Fri Apr 03, 2009 2:29 pm

Re: Running checks

Post by ZevToledano »

Well, if the amount of levels that you are expecting a 'loop' on is limited to say, 3 levels, then you can simply make a validation rule for each level:
I.e. you make a link from child->parent, then make a validation automation rule that checks that the parent's name (or unique identifying field) is not the same as the current record being added/updated (using a custom function).
Then you make a custom link for child->parent->grandparent and add another validation rule for that, etc.

This assumes that the link between records is a single one from child to parent (i.e. that the child has a one-to-many linked field called 'parent').

If you are expecting a large amount or unlimited levels then it's a little more difficult. My approach for this would be to make a flattened list of all parents. For example:
Add a Notes field which I will call 'flat-list', and every time a record is added/changed:
1 Clear this field
2 Copy the value from the parent's 'flat-list' field into this one, and append the parent's name itself to the list as well with a separator (use a custom function to concatenate the string)
3 Trigger a change in all of the children's records so that the same automation runs on them as well

Now you have a flat list of all parents in each record, you can check to see whether the current name/uniqueid is contained inside the parent's 'flat-list' field with a single validation rule.

Let me know if anything is unclear.
Post Reply