Welcome to the OPA Hub!


Category Archives: November 2017

JavaScript Custom Extension Google Maps for Addresses and Reverse Geocoding

JavaScript Custom Extension Google Maps for Addresses and Reverse Geocoding Input

What is it about Google maps? This little example of a JavaScript Custom Extension Google Maps for Addresses and Reverse Geocoding was often requested by customers and students alike. Whether it be in the Siebel Hub or the OPA Hub Websites, Google Maps always seems to be a popular topic!  When I did a Google maps customlabel in Oracle Policy Modelling a few months ago, it was one of the most downloaded examples we have ever had.

JavaScript Custom Extension Google Maps for Addresses and Reverse Geocoding

And so, all I have decided to revisit the example.  This time however we will create a custom input control, and the user will click on the map to show where they are located.  These might be useful in an emergency situation, or something far more mundane such as simply be able to say what your address is, quickly.

To do this, we’re going to use the Google Maps JavaScript API once again.  We will use the same functionality as before, with new twists:

  • Marker on the map to display their browser-reported location (seen previously)
  • Information window to display text  (seen previously)
  • From the latitude and longitude obtain the Street Address
  • The possibility to drag the marker to another location if incorrect 
  • A button to confirm the selection of the address
  • The chosen the address will be passed to an attribute in the  Project

In this example therefore, we will need to use reverse geocoding.  Specifically, we need to convert the latitude and longitude into an address.  Using this Google service will normally provide us with a close match.  There may be multiple matches, or indeed no match at all.

For simplicity we will only handle the case where at least one match is found, and we will take the first match which is typically the closest.  We will not look at the other cases where there are multiple choices.  We are reserving that for another post in a little  bit!

In the example provided, which is as usual for education and amusement purposes only, the information from Google goes to our interview and is passed into an attribute.  Of course, what happens after that, it’s you that decides!

To keep things simple, the initial part of the script is the same.  We use your location to plant the marker on the map.  The exact icon used, depends entirely on what you chose in the interview : we used a simple example where the user declares an accident or a fire or some other emergency.  The marker is planted on the map. Then we introduce drag and dragend handlers, as well as a click handler.

The first page of the Interview is shown below.

JavaScript Custom Extension Google Maps for Addresses and Reverse Geocoding 1

Then we have a typical page displaying only a single Input Control for our demo.

OPA 12 - JavaScript Custom Extension Google Maps for Addresses and Reverse Geocoding 5

Our code will handle a few events. The marker click handler will display the address of the location in an infowindow. The drag and dragend handlers manage the user dragging the marker to a new location: maybe they didn’t get it right first time, so we let them do it again.

JavaScript Custom Extension Google Maps for Addresses and Reverse Geocoding 2

The two main functions in this code are the confirm_my_address function, which lets the user click a button in the marker and pass the address to Oracle Policy Automation to confirm that the marker is in the correct location, and the geocodeLatLng function, which does exactly what it says.

JavaScript Custom Extension Google Maps for Addresses and Reverse Geocoding 3It takes the latitude and longitude of the marker and queries Google to find the address of the marker before it is pushed to our attribute.

JavaScript Custom Extension Google Maps for Addresses and Reverse Geocoding 4

Because it doesn’t always work, we also have to manage the situations when had no address is returned. In this case we handle it with nothing more than an alert, which is fine for our little test. Regarding geocoding and so on you can find much more information of course on the Google Maps JavaScript API Documentation page.

Enjoy the video and if you are interested, you can download the code example for free, with no warranties and just for fun, from the OPA Hub Shop as usual. Remember to use Ctrl+F5 to run it in a real browser.

video

Signature Control Oracle Policy Automation JavaScript Extensions

Signature Control Oracle Policy Automation JavaScript Extensions

Here at the OPA Hub we have already gotten back into gear after the holidays and in fact next week we will be off to Finland for some exciting OPA-related things but in the meantime, here are some thoughts about the Signature Control. Actually it is not just about the Signature Control. Rather, in this post, we want to look at some ways of extending the unextendable. If you check out the documentation regarding the Oracle Policy Automation JavaScript Interview Extensions, the Signature Control is not in the list (except for the styling possibilities- there are no extension capabilities). So what if you need to change it’s behaviour? Can we invent Signature Control Oracle Policy Automation JavaScript Extensions?

Of course I can hear you say that the likelihood of wanting to use the Signature Control Oracle Policy Automation JavaScript Extensions is small : after all we should never be using the JavaScript extensions to do anything too crazy (remember the guidelines at the bottom of this page). What on earth would people want to change for the Signature Control – or indeed for any Control that is not currently listed as having that capability?

Well, here is a simple example :

Signature Control Oracle Policy Automation JavaScript Extensions

