This discussion is archived
3 Replies Latest reply: Aug 21, 2012 9:15 PM by 956042 RSS


956849 Newbie
Currently Being Moderated
I have a test rule based on the OPM function help which checks entity values :

the person is happy if
forAllScope(the person's cats)
the cat is happy

I've set up all my entites and relationships and everything works as expected when the person's cats entity contains one to many instances, etc. but the question I have is that if there are no "cat" entities, but containment for that entitiy is set to complete in the debugger it returns true to the person being happy - even though nowhere in the scope is the cat happy (as there are no entity instances).

What I would like to happen is for "the person is happy" to be false if no cat entities are present and containment is complete. I understand I could add an additional ExistsScope but I really want to understand what ForAllScope is doing in this situation.

  • 1. Re: ForAllScope
    BradTuckett Pro
    Currently Being Moderated
    Hi Mark,

    If you search the user's guide for "zero instances", you should be pointed towards the topic "Use an entity or relationship in a rule", which notes the following (taken from OPM v10.4.1):
    Note that if there are zero instances of the entity, then the rule using the For All operator will evaluate to true.
    This is also the case for the ForAllScope operator

  • 2. Re: ForAllScope
    MattSevin Pro
    Currently Being Moderated
    Another way to think of this is the default is to assume that ForAllScope will evaluate to true if all entities are known AND those that exist satisfy the subsequent conditions. What this means is you need to decide whether you want the logic to represent "at least one cat exists AND all cats are happy" (which requires an additional condition) or "every cat that exists is happy" (the default).

    In terms of the policies / rules, it is always best to be explicit (regardless of the default behavior of a function such as ForAllScope). The recommended approach would be to explicitly state whether at least one cat must exist for the person to be happy OR whether the person is happy if the person has no cat's.
  • 3. Re: ForAllScope
    956042 Newbie
    Currently Being Moderated
    Add another condition: InstanceCount(the person's cats) > 0
    Conjunction to be used: and


  • Correct Answers - 10 points
  • Helpful Answers - 5 points