Custom Functions – Use Cases and Usage

It seems like ages but Custom Functions have not been with us for very long – even if the icon that displays in Oracle Policy Modeling feels like it has been with us for a very long time 😉 –

But now that the icon is here, what is it used for? Join intelligent-advisor.com on a three-part exploration of use cases, usage, suggestions and more. But let us begin right at the beginning. What is a custom function?

A custom function is broken into two parts:

  • A structure
  • A set of rules

The definition is basically the contract – what must be presented as input, and what comes out as output. There can, currently, be only one output. There can be multiple inputs.

The structure

The structure is what you build when you click on that icon above. The dialog looks like this:

In the example above, the function can be broken down into the following parts.

  • the function name is the wording you will use to call the function later, whenever you need it.
  • the function text is used in the rules that you write to describe how the function works
  • the input(s) are the information required for your function to work
  • the output is, well, the result or answer or output your function will provide.

So in my case above, the age(date of birth) function will use a date input represented in natural language as “the age function date of birth” and the result will be “the age function result”. How that works, is not defined here. This is just the skeleton of what is going to be created.

Many of you will be looking at this and thinking “this feels just like an entity – it has a unitary name “the age function” and it has attributes (“the age function date of birth” and “the age function result” – it feels like we are creating a (bizarrely named) entity. Well, here’s the thing. You’d be right.

Above is the projectDataModel.xml file from this project. In the Entities section, note there are three : “global”, “the dog” and “the age function”. Note that “the age function also has an “invisible” containment relationship (with no text associated with it, and not displayed in Oracle Policy Modeling).

Once you get that idea straight, then everything will fall into place (more or less – especially in part three of this series). But for now, just concentrate on the second stage of any function creation in Oracle Policy Modeling – the set of rules, that defines how the function will process the inputs and provide the output. In this first example, we will use Word.

Custom Function Definition Rules

The comment “Function definition” is absolutely not required. I just wrote it there to make it clearer. Look at the rule underneath. You can see several important points:

  • We provide a mechanism to populate our defined “the age function result” output.
  • We use the natural language wording (“the age function result” and “the age function date of birth”) that matches the custom function structure we created earlier.
  • We can use other native functions and our own attributes to infer the output. How we reach the output is just a matter of what rules you will use.

The result is treated an inferred attribute, so it has to be inferred from somewhere – in this case, we write a single rule. If you don’t infer the value of your output attribute, you will see an error in Oracle Policy Modeling:

Notice below how the input is also underlined in Word, just like normal attributes would be. Now we can use the function anywhere we please, to calculate the age of something. All we need is a date input. So here are two examples of me “calling” my new function.

Custom Function Rules 2

In the examples above, suppose I have two separate entities the pet and the child – now I can calculate the age of each pet or child without having to write the same rule in both entities.

Let’s take the idea of a custom function being an entity a little further. Suppose I change the rules to the following:

I have introduced a new attribute, which is neither input nor output. I’ve called it the “intermediate attribute” just for fun and for clarity. Because it contains the “custom function text” (the age function) it is considered part of the “entity”. If you look in Oracle Policy Modeling, this is what you will see:

Custom Function Attribute

See, I told you it behaved like an entity. What is interesting is that this “attribute” will show up in the decision tree of the answer. With the following rule:

And the following information in the debugger:

Custom Function Debug First Example

The only place the “intermediate attribute” shows up is when I choose “Show Decision”. This attribute belongs to the function and when debugging the function I can see it.

Custom Function Debug

Now that you have a good grounding in the basics of custom functions, in the second part we will look at a great use case and also how Excel can help build custom functions too! The official documentation is here, for reference.

Author: Richard Napier

After 8 years in case management and ERP software roles, Richard Napier joined Siebel Systems in 1999 and took up the role of managing the nascent Siebel University in Southern Europe. He subsequently was Director of Business Development and Education for InFact Group (now part of Business & Decisions) for 8 years. He now runs Intelligent Advisor IT Consulting OÜ. Owner of intelligent-advisor.com, he also is Co-Founder of the Siebel Hub.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Intelligent Advisor IT Consulting Serving Customers Worldwide
Hide picture