Welcome to the OPA Hub!

Archives

Oracle Policy Automation Workshop – Sept 24-27 North America (FINALIZED)

Oracle Policy Automation Workshop – Sept 24-27 North America (FINALIZED)

Things are now starting to fall into place with the Oracle Policy Modelling and Oracle Policy Automation Workshop that I mentioned in an earlier post. So first of all, you can join the class from Ottawa, ON, Edison, NJ, King of Prussia, PA and iMVP (live virtual). All are of course welcome. The main base will be Ottawa, ON. If you choose one of the locations above you will be in a high-tech training center with lots of cameras and things – unless you choose live virtual of course in which case you could be in your office or your living room eating donuts and wearing pyjamas.

The last few events we have organized have been a great success and well-received by the students, and we are very thankful for that. We think that the combination of Oracle Policy Automation, Oracle Siebel CRM and Oracle Sales / Oracle Service Cloud experience in one trainer generally means people can ask any question they can think of and we can help them find an answer!

The course outline is now completely ready and you can get all the details by reading the details on the OPA Hub Website Calendar here or directly on the training venue website here. If you are not on the North America East Coast, then please get in touch as we are gradually working on our calendar for West Coast, and Europe / Asia Pacific.

We look forward to seeing you and your colleagues on this or one of our future Oracle Policy Modelling and Oracle Policy Automation Workshops somewhere in the world. If Siebel is more your thing, you will be interested to know we have just launched our Siebel 2018 workshops, over on the Siebel Hub Website – find out more on their calendar.

 

Interviews, Languages and URL Arguments

Interviews, Languages and URL Arguments

The other day I was part of a discussion regarding the launch of Interviews. A couple of questions arose that formed the basis for an interesting discussion.

The details are not really important, but the basic thread was

  1. How can we be sure to launch an Interview in a specific language?
  2. How can we pass information into an Interview in respect of the language of the user?

Of course these two questions can be synthesised further to :

  1. What are the ways to find out what language the user is using?
  2. How do I pass seed information in the URL?

What language are you using?

You might be tempted to try all the different ways to do this JavaScript,  that you might find people talking about on Stack Exchange . There is basically no reliable method to detect the language of the user. Perhaps I have set the language of my Browser to German, but my Windows is in French. So which is my language? Perhaps I am in France so you can geolocate me, but I am actually a Finnish speaker? Perhaps I am in a country where geolocation is not usable or reliable? And so on…

In Oracle Siebel CRM, we have GetProfileAttr(“org.country”) available to us, for example through the JavaScript API, which will give us the Country in which we are supposed to be based. In Oracle Service Cloud we have the Country and Language in Contacts and no doubt we have other options in other applications. That will probably be the most reliable method, since it is not dependent on what the end user has done to their computer. Fine.

Suppose we want to pass that information to Oracle Policy Automation?

Let’s get down to basics.

In the image above :

  1. Whenever a Project is launched from a button, we can add the correct locale information to the URL to ensure it is launched correctly. So in the silly example above, there are two buttons. One uses”fr-FR”, the other “en-US”.
  2. This information is appended to the root URL via the ClickMe (mypath)  function.

In the third bullet, is illustrated the other part of the question. How can we pass this information into Oracle Policy Automation. using the JavaScript object we pass seedData={} into our Project. And in the seed data you can see our information being passed.

In the Interview itself, we can recover the information using the URL Argument feature in our mapped Project:

Of course the attribute can now be used in our Interview or our rules, should we need to display or leverage this information:

This little set of examples does illustrate that Oracle Policy Modelling could really do with some functions to at least allow the rule designer to capture the locale of the user (which language did they choose to view my interview in, so to speak).

Oracle Policy Automation Workshop – Sept 24-27 North America

Oracle Policy Automation Workshop – Sept 24-27 North America