The Signature Control is not responsive. Of course I could tell my phone and tablet users to zoom in or out, or switch orientation. But I don’t want to. Look, I’m just trying to make a point. Customers will always come up with things that we might not expect, and the Signature Control will be no exception.

The width of the control is fixed, by the parameter entered at Design Time :

Signature Control Oracle Policy Automation JavaScript Extensions

Since we cannot extend the behaviour of the Signature, maybe we need another approach. Let’s look at some useful things we came across while researching this article.

  1. The most obvious way to extend the Signature Control is to add a blank Control to the Interview that can be extended, and leverage the keys (mount, unmount and so on) of that Control to work on the Signature. In the case shown below, a blank Container has been added to the Interview for that purpose. It has a custom property to help identify it in the JavaScript later, like most of the examples shown on this site and elsewhere.

Signature Control Oracle Policy Automation JavaScript Extensions

2. Secondly, We should be aware that the value set at Design Time for the Signature Control width (and a lot of other useful information about your Interview) can be referenced in JavaScript :

var currentWidth = interview._session.config.interviewProperties["signature-width"];

This might be useful for some sort of fallback or default value.

3. Thirdly we should be good citizens and not forget that the styling options in Oracle Policy Automation do give us a fairly broad range of options without resorting to JavaScript code. For example:

Signature Control Oracle Policy Automation JavaScript Extensions

In the above example, we use the styling capabilities of the Signature Control to change the ink colour, and we apply a CSS style to the Control as a whole. With that in mind, we can leverage media queries in the CSS to establish different sizes of display for different users:

In the example CSS below, the outline (the border) of the Signature can be changed depending on the size of the viewport / screen that the user is holding. Smaller viewports will use a one pixel border, larger ones will use 2 pixel. It’s a simple example.

4. The Signature Control might only need extending during the mount or unmount process – which makes a Container Control a good choice. For the update we will simply leave that blank since there is nothing on the Signature Control we want to work with.

The client didn’t like that funny dotted line you get when you need to sign the signature panel. Using our newly added Class, we can select the siblings of the Signature and remove the line:

var myDiv = $('.eca-signature');
var myLine = $("canvas.eca-signature").siblings();
myLine.hide();

Signature Control Oracle Policy Automation JavaScript Extensions

5.  We might also use jQuery to add a resize handler to the Interview window, and based on that we could resize the Signature to a certain degree. We can also trigger the resize handler when the window is first shown, to make sure our Signature Control is always presented in the right size. And that opens up a world of opportunities.

So what does all this give us? The following video shows some of the results. This is just a scratchpad idea – so as usual the example is given with no warranties. You can get the example code from the OPA Hub Shop by searching the code examples for Signature Control.

Signature Control Oracle Policy Automation JavaScript Extensions – Summary

It’s a work in progress, but piggybacking on top of an extendable Control like the Container (which is also pretty much invisible, which is a bonus) let’s us imagine all sorts of trickery on the Signature Control. Plus, as good citizens we have learned along the way of some interesting standard styling and customization.

In the example code there are, as usual, a number of console logs as well as some experimental code that probably does nothing : as I always say, this is for educational purposes!

Custom Entity Container JavaScript Extension Example #1

Custom Entity Container JavaScript Extension Example

Note : this JavaScript is destined for use in Debug mode. For a version usable outside of Debug Mode, please continue reading the second part of this series), followed by the final example in part three. You can also watch a quick video of the final example on  our YouTube Channel.

Once again, we look into an educational JavaScript Extension example for Oracle Policy Automation. As usual the example provided is purely intended for learning purposes. It involves a situation that you probably have come across many times. We wish to display a set of inferred entity instances in our Interview. But we are afraid that our set of instances is going to produce a layout that is rather unfriendly. Here is a visual example, taken from a sample project with a simple inferred entity that has only two attributes :

Custom Entity Container JavaScript Extension Example

There are fifty three items in my list. So the Entity Container provides a very long list. Yes, I’m sure I could play around with labels and containers and goodness knows what, in order to make it shorter. But basically, the Entity Container just spawns an elastic list. Which is the opposite of what I want. Instead I would like to see this:

Custom Entity Container JavaScript Extension Example

The above example is a fixed height, and has a scroll bar in order to visualise the content at my leisure. The page is not affected by a very long list. And that is rather nice, especially if you have a dynamic list of terms and conditions, or something similar. Here is the data model, including the inferred entity, relationship and attributes.

Custom Entity Container JavaScript Extension Example

The Excel spreadsheet is very basic for our example:

Custom Entity Container JavaScript Extension Example

Custom Entity Container JavaScript Extension Example

So now on to the mechanism for displaying the content. This Custom Entity Container JavaScript Extension Example will use a standard JavaScript template based on the Oracle Policy Automation documentation. The code of the mount section is as follows:

 

Custom Entity Container JavaScript Extension Example

