Welcome to the OPA Hub!


Tag Archives: JavaScript

The OPA Hub Snap Poll Results

The OPA Hub Snap Poll Results

The OPA Hub Snap Poll Results

As you know, the OPA Hub Website runs short-term polls or “Snap Polls” in an effort to collect and share information about Oracle Policy Automation that may hopefully be of value to the Community. The OPA Hub Snap Poll Results concern the question we asked in March 2018, specifically “Are you going to be using the new JavaScript Extension in your OPA Interviews?”.

The most recent versions of Oracle Policy Automation have pretty much consolidated JavaScript as the client-side platform for delivering just about any visual changes you might wish for. Many of us are also pretty hopeful that the JavaScript library in interviews.js is a forerunner of a future REST client, and hopefully the basis for some sophisticated integrations as well.

Of course there are other avenues of development of Oracle Policy Automation, notably the experimental RuleScript, based on the output of the Oracle Labs and the graal library. Anyway, The OPA Hub Snap Poll Results were quite definitely in favour of the JavaScript extensions. You can find the results below, and I have included a link to a dynamic version of the graphic hosted by our friends at easel.ly.

 New OPA Snap Poll

As the Snap Poll on the subject of JavaScript has now closed, a new Snap Poll has been opened, this time in an effort to get more information about the needs of the Community in respect of training and advanced workshops. Please take a moment to answer the OPA Hub Snap Poll on this subject.

You’ve got to be in it, to win it

A reminder : when we close this Snap Poll, one lucky voter will get a free copy of Getting Started with Oracle Policy Automation 2018 Edition, so don’t hesitate to vote today. The Snap Poll will close on the 31st April 2018, and results will be published on this website soon afterwards.

 

Getting Started with Oracle Policy Automation 20018 Edition

Snap Poll : Training – 1 Question, 30 Seconds and a Chance to Win

Snap Poll : Training – 1 Question, 30 Seconds and a Chance to Win

As you all know, the OPA Hub Website tries to provide content and services that meet the needs of all of us who are working with Oracle Policy Automation, and probably Oracle Service Cloud or Oracle Siebel CRM on a day-to-day basis. One of the areas we have been looking at with our partners and content providers is the subject of training. We have a number of different training projects in the pipeline. But read on to find out about our Snap Poll : Training – 1 Question, 30 Seconds and a Chance to Win…

Some of the training we already provide has met with good feedback and seems to fill a gap left by the official training provider. However, we are always eager to find out more. That is why this post contains a snap poll : it is so easy to answer the question it will take you all of 30 seconds. You can register your vote using either an anonymous vote or if you use your OPA Hub Website login you will automatically be entered into a draw to receive a free copy of the Getting Started with Oracle Policy Automation 2018 Edition.

Snap Poll : Training - 1 Question, 30 Seconds and a Chance to Win

This book is so new it is not even in the shops yet, I have just received the first copy from the printers so it is fresh as fresh can be. The book can therefore be yours just for entering our Snap Poll : Training – 1 Question, 30 Seconds and a Chance to Win!

Thank you to everyone who takes part in the spirit of sharing your opinion. The data will be reviewed on the OPA Hub and will be completely anonymised. The name of the voters will only be used to ascertain the winner of the free copy of the book!

What kind of advanced OPA training would you be interested in attending?

Custom JavaScript Extension Places and Custom Options List

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.

JavaScript Custom Extension Google Maps for Addresses and Reverse Geocoding

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.

Custom Entity Container JavaScript Extension Example #2

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 – JavaScript Custom Search

Oracle Policy Automation – JavaScript Custom Search

As many of you will no doubt  have discovered, the recent version of Oracle Policy Automation now comes equipped with a complete JavaScript Extension API. Simply put, we can create custom Labels, Input Controls and so on using JavaScript objects. Our code, which is part of the Project, is detected at runtime and executed by the JavaScript engine in your browser. In this post we will look at JavaScript Custom Search and how to use it in your own projects.

One of the most fun parts of this new API is of course discovering ways to use it. Following on from the post a couple of weeks ago, I thought I would share an example of using the customSearch. The principle behind using JavaScript Custom Search in Oracle Policy Automation is very easy to understand. Most of us are familiar, for example, with the concept of typing in a little bit of text and then the browser completes it, providing a drop down of potential choices. There are a myriad of ways and places to see it on the Internet. Perhaps you are searching for a street, so you type in the postal code and sure enough, your website might propose the list of streets in that area.

Whatever your reason for using it, here is an example you can play along with. Since we need a data provider, we are going to use JSONPlaceholder – a wonderful fake REST API that you can use for testing just this sort of thing. It is free and easy to use. We can call various different endpoints and the server will report back with fake data. We can use all the verbs and many different sorts of REST call. Great!

What else do we need?otn We need a JavaScript editor (step forward Notepad ++ for example) and the August 2017 edition of Oracle Policy Modeling. Before we look at the code however, remember the following caveat : anything you read here is for entertainment and education purposes only and should not be relied upon for any reason or situation.

Let’s get a big picture first. You are going to be coding three things

  1. The Search
  2. The Commit, which you can think of as “any post search processing”
  3. You will be building a set of records to be passed to the callback function