I’m pleased to let you know we are going to be running another Oracle Policy Automation Workshop in September. Thanks to the wonderful Multimedia Video Presence technology, although we plan to run it in either Toronto or Ottawa (depending on the balance of attendees), you can also join from a number of locations in Canada and the United States!

Get in touch using the Contact form or LinkedIn and we can share with you the complete list of locations and the pricing for this event.

Duration and Content

Oracle Policy Automation WorkshopThis is a four day hands-on Workshop which covers all you need to know to be productive in Oracle Policy Modelling and Oracle Policy Automation. The workshop content is available for download on our Oracle Policy Automation Workshop page, and covers all the practical aspects of Oracle Policy Automation and Modelling (including teamwork, collaboration, Hub management and interfaces).

Of course, these workshops are also driven to some extent by the attendees, so you are welcome to ask anything about Oracle Policy Automation, Oracle Siebel CRM, Oracle Service Cloud or Oracle Sales Cloud if we can fit it in, we can discuss

it.

Materials

As well as the PDF slide content, everyone who attends will get a copy of Getting Started with Oracle Policy Automation.

This workshop is one in a set of workshops that we deliver all year round:

We also, as co-founders of the Siebel Hub website, design and deliver a variety of Siebel-specific workshops which you can find out about over there.

Delivery Language

This particular Oracle Policy Automation Workshop will be delivered in the English language. If you are looking for la version française, parlons-en!

List of Values, Display Values and Translations in Oracle Policy Automation

List of Values, Display Values and Translations  in Oracle Policy Automation

A common List of Values question that comes up is the following:

“How are list of values handled in Oracle Policy Automation, when I have more than one language? What gets put into the database?”

Of course, by “database” I mean whatever platform you are using to save the response from Oracle Policy Automation  : Oracle Sales Cloud, Oracle Service Cloud, Oracle Siebel CRM, Salesforce or any other.  For the record, the exact behaviour of your Connector will depend on how it has been programmed,but if it is doing what it should be doing, then the following information will apply.

The question that comes up is actually, to be fair, usually more detailed : people want to know the behaviour of the list of values both when it is created as a Screen element (single-use) or as a Value List (multi-use) and when there is more than one language involved. Well, fear not because the video below will answer all of those questions I hope, in a friendly and easy to follow way.

Imagine you have a Project in Oracle Policy Automation that includes an attribute of type Text, with a drop-down list to display values for the user.

  • What if there are multiple languages?
  • What if you use Screen-based Values?
  • What if you add Display Values as well as Values?
  • What if you migrate to Project Value Lists?
  • What editing might you have to do in your Translation file(s)?
  • What gets into the database?

List of ValuesAll these points will be covered in the video. Hopefully there will be no surprises in the video itself,  but it will be useful to see it in action and get confirmation of what you think might happen. And as mentioned previously, a big thanks to our OPA Hub Website Sponsors Mantis Solutions, makers of the OPA DB Connector, whose assistance made this video way easier to create and much faster to implement. If you are interested in Mantis OPA DB Connector, please reach out here.

 

Until the next post, I hope you are (at least those of you in the Northern Hemisphere) all having a pleasant Summer.

Temporal Reasoning in Oracle Policy Automation #3 : Time Travel

Temporal Reasoning in Oracle Policy Automation #3 : Time Travel

Following on from the previous parts of this series (which looked at the basics of Temporal Reasoning and Temporal Functions), this third post continues our investigation of temporal calculations in general, this time with a focus on another series of functions and concepts, that are closely involved in using temporal data to calculate numeric or currency amounts.

In the previous chapter of this series, we saw how the functions such as WhenLast() give us the capability to investigate the temporal data at our disposal and find out what was happening on a given date, according to the information you have.

How much would I have saved if?

Taking the example from the previous post and turning it upside-down, we can use Oracle Policy Automation to find out how much money would could save if we had been good and put money in our bank account. There are two principles here :

  1. We need to know how much money we are willing to save
  2. We need to know how regularly we are willing to put it in the bank account.

In real life, you might say to me:

