1 Reply Latest reply on Aug 22, 2012 4:32 PM by Ben Rogers

    Zero Instances - InstanceCount resulting in "unknown"

      I’m having trouble understanding why the InstanceCount results in "unknown" if there are zero instances. If you add an instance of the entity being counted and then remove it, InstanceCount results in 0. When you first start debugging, the result is unknown.

      Here is a simple rule example. "the persons of the family" is a many to many relationship from Global to the person:

      the individual count = InstanceCount(the persons of the family)

      Thanks for any help!
        • 1. Re: Zero Instances - InstanceCount resulting in "unknown"
          Ben Rogers

          InstanceCount will return unknown if:
          -containment is not complete for that entity (I assume you are using OPA 10.2 or later)
          -or you have not set the relationship to "known" if it is a reference relationship

          Next time, when you start the debugger (fresh session), do nothing else but right click on the persons of the family and click "containment complete". The individual count should be inferred as 0 without you needing to add one and then take it away.

          When containment is not complete, this essentially tells OPA that "there are more to come..." or "this isn't finished yet...", so it cannot reliably count the instances, and therefore returns unknown. Marking containment complete tells OPA that "this will not change, no more will be added or taken away" and therefore OPA can reliably infer the InstanceCount.

          This is exactly the same for a reference (manual) relationship. If you do not set the relationship to "known" in the debugger, OPA keeps the InstanceCount as unknown, until it is explicitly set to "known".

          Most of the time the OPM debugger handles this for you - once you add one instance OPM automatically marks the containment as complete for convenience so that you dont have to keep manually ticking "containment complete". Even if you remove the initial instance, the containment is still marked as complete, again for convenience, which is why you are seeing the 0 automatically inferred when you remove it. This is the same principle for entity collection screens - once the screen has been submitted - even if no instances have been added - the containment is marked as complete.

          Hope this helps, let me know if you have any more questions.