Welcome to the OPA Hub!


Category Archives: Examples

Calendar Black Out Dates with Control Extensions

Calendar Black Out Dates with Control Extensions

The OPA Hub Website is always happy to hear from readers and learn about the things they are doing and trying to do. In this case, this article was inspired by our reader AF, from Adelaide. The question was; how can we implement a calendar control, to allow the users to select a date – but the calendar control must be able to black-out certain dates (public holidays, non-work days). It’s the sort of thing we probably can all relate to.

The Calendar control that Oracle Policy Automation uses is a very standard JavaScript dropdown, but there is little in the way of configuration in respect of the dates shown. We can style the calendar and we can offer two different ways to enter dates (either as the traditional calendar or the three-fields-in-a-row style that some applications use).

So it comes down to what can be done with an Extension. Regular reader will remember that we have spoken about calendar controls before, on the subject of Year-Only Selection. So that Extension will be the basis of this article.

Firstly, what are the tools we might need?

  • jQuery
  • JQuery UI, especially datepicker

The datepicker widget from jQuery supports a variety of user-related events, including one called BeforeShowDay, which is where we can come in a specify which days should not be clickable. They remain in the calendar display of course.

The basic concept therefore, for this demonstration is:

  1. The user can select a date from the control. Certain days are not available.
  2. The control must handle both adding a date when the date is not currently entered, as well as when the date is already entered and the user wants to correct it (for example, going back to a previous screen in the interview.
  3. The date must of course be saved to our chosen attribute.

As always this is without any warranty or guarantee of fitness for purpose. It’s a quick demonstration that you can then add to and correct yourselves.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
 * Richard Napier The OPA Hub Website March 2019
 * Educational Example of Custom Date Control Extension
 * I will remember this is for demonstration purposes only
 */
OraclePolicyAutomation.AddExtension({
	customInput: function (control, interview) {
		if (control.getProperty("name") == "xDate") {
			return {
				mount: function (el) {
 
					var myDatePicker = document.createElement('input');
					myDatePicker.setAttribute("id", "dateselect");
					var mySessionDate = interview.getValue("dt_session");
 
 
					el.appendChild(myDatePicker);
 
 
					$('#dateselect').datepicker({
						dateFormat: "yy-mm-dd",
						onSelect: function (dateText) {
							var RecoveredDate = dateText;
 
							interview.setInputValue("dt_circ", RecoveredDate);
 
						},
						beforeShowDay: function (date) {
							var array = ["2019-03-14", "2019-03-15", "2019-03-16"]
							var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
 
							return [array.indexOf(string) == -1]
						}
					});
 
					var mySelectedDate = "";
 
					if (interview.getValue("dt_circ") == null) {
 
						$('#dateselect').datepicker("setDate", mySessionDate);
						var RecoveredDate = mySessionDate;
 
						interview.setInputValue("dt_circ", RecoveredDate);
 
 
					} else {
 
						var myPreviouslySelectedDate = new
							Date(interview.getValue("dt_circ"));
 
 
						var myPreviouslySelectedDateAsDate = new
							Date(myPreviouslySelectedDate);
 
						var myDayPrefix = "";
						var myMonthPrefix = "";
						if (myPreviouslySelectedDateAsDate.getDate() < 10) {
							myDayPrefix = "0"
						}
						if (myPreviouslySelectedDateAsDate.getMonth() < 10) {
							myMonthPrefix = "0"
						}
						var myConvertedYear = myPreviouslySelectedDateAsDate.getFullYear();
						var myConvertedMonth = myPreviouslySelectedDateAsDate.getMonth() + 1;
						var myConvertedDay = myPreviouslySelectedDateAsDate.getDate();
						var myPreviouslySelectedDateOnly =
							myConvertedYear + "-" + myMonthPrefix + (myConvertedMonth) + "-" + myDayPrefix + myConvertedDay;
 
 
						mySelectedDate = myPreviouslySelectedDateOnly;
 
 
						$('#dateselect').datepicker("setDate", mySelectedDate);
 
 
						var RecoveredDate = $('#dateselect').datepicker("getDate");
 
						interview.setInputValue("dt_circ", new Date(RecoveredDate));
					}
				},
				update: function (el) {},
				unmount: function (el) {
					var RecoveredDate = $('#dateselect').datepicker("getDate");
 
					interview.setInputValue("dt_circ", new Date(RecoveredDate));
 
					var myPicker = $('#dateselect');
					myPicker.remove();
 
 
				}
			}
		}
	}
});

Calendar Black Out Dates with Control Extensions – About the Code

The first part of the Mount is basically setting up the jQuery datepicker to be able to hide some days. We also set the date format to the international YYYY-MM-DD that we all know. Of course a more sophisticated approach would check the region and apply the correct format.

Line 22 Sets up the Select Event and Line 29 the BeforeShowDay  Event.

We attempt to grab the value of our user-entered date (dt_circ) and place it in the date control. If that is unknown or null, then we will default to the current date.

When the user selects a valid date, we will of course copy it into the attribute again.
Finally, when the Unmount fires, we will clean up.

The End Result

 

In a later post we will look at using an entity to store the blackout dates. Stay tuned! For the time being the Project is in the OPA Hub Shop.

OPA 10 – Missing “It is currently known”

Hi There!


This content is accessible only to logged in users of the OPA Hub Website.

To Register takes only 10 seconds and uses LinkedIn for authentication.

Once registered you can change your OPA Hub password and manage it independently of LinkedIn.

We recommend you keep different passwords for all your sites.

To register, click the Log in link in the menu at the top of your page.

Thanks, the OPA Hub Website.

Getting Started With Oracle Policy Automation Book Now Available

Hi There!


This content is accessible only to logged in users of the OPA Hub Website.

To Register takes only 10 seconds and uses LinkedIn for authentication.

Once registered you can change your OPA Hub password and manage it independently of LinkedIn.

We recommend you keep different passwords for all your sites.

To register, click the Log in link in the menu at the top of your page.

Thanks, the OPA Hub Website.

OPA 12 – It’s all in the Natural Language Text

OPA 12 – It’s all in the Natural Language Text

I suppose this article could have just as easily been about Oracle Policy Modelling 10 as well. But since I was teaching version 12 I decided to use it for the screenshots. I also was teaching a group of French students so the examples are in French and English. Ultimately the same challenges occur no matter what language you are using, provided that language uses definite articles in the same way. Natural Language is not always natural.

Consider the following :

An Entity called “the contact” or “l’interlocuteur”.

OPA 12 - Contact Entity Natural Language

As you can see, the Relationship Text has been changed to “tous les interlocuteurs” or “all the contacts” instead of the standard “all instances of the contact” or “toutes les instances de l’interlocuteur”. I see a lot of students working in this way. However there are some side effects of using this kind of wording…

Let’s imagine that every contact has a telephone number, and we want to check that the telephone number has been entered. The first part is fine, we can write the following rule to assign a Boolean value depending on whether we have a telephone number or not, and let’s build a rule that uses Entity Quantifiers to look at the different contacts.

When is Natural Language really Natural?OPA 12 - For Each of the Contacts Natural Language

In English we would have something like

OPA For Each Contact in English Natural Language

We are using the longest version of the “natural language” Function “ForAll“. And it looks a bit, well, long-winded. So we might try one of the other versions:

OPA 12 - For Each of the Contacts EN Part Two Natural Language

That’s even worse. In French too it’s almost comical …

OPA 12 - For Each of the Contacts FR Part Two Natural Language

That’s even worse. So let us try a different approach. We decide to modify the Relationship Text and remove the “all” to leave only “the contacts” or “les interlocuteurs”. So now our rules look a bit more “natural language” when we use the ForAll function in it’s long form.

OPA 12 - For Each of the Contacts EN Part Three Natural Language

OPA 12 - For Each of the Contacts FR Part Three Natural Language

Of course I can hear people saying, why don’t you just use ForAll or PourTous – that is, the terse or short version of the function? It does of course depend on your environment, but a non-technical user is going to be far more comfortable using a natural language-based solution.

Have fun improving your text, until next time

Rich@rd

OPA 12 – Whatever happened to…

Hi There!


This content is accessible only to logged in users of the OPA Hub Website.

To Register takes only 10 seconds and uses LinkedIn for authentication.

Once registered you can change your OPA Hub password and manage it independently of LinkedIn.

We recommend you keep different passwords for all your sites.

To register, click the Log in link in the menu at the top of your page.

Thanks, the OPA Hub Website.

Oracle Policy Automation Quiz Question Two – AND

Oracle Policy Automation Quiz Question Two – AND

Many of you probably saw this one coming after the first Quiz Question. Well, here it is.

I am sharing with you all another question I often ask during the Oracle Policy Automation training to my students. I ask it for three main reasons

  1. It helps to understand the Engine and the inferencing process
  2. It’s fun and a great way to challenge yourself
  3. It is good preparation for the sort of question that you might get in the Certification examination.

This is quite an easy one, and most people will get it right away

Something to think about

The Oracle Policy Automation  Certification, as it is sometimes called (incorrectly) is in fact actually called “Oracle Policy Automation 10 Rule Developer Essentials 1Z0-534” and as such is focuses for the major part on rule development. The exam study guide seems to have gone 404 on the Oracle University Website but the corresponding guide in the partner website is still useful.

Update in 2016

Of course, since this article was originally written for Version 10, things have changed – not least with the arrival of a Cloud-focused certification examination that, at time of writing in December 2016, was undergoing beta testing. Although there are currently no self-testing or exam guides yet available, I hope this is just a matter of time.

OPA – Entities Adventures #10 Temporal Reasoning

Temporal Workshop

And so we come to the tenth, and final (for the time being) post in this hopefully useful and entertaining series for learners of Oracle Policy Automation. In this episode we will discuss the concept of Temporal Reasoning and apply it to the Workshop example we have been using since the beginning of the series.

What is this temporal stuff?

To give you a simple example, our Workshop has a variety of elements to it that change over time :-

  • Cars in the Workshop
  • Mechanics
  • Car Storage Cost

And of course, these pieces of data might need to be analysed and calculated over time. This is a common thing in business of course. Generally software tries to handle this by having “data points” – snapshots of data – but usually they are not very good at handling “periods of time” – where you don’t have data for each day or other time period  but you expect to have to calculate as if you did. Say for example you have a person who receives money from the state. They receive it on a weekly basis. We need to calculate from their date of first receipt, until today. So we need to be able to “span the time period” and calculate the figures. And that is pretty cool.

How does it work in Policy Automation? – an example

In Policy Automation, we need first to understand how the data is entered. Let’s focus on the storage costs – cars that are left in the Workshop are charged at a daily rate to the customer, for storage, once they are left more than 3 days. In addition, the storage charge is a percentage of the value of the vehicle. Finally, storage of more than 10 days gets a higher rate.

So let us work up an example. Assume two cars being worked on in the Workshop. One of the them arrives in the Workshop on September 11, the other on September 1. Today is September 17. So how much storage should we charge? To make matters more realistic, we can say that the first ten days are charged at 9% of the car’s residual value, the next ten days at 11%, and beyond that a punitive 15% since the car has really been here too long.

OPA - Daily Cost of Storage Temporal Example

In the above example we introduce some new Attributes (the cost of the car’s storage and the date of the car’s arrival) respectively currency and date types, and the function TemporalBefore().

From the Function Reference we see that TemporalBefore (date) is explained thus:

Returns a Boolean attribute that varies over time and is true before a date and false on and afterwards.

So essentially our cost will be calculated using the car’s residual value * 0.09 for as long as TemporalBefore(AddDays(the date of the car’s arrival, 10)) is TRUE.

There are other versions of this function to handle things like “on or before” or similar calculations for “after” or “on or after” dates.

Visualising the data in the debugger makes it clearer how this is working. Don’t forget to right-click the cost of the car’s storage in the Debugger window and choose Show in Temporal Visualisation.

Now we can see the cost of storage incurred based on the car residual value and the arrival date of the car, according to the different values over time. But perhaps you didn’t see what you were expecting – the actual total cost as of today. So let us introduce this into the mix:-

In the following screenshot, note we have added new “total cost” and “current daily cost” Attributes.

As a demonstration we are using the ValueAt() function to get the current value charged today (according to our table of values).

We are also using the IntervalDailySum(start, end, value) to calculate the total amount payable to date.

OPA - Car Storage Cost Rates and Total Temporal Function Example

Now that we have the total cost of the storage, we can go ahead and work out if the car storage has exceeded the residual value of the car.

And so we come to the end of this 10 part series, designed to give you some more fun examples of working with Entities. For those of you who are reading this after taking the OPA Essentials Class with me, I hope you enjoyed them.

What Next?

For the next series of posts we will be looking at teasing questions that might help you prepare for the certification. After that, get ready for more function examples and fun with Oracle Policy Automation.

Rich@rd

OPA – Entities Adventures #9 Testing using What If

What If?

Back in the Workshop now with all our different chapters, things are getting more and more complex. But one feature of the Policy Modelling user interface that we do not cover in the standard training course can come to our rescue. I’m talking about the What If Analysis feature. This is based on Microsoft Excel and reasonably easy to explain to a non-technical user, so it can be leverage to prove that a use case has been understood, or as a tool for working with the business to understand each other.

The use of this functionality starts with a new file in your Project:

OPA - What If Initial View

As you will have seen, the first time you open it can be quite a disappointment. What you need to do is proceed first to an initial setup, then to some data entry. Begin by clicking the Add Worksheet button on the top left, and adding Worksheets for any Entities that you intend to work with. It will end up looking like something like this, using our Workshop as the example:-

OPA - What if Added Entities

Now we proceed to each of the Worksheets and click the Add Column button. We add any attribute we intend to enter data for, as well as any inferred attributes we want to see the results for after our analysis. Notice the color coding for the columns to make it easy to see which are conditions and which are conclusions.

OPA - What If Added Columns

As in the example above, the colors indicate:

  1. Black is an identifier for the Entity on this tab. In our case here, the customer.
  2. Blur is an identifier for another Entity in the Rulebase. In this case, the Global Entity as well as the customer’s car.
  3. Green is a base attribute
  4. Brown is an inferred attribute

Entering the correct data can be a little daunting, since in many cases you will need to remember for example that car #1 is the Fiat, and mechanic #1 is Bob and so on. But you quickly get the hang of it. Common traps include

  • failing to compile your documents before clicking the Analyze button
  • failing to add information to the Global tab.

Remember that all your Entities will fold up into the parent Global, so there will need to a record on the Global tab. Go ahead and click the Analyze button and see what happens. For the purposes of demonstration, enter one car, one mechanic, one customer and one set of wheel-covers. For inspiration here is a carousel of What If Analysis Worksheets with some example data, and the results (ie, these screenshots were taken after clicking the Analyze button.

Hopefully you will see from the carousel that the inferred attributes have been updated following the Analyze button being clicked. Of course why stop there with only one car and one customer. Not only can we enter many of them for our Global Case #1, we can create many Global Cases, and associate our Entity Instances with a different Global Case.

Furthermore once you have built your complex What If scenario, you can export it to a Policy Modelling Test Case file for further testing.

Have fun, until next time

Rich@rd

OPA – Entities Adventures #6 Cross Entity Reasoning

Hi There!


This content is accessible only to logged in users of the OPA Hub Website.

To Register takes only 10 seconds and uses LinkedIn for authentication.

Once registered you can change your OPA Hub password and manage it independently of LinkedIn.

We recommend you keep different passwords for all your sites.

To register, click the Log in link in the menu at the top of your page.

Thanks, the OPA Hub Website.

OPA – Dynamic Visibility

Dynamic Visibility

In certain situations, it is necessary to display or hide elements of the Policy Automation Interview. The easiest way to obtain this OPA – dynamic visibility is to create rules, whose conclusion can act as a basis for the Visibility. For example, if the color is red, then show the size question. And inversely – If the color is not red, then do not show the size question.

Such a method is simple and the result is attractive to the End User. It can be implemented with the Question displayed during the Interview, referencing the rule you have created. In the following screenshot you can see an example with the relevant Boolean Attribute referenced in the Attribute Input Control properties.

Question-with-Visibility-Rule

Mandatory and Read-Only

A similar approach can be taken to render a Question mandatory, or when a Question should have it’s Value displayed as read-only. The existence of a Boolean Attribute to reflect your business logic is once again a pre-requisite, but the process of aligning it with an Input Control is the same.

Mandatory-Question-using-Dynamic-Boolean

 

List of Values – Dynamic Values

A further area where such dynamic visibility can be useful to make the end user experience more enjoyable, is in the area of Lists of Values. If a Attribute has a List of values, some Values may need to be hidden in certain circumstances. The same dynamic effect can be achieved by associating each Value with a Boolean Attribute in much the same way as the previous examples.

 

Visibility-of-Pick-List-Value

Better for the End User

Simple logic such as this can increase the engagement of an End User – after all, the easier it is to complete something with the minimum of irrelevant questions or data the more likely you are to see happy End Users. Until next time, see you soon.

Rich@ard