“Richard, if I saved $1 a day, every day, since the beginning of the year : – how much money would I have now?”

In Oracle Policy Automation we can ask the same sort of question.  And of course, get the answer. The key points here are the daily sum, and the date range. In a sense, you are creating your own change points daily in order to calculate the result.

Again, it probably will not surprise you to know that there are a whole raft of Temporal Reasoning functions that work in similar ways to this one.  Suppose you admit to me, that you cannot save money on the weekend, because you like to go out and spend it instead.

“Richard, if I saved $1 a day every week day since the beginning of the year:- how much money would I have now?”

Your familiarity with Oracle Policy Automation probably helps you guess that the function IntervalDailySumIf exists, so you decide to use it, as in the example below.

At first glance, this looks alright. But it really isn’t. The problem is a common one when imagining Temporal Reasoning. The Boolean attribute “you are not spending the money instead” is not going to be very useful, since it is not a temporal value. You get to set it once in the Debugger – not for every weekend:

So mixing a Boolean and our temporal calculation produces a not very useful result. But thankfully Oracle Policy Automation can help. It includes a function to let us know if a day is a weekday or not, based on a range of dates. It returns a set of values that illustrate the changes. It is another example of a temporal reasoning function.

In the above case, the day is a weekday returns a set of change points showing you the way:

 

In the next episode of this series, we will look at the display of Temporal data to the end user, in a way that is easily readable.

Have fun

OPA Hub - REST API Generate Class

Deployment REST API : Uploading Zip Files #1

Deployment REST API : Uploading Zip Files

Following on from a post in the not too distant past, where we looked sideways at the Deployment REST API and the ability to download the Zip File of a deployment snapshot programatically, this new post answers a request from one of our readers regarding the “other side of the coin” ; specifically how to take a Zip File that needs to be uploaded into an Oracle Policy Automation Hub, and get the file to load up into the Deployments, using code. I must thank the commenter on the previous article for sharing his question, since it is one that comes up quite a lot and this is a good opportunity to hopefully show how you might do it.

The starting point of the process is that you have previously downloaded a snapshot file from a Deployments page of your Hub in environment A, and you now want to copy it across to environment B.

With your Zip File in hand, what can you do to automate this process? Of course, you turn your attention to the REST API and the deployment REST API in particular. Find the page that matches your version and let’s have a look.

{
    "name": "Example",
    "description": "Description of Example Project",
    "compatibilityMode": "latest",
    "services":
    [
        "interview",
        "webservice",
        "mobile",
        "javaScriptSessions"
    ],
    "collections":
    [
        "Default Collection"
    ],
    "versions":
    {
        "items":
        [
            {
                "description": "The initial version",
                "activeVersionFlag": true,
                "snapshot":
                {
                    "base64": "...base64 value..."
                }
            }
        ]
    }
}

How to get a class out of that? If only I could find a way to turn that into something easy to use in Visual Studio, I could create my own…wait a minute! Enter JSONUtils – the perfect site for converting JSON into C# or Visual Basic Classes.

OPA Hub - Deployment REST API Generate Class

How easy is that?

  1. Choose your language
  2. Give your new Class a name
  3. Paste the sample from the Oracle REST API documentation
  4. Press this button
  5. There’s your class, ready to use in your Visual Studio project.

Armed with this, we are ready to continue our research. We also need to be able to POST our request to the Oracle Policy Automation Hub. Thankfully somebody else has already asked about POSTing JSON to a specific URL millions of times, and there is a good starter function on Stack Exchange. At the bottom of that question is a great example.

Checklist – REST API Deployment

We can step back a moment and review a checklist

  1. We have Class to model our request
  2. We have a function to use HTTPWebRequest send things to the Oracle Policy Automation Hub
  3. We have an integration user and password, and the url of the Oracle Policy Automation Hub

So what else do we need? We need to be able to turn the Zip File into an encoded string as per the example given on the Oracle Policy Automation website : something like this:

 

