Back to Basics : ForScope, For, ExistsScope and the rest

Back to Basics : ForScope, For, ExistsScope : If there is one error message guaranteed to strike fear into the heart of an Oracle Policy Automation rulesmith learning their craft, it’s the “My Thing is not available here. You may need an alias…” error that pops up just as things start getting interesting when you are learning about Entities and Relationships.

It doesn’t help that the error is a bit opaque. But at heart this error is trying to tell you some good news – you’ve gotten your Entities off the ground!

Let’s start with some ideas to get back on track:

Firstly a picture. Its nearly Halloween and here in my office they’ve been decorating so I’ve been forced to follow their lead:

 

Back to Basics : ForScope, For, ExistsScope and the rest 1
Imagine you are walking through the graveyard late at night. It’s dark and stormy and you find your way to the first tomb. A big, crumbling Gothic one. And inside are some graves. And in each grave there are maybe some ghosts.

Alright, you get the idea. But trying to write a rule like this (assuming you have changed the relationship texts from “all instances of…” into something more useful:

the person walking at night is frightened if

InstanceCount(the ghosts in the grave) > 4

…and you will get the magic error:

Back to Basics : ForScope, For, ExistsScope and the rest 2

Think of it like this. Walking through the graveyard with your flickering torch, you can hardly see your way forward. Your “vision” of the ghosts that await is dependent on your ability, first of all, to focus on a grave ( since ghosts live in a grave) and seeing a grave means you first have to focus on a tomb. That’s the way our model is built.

Now consider the following:

Back to Basics : ForScope, For, ExistsScope and the rest 3

You can see that the rule document mirrors our nervous walk in the graveyard at night..find the tombs, then find the graves in the tombs, and peep inside each grave to look for ghosts. I can handle up to three ghosts per grave.

The basic idea should make sense – you need to give the correct “scope” to your conditions. This whole idea is all about scoping.

Once you’ve gotten your head around that concept, the next step is to be clear on what you are actually trying to achieve. The above example might be written like this instead:

Back to Basics : ForScope, For, ExistsScope and the rest 3

Did you really mean that you are only frightened if every tomb has graves, and all of the graves have more than three ghosts? Wow! I’m impressed. I’m way more likely to want to write:

Back to Basics : ForScope, For, ExistsScope and the rest 4

Or, in longer form:

Back to Basics : ForScope, For, ExistsScope and the rest 5

That’s right, some of these scoping functions have filters so that you can quickly define “all of them” or “at least one of them” kind of conditions.

So far so good. But what’s the difference between these two?

Back to Basics : ForScope, For, ExistsScope and the rest 7

Back to Basics : ForScope, For, ExistsScope and the rest 8

Aside from the obvious visual difference, they are the same. Let’s review the help text:

Exists(<relationship><condition>)

Used to refer from one entity to another entity in a relationship, when you need to determine whether any members of the target entity group need to satisfy the rule. This form is used when there is only one condition in the rule.

ExistsScope(<relationship>)

Used to refer from one entity to another entity in a relationship, when you need to determine whether any members of the target entity group need to satisfy the rule. This form is used when there are one or more conditions in the rule. This function is not supported in Microsoft Excel rules.

I’ve highlighted the difference. Using “Exists” limits you to one element after the relationship name. If you want to have more than one, you need to use ExistsScope, you can’t stick them in the “shorter” version.

Ghoulish Result 2

Don’t worry, there’s more 🙂 but that’s a good start. We’ll dig into some details next.