JavaScript Custom Search

The search itself, as I mentioned before we will use the JSONPlaceholder service. I have selected the users endpoint, so that I can fire off a query like “‘/users?q='” and pass the text string entered by my user. Hopefully the service will return some people.

JavaScript Custom Search Step by Step

The processing and preparation will involve, purely for the purpose of demonstrating the principles, laboriously removing any elements of the data I am not interested in. In fact I am going to delete everything except the name and the email address. The callback function expects a set of data that respects a specific format: “This can either be an array of strings or an array of objects where each object has a text property.” So now you know why I wanted to demonstrate the following

  1. Renaming a property in the object
  2. Using the other property, email, in the Commit.

Here is the first part, basically I am :

  1. getting the text from the user and then passing it to the REST endpoint in the form of a GET.
  2. The response is coming back at me as a bunch of objects, which I am going to loop through and trim by removing unnecessary stuff.
  3. Then I am going to convert it into an array of results for our JavaScript Custom Search.
  4. Then I call the callback function with the array passed in.

JavaScript Custom Search Script

The user can now select one of the values I have returned. When they select their chosen value, the commit will handle it:

JavaScript Custom Search Commit

In the picture above you can see the value which is passed in actually included the email element from the REST call, so I am free to use it (and any of the other bits I didn’t delete in the previous steps) to populate other attributes, such as the email address.

To help you make sense of all of that, you will find below a video which guides you through the steps and shows the different elements.

Have a nice day and I hope you enjoyed reading an example of JavaScript Custom Search in Oracle Policy Automation.

JavaScript Custom Search Video

Update (December 2017)

I forgot to mention that if your input control is displaying an attribute that is not of type text, this code will not run. It works (perhaps self-evidently, but for completeness I reiterate it) only on text attributes.

Oracle Policy Automation -JavaScript Custom API : Google Maps

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 May 2017 – New Features #2

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 OPA 12 Browser Detection

Oracle Policy Automation OPA 12 Browser Detection

Oracle Policy Automation OPA 12 Browser DetectionI wanted to go back over a situation I had a couple of weeks ago, in respect of needing to detect the user agent of the Browser that had an OPA 12 IFRAME in it, for reasons I will describe in a moment. As many of you know, the latest versions of Oracle Policy Modeling are moving away from the concept of bundling JavaScript files and other externals (such as CSS Files) with the Project by means of the /interview-theme/resources folder. In fact in the latest versions in “latest version” mode there is no support for JavaScript or CSS added by this mechanism, nor by Custom Control. So “August 2016” mode to the rescue when it comes to OPA 12 Browser Detection.

We could either just drop the JavaScript and CAA in the resources folder above, or in the case I met this week, this was not an option, it had to be a PHP file thus it was a Custom Control.

Putting aside the questions like “Where is OPA going with support for JavaScript?” (which would seem to point in the direction of RuleScript) it brings to the fore the need to achieve certain things – like browser user-agent detection – within the now somewhat less flexible framework. Let’s look at what I am talking about.

Internet Explorer 11 and the IFRAME : OPA 12 Browser Detection

Internet Explorer 11, especially in Windows 10 and on Surface tablets, behaves differently from the majority of browsers (why is this not a surprise?) in respect of opening PDF files from within an IFRAME. The PDF file is not displayed, an error is logged in the console and (in the case of Oracle Policy Automation) the session is lost.

So one obvious approach would be to prepare two links, one to download the PDF and another to open the Oracle Policy Automation Form in, for example, HTML format since that is not subject to the same security block. And then, depending on the browser user agent, hide one of the links so for the end user it is totally transparent:

  • For IE11, display the HTML version of the OPA Form
  • For all other browsers display the PDF link to the OPA Form

The advantage of this approach is improved maintenance – there is only one form, just two delivery mechanisms. Now we need to show or hide the relevant link depending on the browser.

Getting the User Agent : OPA 12 Browser Detection

Now we are faced with the User Agent issue. As you probably know, Custom Controls in PHP are still supported or at least functional as long as it is an Oracle Policy Modeling Control of type Label and your Project is set to “August 2016 mode” . So this is how we might proceed. If we use a Custom Control in PHP, the $_SERVER[‘HTTP_USER_AGENT’] variable will contain the User Agent ready for use in PHP. But it will probably return a value that is not that serviceable or even correct. But the advantages of being able to access the $_POST array (with all of the interesting metadata and things in it) mean that sometimes PHP is the way you need to go.

PHP Version : OPA 12 Browser Detection

So, JavaScript via PHP to the rescue (and yes, I know there are other ways of doing this, but I just want to illustrate a problem and point you in one direction for a solution, even if it perhaps sits right on the edge of server / client code separation). Here is a sample PHP snippet which you can attribute to a Label Custom Control. Host the PHP on your web server or wherever you have PHP.

Notice the “Trident” match : as a simple demonstration I used the text string “Trident” to detect IE11. It is not meant to be a completely bulletproof detection just an example to be replace which whatever string you are looking for. For reference I include the HTTP User Agent reported by PHP versus the JavaScript navigator.userAgent.