Public Function ConvertFileToBase64(ByVal fileName As String) As String
        Return Convert.ToBase64String(System.IO.File.ReadAllBytes(fileName))
    End Function

In the second part of this post, we will put it all together and see the result!

OPA Quizzes : Helping you learn Oracle Policy Automation

OPA Quizzes : Helping you learn Oracle Policy Automation

We are always looking for ways to help you learn Oracle Policy Automation, so that’s why  we came up with our OPA Quizzes.

Whether it is for your next interview, or even as a preparation for your upcoming certification examination if you are planning on taking one, we hope that our range of free quizzes can help you get ready. If you are not familiar with the examination find out about it here  OPA Quizzes

In any case we hope that you enjoy them and have fun with them. Share them with your friends as you learn Oracle Policy Automation.

And while you are at it, reward yourself with a mug from the Shop. Maybe we will give away a few mugs at the end of the year to the Leaderboard Winners.

Yes, that’s a nice idea and this time we are organised enough to do it.

At the following page you will find all the OPA Quizzes and the links to the OPA Quiz Leaderboards. Check your results against the top scores and enjoy the stress of answering questions against the clock.

We recently began the process of building another’s two sets of questions so stay tuned and watch out for them in the coming weeks. In the meantime keeping smiling and have a good day!

What’s New in Oracle Policy Automation 18B #2 Relationship Control Extensions

What’s New in Oracle Policy Automation 18B #2

The main thrust of this post first came into my head when I was writing one of the recent Back to Basics posts about Relationships. And as if by magic, Oracle Policy Automation went ahead and improved the product with something I felt was lacking. I should ruminate more often, perhaps they have telepathic powers over there. So in this post, What’s New in Oracle Policy Automation 18B #2, we are going to look at the new feature of the Control Extensions : the ability to customise the Relationship experience.

What’s New in Oracle Policy Automation 18B #2

The relationship above is a good example. In the course of a prototype, I designed the car and the passenger entities for a car-sharing enterprise. A car can have many potential passengers. For each journey, however, your passenger can only be in one car at a time. And yes, I understand that I could build a many-to-many and intersection the car and passengers or infer the current passengers or what have you, but this is just an example.

What’s New in Oracle Policy Automation 18B #2

So in the above example, you can see that I am in the process of selecting the passengers for each car. Putting aside the discussion about how best to model the data, there is a challenge here. The checkbox (which is the only display offered) is fine, but due to the lack of dynamism (?) in the display, the choices remain static. I mean by that you are able to choose an incoherent selection, with the same passenger being in multiple cars.

Of course, when you do so, the engine (correctly) gives you an error and you must correct your data entry. But what if we did it another way?

The core of this is the fact that now, in Oracle Policy Automation 18B, you can use the following in your Extensions:

control.getControlType() – which now will return “OneToMany” or “ManyToMany” and so forth for relationship controls. So your code could adapt the User Experience based on the cardinality.

control.getOptions() – returns an array of the different choices for the user ( the passengers in my case above). So you can retrieve the list of choices.

To help manage this kind of extension, control.getValue() returns an array of the selected values for your relationship (the instances that have been selected). So you can examine the selected values.

Let’s look at this code. It is, as always provided for educational and entertainment purposes (indeed, many will find my stream of consciousness code amusing). It is also available on the OPA Hub Website Shop page as a free PDF download. So let’s see What’s New in Oracle Policy Automation 18B #2 : Relationship Controls with an example.

 

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
/*
(c) 2018 Richard Napier The OPA Hub Website May 2018
Educational Example of Relationship Input Controls
I will remember this is for demonstration and educational purposes only
 */
 