Let’s look at it in detail. There is some interesting stuff in there. Firstly, the basic principle is as usual. On line 8, as before, we reference a custom Property in our Screen that allows us to identify the Entity Container Control on the Screen. Then, in lines 11 to 15 we create a simple DIV and add a scrollbar that will appear if the content is too large to display in the 100 pixel height.

Then we begin a loop in line 17, based on a global variable called data.data[1].instances.  Of course we should create a reference to it, but for the purposes of learning we can leave it as is. This object, whose exact index will change depending on the structure of your Oracle Policy Automation data model, will prove very useful indeed. It is clearly visible in the Debugging Console of the Browser, if you insert a handy break-point:

In the case of my inferred entity instances, this array contains all 53 instances in my Browser. The same array is also visible as a Local variable as well:

Note in the screenshots above, the location of the break-point is not really relevant here : it is just used to stop the JavaScript engine in the middle of mount.

So the ability to access the instances is most useful. The code loops based on the number of instances. We add a child DIV element for each instance, and then access the values of the two attributes to concatenate them into a longer string. Word-wrap is switched on in my screenshot so you can see the whole Custom Entity Container JavaScript Extension Example code.

Finally we add a horizontal rule just to break the list up a bit. Of course there are lots of things we could do here : but we are just building a simple list and don’t really worry about styling the elements in line, which is not good practice of course.

The rest of the code simply gets rid of the element when the unmount section is called.

Custom Entity Container JavaScript Extension Example

This example is interesting since it reveals a little about the inevitable content of our JavaScript extension. There are probably other ways to get hold of the content of the inferred entity but this is useful for educational purposes.

Summary

But as you have no doubt seen, the code example here will only work with the Debugger. It has it’s usefulness of course, to be able to understand that the content is structured in a certain way. But what about after Debug? That’s what’s coming next.

As always the code is available for free download from the OPA Hub Shop. Look for Custom Entity Container JavaScript Extension Example in the product list.

Custom Year Picker JavaScript Extension Example

Custom Year Picker JavaScript Extension Example

Continuing in our random series of examples of using the Oracle Policy Automation JavaScript Control Extension API, this one came up the other day. How to allow the user to only enter a year in a calendar? The data type underneath fully expects there to be a day, month and year to complete the picture, but suppose you are entering an attribute such as “Year of Registration” and the business rule states that the product is always registered as of January 1st of that year. We can call it a Custom Year Picker JavaScript Extension.

Of course as always there are many ways to achieve this, and JavaScript is definitely not the only solution. As good citizens of the Oracle Policy Automation world, we should always try and reach our goals without resorting to scripting unless it is completely necessary. Since this is supposed to be an article about the technique rather than the business requirement, let’s push on and find out how you might do it.

Firstly, there are a couple of pre-requisites. This example uses jQuery, and jQuery UI plugin called, unsurprisingly perhaps given the topic, Year-Select. I am sure there are a multitude of different plugins or tools to do this. Year-Select has the advantage of being super small and easily styleable. In addition it requires minimal coding to get it to work. Two good reasons to use it for this example. Download the file and place it in your folder. Add the jQuery files that you can download from the official site.

Now your resources folder will probably look like this : note the three external files (two from jQuery and “yearpicker.js” for the Year Picker) and your own custom JavaScript file that you are about to create “datepicker.js”. For this example, you should also create the following

  1. A Word document with a global goal that relates to couple of date attributes
  2. The two date attributes just mentioned that you should also create. Give them names as well.
  3. A label which displays these pieces of information.
  4. A date control on the Screen with a custom Property called name, value “xDate” or anything else you might like to use instead. This is similar to the other examples already described on this site.

Here are the images to help you work all that out. First the screen, with the Date control and the two attributes in the label:

Custom Year Picker JavaScript Extension Example

And secondly, the actual content of the Word document. You will notice that I am just trying to usefully have two attributes, one which is the session timestamp (which we can use when the Interview starts up, to default the Year Picker to the current year, for example) and the second attribute is going to store the selected value chosen by the user.

For the avoidance of doubt, in this Custom Year Picker JavaScript Extension Example, dt_sess is the name given to the date of the session and dt_circ is the name given to the date of registration.

On to the JavaScript code. As usual this will take the form of several different sections. In the first mount section we will

  • Create an Input control, which is the basis of our Year Picker
  • Get the Session Timestamp
  • Convert it to a Date object
  • Extract the Year
  • Apply the magic CSS class and call the yearselect.js code to intialise the jQuery UI widget

Custom Year Picker JavaScript Extension Example

  • If the date of registration has no value, then set the value to the year of the Session Timestamp, January 1st (since this was the requirement)
  • If the date of registration already has a value – because someone has already edited the year in this Interview session, then get that value and apply it to the Year Selector

Custom Year Picker JavaScript Extension Example