<?php
echo '<div style="display : none;" name="ode_browser_check" id="ode_browser_check" class="ode_submit" >' . $_SERVER['HTTP_USER_AGENT'] . '</div>';
echo "<script type=\"text/javascript\">
var myData = navigator.userAgent;
if(myData.match(/Trident/i) )
{
 (function($) {
 $(document).ready(function(){
 $(\"#id_tohide\").remove();
 $(\"#id_toshow\").show();
 $(\"#id_ofcontainerdiv > a\").attr(\"target\", \"_blank\");
 });
 });
})(jQuery);
} else {
 (function($) {
 $(document).ready(function(){
 $(\"#id_tohide\").remove();
 $(\"#id_toshow\").show();
 });
 });
})(jQuery);
};";
echo '</script>';
?>

The example above assumes you have two HTML IDs, one for the link to hide, one to show. If you are using the standard OPA Form link, you will need to add the “_blank” target to the link that points to the HTML output version, as in the example otherwise IE11 will open it in the same window and you lose your session. With these tags and code in place, your IE11 users will see one link, the other browsers will see another link.

JavaScript Version : OPA 12 Browser Detection

If you are in a position where a JavaScript file is all that is needed then you can do pretty much the same thing of course just by reverting to normal JavaScript syntax.

if(navigator.userAgent.match(/Trident/i) )
{
 (function($) {
 $(document).ready(function(){
$(\"#id_tohide\").remove();
 $(\"#id_toshow\").show();
 $(\"#id_ofcontainerdiv > a\").attr(\"target\", \"_blank\");
 });
})(jQuery);
} else {
 (function($) {
$(\"#id_tohide\").remove();
$(\"#id_toshow\").show();
 });
})(jQuery);
}

Note : All of the above will, by definition,  not work in “latest version” mode since Custom Controls / JavaScript  are not supported in “latest version” mode.

Note : In light of all of this, it makes me wonder how much longer Oracle Policy Automation deployment on a website  or on Oracle Service Cloud Customer Portal or Agent Desktop, can depend on such a nasty, legacy HTML tag as the IFRAME.

Have fun.

Chrome Debugging Policy Modeler Interviews

Chrome for Debugging Policy Modeler Interviews

When looking into an Oracle Policy Modeler Debug session, I often want to view the Interview in Google Chrome, even at an early stage. The embedded Web Browser of the Debugger being Internet Explorer-based (and for various reasons which I quite understand, not having all the Context Menu options that normal IE has), I want a quick way to get into Chrome. I need to see the CSS, the JavaScript, and all the rest. Basically give me a Browser Debug Console.

To do this requires Registry Editor work, but the result is worth the effort. Firstly, let me again make clear I am not responsible for anything you choose to do with this information – you should think before doing anything in the Registry, and make backups. The example I am giving is for Windows 10, since it seems to be the least obvious solution – certainly it took a fair bit of searching on the Internet to get this working.

Add the following Key to add the ability to call Chrome directly from a URL in Internet Explorer, so to speak. You are going to create a new protocol to add to the http:// https:// file:// res:// and so on that you can use already for links. My protocol is called Trickshot://. Doing this in Windows 10 is much harder than in previous versions since there are many more restrictions in the domain of programs, defaults and so on.

In addition, just so we understand each other, we are basically using a security issue that could, in theory, be hijacked for nefarious purposes.

Several registry keys are needed. One in the HKEY_LOCAL_MACHINE and one in HKEY_CLASSES_ROOT branch.

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Trickshot\shell\open\command]
 @="\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\" -- %1"

[HKEY_CLASSES_ROOT\Trickshot]
@="URL:trickshot"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\Trickshot\shell]

[HKEY_CLASSES_ROOT\Trickshot\shell\open]

[HKEY_CLASSES_ROOT\Trickshot\shell\open\command]
@="\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\" -- %1"

Obviously you would adjust the path to correspond to your system. Now if you go to Windows Run command and type “Trickshot:// google.fr” – with a space after the slashes and without the quotes, you should see Chrome open the relevant site. So now we could use this as a link in our Debugger. The link will work, but as a side effect, a window of the OPA Debugger will open, will fail to load the page (with an Unknown Protocol error) but then Chrome will start and you are looking at the Interview. You can start a new session, switch on the JavaScript Debugger of Chrome and so on.

Embed a label in your Interview (or put it somewhere, hard coded) that looks like this:

<a target="_blank" href="./" onclick="window.open('Trickshot:// ' + this.href, 'mynewwin');return false;">Go to Chrome</a>

This is just an example of course. Run the Interview with the Debug button as normal. Click your Go to Chrome link. When you click it, the Embedded Internet Explorer will fail to open it, but the registered application will take over and Chrome will load the page for you.

So the flow is something like this:

And of course, it is true, you could right click the normal Oracle Policy Modeler Debugger window, click Create Shortcut, minimize Oracle Policy Modeler, find the right Shortcut, run it in Chrome, ad eternam (so many useless icons on your Desktop!) and work like that. But I think this method is much faster and easier in the long run.

Have fun!