OraclePolicyAutomation.AddExtension({
	customInput: function (control, interview) {
		if (control.getProperty("name") == "xPassengerSelect") {
			return {
				mount: function (el) {
					//console.log("Control " + control.getProperty("name") + " is a " + control.getDataType() + ", originally a " + control.getControlType());
					var myValues = [];
					//Previous values
					myValues = control.getValue();
					var myOptions = control.getOptions();
					//console.log("Obtained list of instances for control " + control.id);
					var myDropDown = document.createElement('select');
					myDropDown.setAttribute('id', control.instance.toString());
					myDropDown.setAttribute('data-instance', control.instance.toString());
					myDropDown.setAttribute('data-entity', control.entity.toString());
					myDropDown.setAttribute('multiple', 'true');
					for (j = 0; j < myOptions.length; j++) {
						var myoption = new Option(myOptions[j].text, myOptions[j].value)
							myoption.setAttribute("data-instance", control.instance.toString());
						myoption.setAttribute("data-entity", control.entity.toString());
						myDropDown.options.add(myoption)
						//console.log("Added list option " + myOptions[j].text);
					}
					for (i = 0; i < myDropDown.length; i++) {
						currentOption = myDropDown[i];
 
						if (myValues.indexOf(currentOption.value) != -1) {
							$("select [data-instance='" + myDropDown.getAttribute('data-instance') + "']").filter("option[value='" + currentOption.value + "']").attr("selected", "selected");
						}
 
					}
					$(myDropDown).change(function () {
 
						//New Values Selected
 
						for (i = 0; i < myDropDown.length; i++) {
							currentOption = myDropDown[i];
 
							if (currentOption.selected == true) {
								myValues.push(currentOption.value);
 
								//Disable All Values Matching Selected in other instances
								$("select [data-instance!='" + myDropDown.getAttribute('data-instance') + "']").filter("option[value='" + currentOption.value + "']").attr("disabled", "true")
 
							} 
 
						}
					});
					var deselectbutton = document.createElement("button");
					deselectbutton.setAttribute("type", "button");
					deselectbutton.setAttribute('data-instance', control.instance.toString());
					var deselectbuttontext = document.createTextNode("Deselect All");
					deselectbutton.appendChild(deselectbuttontext);
 
					el.appendChild(myDropDown);
					$(myDropDown).after(deselectbutton);
 
					$(deselectbutton).click(
 
						function () {
						$("select [data-instance='" + this.getAttribute('data-instance') + "']").filter(":selected").prop("selected", false);
						control.setValue("");
							$("select [data-instance!='" + this.getAttribute('data-instance') + "']").attr("disabled", false);
					});
 
					for (i = 0; i < myDropDown.length; i++) {
						currentOption = myDropDown[i];
 
						if (myValues.indexOf(currentOption.value) != -1) {
							$("select [data-instance='" + myDropDown.getAttribute('data-instance') + "']").filter("option[value='" + currentOption.value + "']").attr("selected", "selected")
 
						}
 
					}
				},
				update: function (el) {},
				unmount: function (el) {}
			}
		}
	}
});

So what are we looking at. There are probably four key areas in this rough prototype.

Lines 18 to 27 build a multiple-select drop-down instead of the check-boxes. Using HTML 5 data attributes, each option and each drop-down (there will be  drop-downs, one for each of the car ) is tagged with the instance name and the entity name. This is useful if you intend to have a page with lots of entity-related things on it , and it was useful in the Entity Collect example from a few weeks ago as well.

Lines  29 to 33 look through the existing values of the Control (maybe the user has already been working on this page, and has now come back to it for further editing) and selects programatically all those values that were chosen previously. Otherwise when you click the Next button and then the Previous button, you will no longer “see” your selections even though they actually have been selected.

Lines 38 to 58 handle the Change event if the user selects other items in the multi-select, and ensures that the corresponding items are deactivated in the other drop-downs.

Lines 58 to 78 create the Deselect All button for each drop-down, which removes all the selected items both from the drop-down and from the underlying control values, and re-enables the values in the other drop-downs.

Once again, I state for the record that this was just a “stream of consciousness” which became a bare-bones prototype. There are lots of holes in the code, and lots of repetition because I just wrote it in a single shot. So you have been warned.