That’s quite a lot going on there. Most of the code is actually spent getting the actual date from the attribute and converting it into something JavaScript believes is actually a Date. Then looking to see if the date is already set, and updating the picker control.

As usual the code is absolutely filled with console logging, and the code is willfully non-optimized in order to make it as easy to read as possible for someone who just wants to know what it does. The final parts of the code handles if the user decides to update the year with the picker, and the usual unmount clears the element from the DOM.

Custom Year Picker JavaScript Extension Example

Now, in your debug session if you have added a new Screen, you can flick back and forth between the End Screen and your New Screen to observe the changes. Your new Custom Year Picker JavaScript Extension should be up and running like the following screenshot.

Custom Year Picker JavaScript Extension Example

The OPA Hub Shop – Download the Script for Custom Year Picker JavaScript Extension Example

And now for some good news (I got a lot of requests for this!). The code example, and all the other code examples, are free to download in the OPA Hub Website Shop as PDF files.

Remember if you have any ideas for examples, or you want to contribute your own, just leave a comment below!

Whats New in Oracle Policy Automation November 2017 #2

Whats New in Oracle Policy Automation November 2017 #2

As in the previous post in this series, the OPA Hub Website is concentrating on the new features, or “Whats New in Oracle Policy Automation November 2017” to be more precise. This is the second in the series. In this post we will explore two different functionalities that have been improved. Firstly, we have all probably at some point found ourselves creating attributes, and thinking about default values : setting them on the different screens of our Interview and so on. We probably also have then spent time creating Rule Tables to handle what happens when we have to default values based on the certainty of other information.

Default Values in Web Service inbound attributes

These days, managing default values in a Web Service environment just got easier. Consider the following simple example. The insurance premium is inbound in a data Connection. It is copied into an attribute called the baseline annual premium. If the inbound value is uncertain, then the default value (in this case £500) will be used. If the inbound value is different to £500, then that value will be used instead. If the inbound value is unknown, then the value of the baseline annual premium will be unknown.

Whats New in Oracle Policy Automation November 2017

Set True and False values in one shot

Another feature from the Whats New in Oracle Policy Automation November 2017 collection : in the same vein, you can now use the If function to set values for a true or false result of a condition, like you would for example in Microsoft Excel formulae. Think of it as “If(expression, value if true, value if false)”.

Whats New in Oracle Policy Automation November 2017

If the baseline annual premium is greater than 500, then the percentage of legal fees will be 100. Otherwise it will be 50. The documentation refers to “condition” but in different places it refers to Boolean attributes or conditions. In any case, it seems to work with both.

Both of these will provide decent shortcuts to existing workflow for developers looking to create cleaner rules. You can find the details in the online documentation here. Catch up with more “Whats New in Oracle Policy Automation November 2017” in the upcoming third post, where we will look at cool new features in the Interview.

PS : Note that my example assumes a Project using the English United Kingdom regional settings.

Whats New in Oracle Policy Automation November 2017 #1

Whats New in Oracle Policy Automation November 2017 #1

With the regularity of a Swiss watch, the Oracle Policy Automation team have released the latest and greatest version of their flagship natural language business rules and automated decision tool : and as usual it is packed with lots of new things for us to get excited about. Here are just a few of the key points that are in the list this time, along with some examples. Let’s look at whats new in Oracle Policy Automation November 2017, this is part one of a multi-part post.

Load During an Interview (conditionally)

One of the commonest requirements that seems to show up regularly is the need to load, for example, reference data during an interview. And for Public Cloud users, the ability to do just that is now built into the Service Cloud Connection. Let’s look at a very simple example. Suppose that you want to load some product information, depending on some criteria such as the dates of the last few purchases. What you absolutely don’t want to do is load the entire product hierarchy. Just the parts you want relative to your customer scenario : perhaps a customer logging in to the portal.

If you look carefully at the attached image above, you will notice that there is now, on the left hand side, the possibility to add a “New Unrelated Mapping”. I have already added one, based on Product. I can select an unrelated object from Service Cloud and map it into my Oracle Policy Automation November 2017 Project. Although this is delivered as out of the box functionality for the Oracle Policy Automation Cloud Service, it is in theory possible to deliver the same functionality for any Connection, provided you use the newest WSDL (which is referenced here in the documentation).

Filtering the Data Load

Furthermore, the data load can include the equivalent of an SQL where clause. In the Entity Properties, you now have access to a filtering feature.

The filter can use any field from the underlying table, even if it is not mapped inbound in Oracle Policy Modelling in your Project. The syntax is similar to the natural language of OPA. Notice also, you can limit the number of records retrieved.

This is a very exciting feature that has been requested for a long time. Outside of Service Cloud, Siebel CRM for example with it’s incredibly rich data model, this allows for considerable optimisation of data transfer to Oracle Policy Automation. In the next post in this series we will see some new functions relating to default values, which are going to be a terrific time saver!