Tag: 4140229

Custom JavaScript Extension Places and Custom Options List

Custom JavaScript Extension Places and Custom Options List

This is the last in the series of posts about Google Maps and Oracle Policy Modelling for now. I’m conscious of the fact that there are lots of people out there who have more knowledge in JavaScript than I have, so I don’t pretend to provide anything more than “sketches” or “ideas” or “rough hacks”. But I hope you enjoy them anyway. This last post is all about a Custom JavaScript Extension Places and Custom Options List. We will use the basic principles of the previous examples and extend :

  • Display a Map
  • Geocode and Mark
  • Show an Infowindow
  • Find places in a certain radius
  • Display them in a Custom Options list

And this time we will use the Places API to get a list of information from Google, before displaying it in the Screen and using the information. Here is the scenario:

  1. You have a problem (fire, accident, police or flood or what have you)
  2. You are at a specific location (geolocalised)
  3. You need a list of people who can help (for example, a list of car repair workshops, or fire stations, or whatever).

This might fit into the scenario of an assistance company which wants to help you, by pointing you to the nearest garage or hospital or whatever. This uses the Google Places API. When you search it, you get a list of places – garages, hospitals or whatever. You set the starting location, define the radius in metres, and the type of search. The results come back as a list of places, which you can parse and add to your Oracle Policy Modelling screen as a Custom Options list.

So here is the lowdown.  The key to the Places search is in the request, as shown below:

var latlngnew = {
 lat: interview.getValue("cl_lat"),
 lng: interview.getValue("cl_long")
 };

var request = {
 location: latlngnew,
 radius: '50000',
 type: [interview.getValue("cli_search")]
 };
 var service = new google.maps.places.PlacesService(map);
 service.nearbySearch(request, callback);

In the example above you will note that there is an Oracle Policy Automation attribute value to define the type. For example, the “accident” option in the first screen:

OPA 12 - Custom JavaScript Extension Places and Custom Options List 1

Google Maps API Places Search uses type to distinguish what to look for. The mapping I made is just for fun, but bear in mind you might not find a single type that meets your needs, or you might not find any kind of match at all. The 50,000 is the number of metres for the search radius. You might get that from another attribute in Oracle Policy Automation, of course. Plus of course, there are the two attributes in which we have captured the latitude and longitude sent by the Browser.

In the callback function, we receive (hopefully) some results for our Custom JavaScript Extension Places and Custom Options List. The results are tidied up a bit, since the Oracle Policy Automation Custom Options Extension wants text and value properties (in case you want to have display values that are different from the actual values that will be stored in the receiving attribute). Finally the result is passed to the interview.

Custom JavaScript Extension Places and Custom Options List 2

Over in the Custom Option JavaScript file, we just need to grab the data from the Places API and display it as a searchable combo.

OPA 12 Custom JavaScript Extension Places and Custom Options List 4

So the end result of our Custom JavaScript Extension Places and Custom Options List exploration is that the list of providers displayed is based on the type of problem, and the location of the device. So hopefully the list of suppliers / fire stations / hospitals / police stations or whatever is pertinent.

As usual the very unpretty code, for entertainment purposes only, can be downloaded from the OPA Hub Shop. The next few blog articles are going to be on very different subjects than the JavaScript extensions, but I’m sure we will come back to these concepts often. Have a great day!

NB : Remember to test this using your favourite real Browser, not the embedded Browser : run the Debug with Ctrl+F5.

Oracle Policy Automation – JavaScript Custom Options

Oracle Policy Automation – JavaScript Custom Options

Following on from the occasional series of posts that has dealt with  Oracle Policy Automation JavaScript Custom Labels and Oracle Policy Automation JavaScript Custom Search extensions, this short post is going to demonstrate how to use the custom Options extension to build an Oracle Policy Automation – JavaScript Custom Options example. The scenario is very simple, and can mostly be achieved using non-JavaScript functionality but the goal is to showcase the capability. You will need to imagine your own business requirement.

Let’s get started. In a simple Oracle Policy Automation Project I have three attributes : the Country, the Town and the Town Level. In each Country, there are a certain number of Towns. These can be considered as a dynamic list for the purposes of our demonstration. They will be stored in an Array of Objects. They could, naturally, be obtained from a REST call to some service or other, much like the example of Search Extension. For our purposes we will have only four towns per country. Each town has a level, which corresponds to its population size.

When the user selects a Country and Town Level, we will display in a Custom Options list, the Towns that have the same Town Level or higher. So if you choose level three, we would like to see towns of levels one, two and three. If we choose level two, we would like to see levels one and two in our Oracle Policy Automation – JavaScript Custom Options list. We wish to display them as radio buttons.

Oracle Policy Automation – JavaScript Custom Options Example

How can we achieve this goal:  here is the example in more detail.

The User Interface is prepared according to the following screenshots:

Oracle Policy Automation - JavaScript Custom Options - Setup CountryThe above shows the first Screen.

Oracle Policy Automation - JavaScript Custom Options - Setup Options Extension

The second Screen displays the future dynamic Options. Note how it is a simple Textbox.

Oracle Policy Automation - JavaScript Custom Options - Code Introduction

In the above image, the basic setup is performed. Values of the Country and Town Level are acquired. An empty Array of towns is created.

Oracle Policy Automation - JavaScript Custom Options - Code Array Creation

The second part of the code is too long to reproduce here, but the above image will give you the idea. According to the Country, the array of Town objects is built. Note the text and value properties which are required, and I have added a level property. I have also, of course, created an alternative set of towns for Ireland (but I won’t show it to save space). Now I will filter the array based on the town level chosen:

Oracle Policy Automation - JavaScript Custom Options - Code Return Array Filtered

In this final screenshot, you can see the filter is based on the level and the filtered array is passed out. In addition I have specified the display as radio buttons.

Oracle Policy Automation – JavaScript Custom Options Result

Executing the code in the Project we can see the following when we select the country as Ireland, and the town level as 2, for example:

Oracle Policy Automation - JavaScript Custom Options - Result Example One

In the same vein, when France is chosen, and town level 1, this is the result:

Oracle Policy Automation - JavaScript Custom Options - Result Example Two

Have a nice day! If you would like a copy of the example code and Oracle Policy Automation – JavaScript Custom Options Project, just leave a comment to that effect. As always the official documentation can be found on the Oracle website.

Worldwide
Logo by Southpaw Projects LLC