It does, however, demonstrate the new functionality, so our post title What’s New in Oracle Policy Automation 18B #2 is fulfilled. This is something you could not really do in previous versions.


Have fun!

What’s New in Oracle Policy Automation 18B #1

What’s New in Oracle Policy Automation 18B #1

The team that creates and updates Oracle Policy Automation have once again been very busy indeed, and the latest and greatest release can be downloaded from the usual Oracle Technology Network pages, and the link to the documentation follows the usual schema, just with the new 18B tag in it. So What’s New in Oracle Policy Automation 18B ?

In this first post in a short series, we are going to be looking at the new features of this release, and there certainly are some crackingly good ones. Let’s get started with the integration-related changes and what they mean for Oracle Policy Automation 18B:

  • A new Integration Cloud Service OPA assessment Adapter

What's New in Oracle Policy Automation 18B ICS

A massively important piece of the integration architecture for Oracle Policy Automation just got a whole lot better. An Oracle Policy Automation assessment can now be called as a step in your integration Workflow built on Oracle Integration Cloud Service. The Oracle Policy Automation assessment adapter has been available as a pre-release version but by the time you read this, or shortly afterwards, it should be available from the list of Adapters on the Oracle Integration Cloud Service site.

  • Embeddable JavaScript Models

An embedded JavaScript model is essentially a completely self-contained rulebase which can run, therefore, in a disconnected scenario. This will be a game-changer for Internet of Things devices, as well as situations where you need to have lightweight, client-side rule execution. This feature does not support Interviews, and is license-based.

  • Inline Customer Portal interview widget

Service Cloud customers can now take advantage of the new IFRAMEless integration capability that we enjoy with Siebel CRM already.

  • New REST API Batch Assessment Licensing Options

The Batch Assess REST API can now be called if you are licensed for Oracle RightNow Universal Policy Automation Tier 3 sessions, even if you are not also licensed for Oracle Policy Automation Enterprise Assessment API. For more information on the licensing and restrictions contact your Oracle representative.

  • Cookie-less interviews

A real boon for Safari users (but not only Safari) : Embedded Interviews no longer require a Browser cookie, which potentially could stop the Interview from functioning in certain environments. CORS still applies for resources shared across domains but basic embedding should now be possible whatever the browser security settings.

  • New Inline API Interview

The new API is OraclePolicyAutomationInterview and it uses the same methods as in previous versions (StartInterview, ResumeInterview, BatchStartOrResume). This new API version enforces all interview element styles. Styles won’t inherit from the parent stylesheet, and interview extensions can be used to modify interview appearance.  Awesome news for customers looking to render a a transparent experience to their users.

  • Relationship Control Customization

In the second part of our What’s New in Oracle Policy Automation 18B post series, we will look at the new Relationship Control extension capability which I was wishing for only a few weeks ago!

Custom Entity Collect Extension in Oracle Policy Automation #2

Custom Entity Collect Extension in Oracle Policy Automation

In this second part of the series, we continue to investigate building a Custom Entity Collect Extension in Oracle Policy Automation, and complete the basic example of a working collector. The code is once again focused on pointing out big ideas, traps, suggestions and the details are left to you, dear readers. Everything you see here is free and you can use it anywhere but it is for educational and entertainment purposes only. The PDF version of the code is available in the OPA Hub Shop for free.

Building the User Interface

The next big chunk of code is all about continuing the work begun previously, specifically building the User Interface by adding input boxes and other User Interface elements to the page. We switch according to data type, and as before we add a number of valuable extra HTML attributes to our elements.

 

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
//GET KEY INFORMATION
									var theinstancename = myrecords[i][j].instance.toString();
									var theentityname = myrecords[i][j].entity.toString();
									var theattributename = myrecords[i][j]._source.config.attributeId;
 
									var myname = myrecords[i][j].id.toString();
 
									attrInput.setAttribute('id', myId);
									attrInput.setAttribute('data-entityname', theentityname);
									attrInput.setAttribute('data-instancename', theinstancename);
									attrInput.setAttribute('data-attributename', theattributename);
									attrInput.setAttribute('data-rownumber', j.toString());
									attrInput.setAttribute('name', myname);
 
									// CONVERT ATTRIBUTES OBJECT TO ARRAY
									var myAttributeObject = myrecords[i][j]._source.screen.clientState[theentityname];
									myAttributeObject = myAttributeObject[theinstancename];
									var myAttributeArray = $.map(myAttributeObject, function (value, index) {
											return [value];
										});
 
									//DISPLAY THE CORRECT VALUE IN THE INPUT BOX
 
									switch (myattributedatatype) {
									case "boolean":
										var response;
										switch (myAttributeArray[j].toString()) {
 
										case "true":
											response = true;
											break;
										default:
											response = false;
										}
										attrInput.checked = response;
										rowdiv.appendChild(attrLabel);
										$(attrLabel).after(attrInput);
 
										break;
 
									case "number":
										attrInput.setAttribute('value', Number(myAttributeArray[j]));
										rowdiv.appendChild(attrLabel);
										$(attrLabel).after(attrInput);
										break;
 
									case "text":
										attrInput.setAttribute('value', myAttributeArray[j].toString());
										rowdiv.appendChild(attrLabel);
										$(attrLabel).after(attrInput);
										break;
									case "date":
										if ($(attrInput).attr("data-datepicker") === 'true') {
											$(attrInput).datepicker();
											$(attrInput).datepicker("option", "dateFormat", "yy-mm-dd");
											$(attrInput).val( myAttributeArray[j]);
											rowdiv.appendChild(attrLabel);
											$(attrLabel).after(attrInput);
 
 
 
										}
										break;
 
									}

Whoa, easy there! So what is all of that about? The different kinds of data (Boolean, text, numbers, dates) need to be handled slightly differently, to display correctly.

Error Display

What happens if the Interview cannot continue (note that this example Entity Collect only handles errors on navigate, the default for Oracle Policy Automation Interviews) because of an issue? The user needs to know what they have done wrong, so they can correct it. Thankfully the errors are available to us (if they exist).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//HANDLE DATA ENTRY ERRORS AND ERROR DISPLAY
var myerrorobject = myrecords[i][j]._source.screen.errors[theentityname]
if (myerrorobject) {
var myerrorinstance = myerrorobject[theinstancename];
if (myerrorinstance) {
var myerrorattribute = myerrorinstance[theattributename]
if (myerrorattribute) {
var errorrow = document.createElement("div");
errorrow.id = "rowcontainer" + i.toString();
errorrow.setAttribute('data-entityname', theentityname);
errorrow.setAttribute('data-instancename', theinstancename);
errorrow.setAttribute('data-attributename', theattributename);
$("#errordiv").append(errorrow);
 
$(errorrow).append("Attribute : " + myerrorattribute.attributeId.toString() + " - " + myerrorattribute.message);
$("input[data-entityname='" + theentityname + "'][data-instancename='" + theinstancename + "'][data-attributename='" + theattributename + "']").css("border", "3px solid red");
}
}
}

In this section we build a small DIV for the errors, and add any errors that exist as rows within it. At the same time, the relevant attribute is highlighted with a red border.

Updating the User Interface

When the user makes changes, we need to handle them and ensure they are passed on. The last part of the code for today concentrates on handling each of the data types, and making sure the data is correctly passed to Oracle Policy Automation. This is quite tricky, and can necessitate quite a bit of review of the Investigate JSON to try and understand what it does not like, as the error in the Browser will most likely be a generic 500 error.

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
var inputtype = $(attrInput).attr("type");
var datepicker = $(attrInput).attr("data-datepicker")
 
switch (inputtype) {
case "checkbox":
$(attrInput).change(function () {
interview.setInputValue(event.target.attributes["data-attributename"].value, this.checked, event.target.attributes["data-entityname"].value, event.target.attributes["data-instancename"].value);
 
interview.saveData();
event.stopImmediatePropagation();
 
});
break;
case "input":
 
if (datepicker === 'true') {
$(attrInput).change(function () {
var mydate = $(this).datepicker('getDate');
mydate = new Date(mydate);
var mydateinstance = $(this).attr("data-instancename");
var mydateattribute = $(this).attr("data-attributename");
var mydateentity = $(this).attr("data-entityname");
var myisodate = mydate.toString();
function formatDate(mydate) {
var d = new Date(mydate),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
 
if (month.length < 2)
month = '0' + month;
if (day.length < 2)
day = '0' + day;
 
return [year, month, day].join('-');
}
interview.setInputValue(mydateattribute, formatDate(mydate), mydateentity, mydateinstance);
 
interview.saveData();
event.stopImmediatePropagation();
 
});
 
} else {
$(attrInput).change(function () {
interview.setInputValue(event.target.attributes["data-attributename"].value, event.target.value.toString(), event.target.attributes["data-entityname"].value, event.target.attributes["data-instancename"].value);
 
interview.saveData();
event.stopImmediatePropagation();
 
});
 
}
 
break;
case "number":
$(attrInput).change(function () {
interview.setInputValue(event.target.attributes["data-attributename"].value, Number(event.target.value), event.target.attributes["data-entityname"].value, event.target.attributes["data-instancename"].value);
 
interview.saveData();
event.stopImmediatePropagation();
 
});
break;
}
 
}

And so this pretty much leaves us with a row builder, and an error builder. But the final part of the code is very important, specifically the Delete Button to delete the row you don’t want any more.

Delete Rows

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//ADD A DELETE ROW BUTTON  AFTER EACH ROW
								var deletebutton = document.createElement("button");
								deletebutton.setAttribute("type", "button");
								var deletebuttontext = document.createTextNode(control.getRemoveButtonText());
								deletebutton.appendChild(deletebuttontext);
								//SET UP THE CLICK EVENT OF THE DELETE BUTTON
								$(deletebutton).click(function () {
									var myliveinstances = control._source.instances.slice();
									// FIND THE ROW THAT CONTAINS THE DELETED INSTANCE
									var found = myliveinstances.indexOf(event.target.parentElement.getAttribute("data-instancename"));
									control.removeRow(found);
 
									drawrows();
								});
								rowdiv.appendChild(deletebutton);

Delete the Right Row

The delete row feature needs to find the row in the live set of instances (the _source.instances) using the HTML element that is the parent of the button. So if you click the Button, which is on the third row of the HTML User Interface, then using the instance name we can find the correct row and remove it. This is because the control.removeRow() uses the zero-indexed array in control._source.instances, not the user interface you are building. For example, if you have four instances on screen, then you delete one, the HTML will show that instance 1, instance 3 and instance 4 remain for example. But the Array members are now marked as rows 0,1 and 2.

The code closes out with the standard stuff :

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
update: function (el) {$("#errordiv").empty();	drawrows();},
				unmount: function (el) {
 
					if (control.getProperty("name") == "xEntity") {
 
						$("#entitycollector").remove();
					}
				}
			}
		}
	}
})
 
 

And so, what remains to be done? Well, of course, reorganize all that code written as a stream of consciousness!

But seriously, the obvious ones are

  • Ensure that when an instance is created, but the user has not yet entered any data, that the error checking is fired ( you can actually advance to the next page and come back to see the errors, because of the way the error object is handled only on the mount , not on the update.
  • Ensure that errors are removed from the page when they relate to an instance that was deleted by the user.
  • Ensure that the HTML building includes CSS class information to facilitate a new look
  • Build out date-time input and currency input and saving

But I’m sure you will find time for that. Have a nice day and enjoy building your own Custom Entity Collect Extension in Oracle Policy Automation!

We’ll leave you with a short video.