Category: JavaScript Extensions

JavaScript Extension : customEntityRemoveButton

JavaScript Extension : customEntityRemoveButton

Once again I came across this question on another forum, so I answered there and decided to reproduce it here in more detail. As some of you are no doubt aware, there are a number of smaller extensions in respect of Entity Collects, that all the developer to manage the process of deleting, or adding instances without having to completely redesign the Entity Collect which is a heavier task by an order of magnitude. customEntityRemoveButton is a good example.

The question, very pertinent I must say, concerned the deletion of instances, and the fact that there is no confirmation dialog. You click the button and the suppression just happens, without a chance to say “oops, didn’t mean that one”. Enter the customEntityRemoveButton!

customEntityRemoveButton 1

  1. An Entity Collect
  2. The Delete Instance Button that will be customized with a customEntityRemoveButton extension

The extension in question is known as a customEntityRemoveButton, and it has a unique handler which you might not have come across. This handler is known as setInstance Рand the job of this handler is to provide the instance identifier. So, for a scenario, if you create three instances, then obviously each button needs to know which instance it belongs to, so to speak. This handler fires first (even before the mount handler it seems) so that you can recover the identifier and then use it to ensure the right button does the right job.

The example scenario is that the user would love to have a confirmation dialog. And since I’m often accused to using too much jQuery, this one is in native JavaScript. It would look like this perhaps:

/*  Generated by the OPA Hub Website 07/04/2020 17:54
Educational Example of Custom Remove Instance Button Extension for Oracle Policy Automation
I will remember this is for demonstration purposes only.
 */
 let mycontext = "";
OraclePolicyAutomation.AddExtension({
	customEntityRemoveButton: function (control, interview) {
		if (control.getProperty("name") == "xRemoveButton") {
			return {
				mount: function (el) {
					var div_parent = document.createElement("div");
					div_parent.id = "xButton_parent";
					el.appendChild(div_parent);
					console.log("Button mounted");
					makebutton(mycontext,el,control);
				},
				setInstance: function (el) {
					console.log("Button set Instance for " + el.toString());
					mycontext = el;
				},
				update: function (el) {
					console.log("Button updated for " + el.innerText);
 
				},
				unmount: function (el) {
					if (control.getProperty("name") == "xRemoveButton" ) {
						console.log("Unmount");
					}
				}
			}
		}
	}
})
 
function makebutton(instance, mycontext,control) {
 
	var div = document.createElement("button");
	div.id = "xRemoveButton" + instance;
		div.innerHTML = "Remove Me " + instance;
	div.onclick = function () {
		var goahead = confirm("Are you Sure?");
 
 
		if(goahead === true) 
		{control.removeInstance(instance);return false;}
 
	else{
		alert("No delete");return false;
	}
 
	};
	mycontext.appendChild(div);
 
}

I repeat that this is just a quick demonstration that I pulled together from somewhere in my head. The documentation on line is very thin concerning this particular handler and indeed these extensions in general.

customEntityRemoveButton 2

In the screenshot above and below you can see the new improved custom Button!

customEntityRemoveButton 3

Users now relax safe in the hands of our sanity checking dialog box ūüôā

If you are interested in the Zip Archive just leave a comment and I will share it. This was done in 20A.

Have a nice day!

JavaScript Extensions for Oracle Policy Modeling

JavaScript Extensions for Oracle Policy Modeling

The JavaScript Extensions for Oracle Policy Modeling book is now available in all the channels that are currently supported:

Buy it from the Publisher

This option is probably the best if you are looking for the eBook. There is also a great bundle deal at the moment with the Getting Started with Oracle Policy Automation 2019 book. For more information you can find the details over on the P8 Tech website page.

Buy it from Amazon.com

The information that Amazon prints regarding availability of the title is incredibly vague and usually inaccurate. But at the moment, it is correct – it is shipping in a couple of days. This option is good for North American readers therefore. Find out more from the Amazon.com page here.

Buy it from Amazon.co.uk

Just like it’s global counterpart, the shipping information is usually wide of the mark but at the moment they have got it right, you can order the book from Amazon.co.uk and it will ship very fast. I’ve included a pretty picture of the book below, or you can click this JavaScript Extensions for Oracle Policy Modeling link. Full disclosure, this link is an affiliate link that earns us 50 cents extra on every purchase.

Buy JavaScript Extensions for Oracle Policy Modeling from the Book Depository

The most efficient and cost-effective way for the Rest of the World to acquire this and the other titles in the collection, the most important benefit of using this supplier is the fact that the book can be shipped anywhere in the world and they are remarkably efficient. Price-sensitive customers will find their shipment charges more attractive than Amazon in general. You can find out more from the Book Depository page for JavaScript Extensions for Oracle Policy Modeling.

What about the other book?

Some of you have been asking about Getting Started with Oracle Policy Modeling. Here are some answers:

  1. Yes it is being updated, worked started in the holiday season
  2. Yes it is being renamed because the product has been renamed and because the scope of the book is broader than ever
  3. Yes it will be released as soon as possible (probably end of Q1, early Q2)
  4. No it will not have broccoli on the cover. Tune in later to find out what it will be. Or submit your suggestion!

Input Extensions – DropDowns

Input Extensions – DropDowns

Many thanks to long-time reader and Oracle Policy Automation expert Aaron H for an interesting discussion just before the holiday season. The subject for this post is as you can tell, Input extensions that are dropdowns.

Our conversation was wide ranging but this article will focus on a couple of things

  1. How to ensure that the extension displays and handles the text and value elements of your list of values
  2. How to handle <uncertain>
  3. How to have a different label for <uncertain>

Along the way this will give us the opportunity to understand the usefulness of the Value() function in a rule. In later posts in this series we will look at other forms of Input, also beyond the basic INPUT or SELECT tag.

So let’s begin with a simple setup – the Zip Archive is available in the OPA Hub Shop by the way) – starting with just one attribute and a Value List:

The initial Value List looks like this – notice that in this case, there is no distinction between the displayed text and the actual value:

Input Extensions - DropDowns

In this simple scenario, one often sees extension code that focuses on the control.getOptions() method and then iterating through the various options from the returned object, something a little like this (for educational purposes only) :

var myChoices = control.getOptions();
for (key in myChoices) {
if(myChoices[key].value)
{
$('#xDropDown').append('<option value="' + myChoices[key]..text.toString() + '">' + myChoices[key].text.toString() + '</option>');
}
}

The code works fine, but makes a few assumptions that can come back and bite later when the rule designer has made changes.

  1. It does not take into account the possible change in the Value List to include display and values.
  2. It will error out if the dropdown becomes non-mandatory since “uncertain” will cause .toString() to fail

So when the developer of the rule changes the Value List to something like this:

Input Extensions - DropDowns 2

The code would no longer be useful since the [key].text and [key].value are two different values. And if we are updating the underlying control, we need to remember that we call control.setValue() so it is expecting a value, not the display value.

So maybe the code gets changed to :

 $('#xDropDown').append('<option value="' + myChoices[key].value + '">' + myChoices[key].text.toString() + '</option>');

Or something similar. All is well and the dropdown is correctly handling things :

Until the attribute is defined as non-mandatory in the Screen where it is displayed. At which point the code breaks again, as the uncertain value is not handled. Let’s take a step back and remind ourselves of the defaut behaviour in these situations, without an extension:

The standard control renders an empty option for the uncertain value. I’ve always considered it a bit of a bug that it does not respect the optional Display Value (in my case, “Not Sure” – see the screenshot a little further up) but always renders a blank, at least in all my browsers.

So in the case of an Input Extension that needs to render the uncertain value (because the control is not mandatory) and also wants to show the Display Value, the code will probably need to have another quick change:

Input Extensions DropDown Code Last One

Which will ensure that the dropdown is rendered with the correct text and value, if there is one. Also, the added bonus is that the display text of uncertain is rendered as we would expect:

Input Extension Showing Uncertain Vlaue

And finally, we have good use of the Value() function so that we can be sure that the correct value is stored in our Interview:

The function above, in a Word document for example, will return the value rather than the display value. So you can drop it onto the final Screen of your testing Project and compare the two to make sure you have gathered the correct one.

Hopefully that was fun and interesting, and you can practice yourself with your own project. As mentioned above the code is available in the OPA Hub Shop. The documentation is of course on the Oracle Intelligent Advisor website.

JSON Extension File

JSON Extension File

As many, but not all readers are probably aware, the Oracle Policy Automation JavaScript API is restricted in terms of what data it can manipulate in code. The default position is simple. If you plan on working with (accessing, updating or whatever is appropriate given the nature of the data and the type of attribute or entity instance) information from the Data tab of Oracle Policy Modeling then it must be present on the Screen that contains your Extension.

Here is a simple example to illustrate. Suppose you have a project that infers a list of Metro Stations. These stations are inferred in some way by Excel or Word rules. You wish to use a drop-down to allow the user to select one of those stations.

You decide to use the much-downloaded educational example called  Dynamic Options from Instances which you found in the OPA Hub Shop. So far so good. You look at the example Project and you see this:

JSON Extension File - Before

Cool. It’s a demonstration of a dynamic options list (at the bottom) driven by the entity instances (at the top). And the console shows some cool output to highlight the construction of the list. On the left, you can see that the interview is made up of two Screens. Excellent. Then you decide to split the interview into three Screens – separating the Instances from the Selection. Sounds really cool and a better layout. Now you see this in the Debugger:

JSON Extension FileWhich I think you will agree, is sub-optimal. Our extension just fails miserably. But now, it’s opm.extension.data.json to the rescue. We create this file in the¬†resources folder and populate it according to our needs. In this case, we add – and this is required for any entity attributes – the relationship name (the technical name, not the textual name) and then we declare any attributes we want. So our file looks like this:

JSON Extension File Example

We re-debug and everything is back to normal. Re-cool. Obviously we should avoid putting too many elements in there – especially parent – child relationships which can result in masses of JSON being generated by Oracle Policy Automation and made available to your JavaScript, potentially creating performance bottlenecks. But for our little example, it’s perfect.

Most Popular Downloads on this Site

Most Popular Downloads on this Site

We used to say that anything with “Google Maps” in the title was a sure-fire winner when it came to people downloading examples – after all Google Maps used to be so easy to get into, and so many people just “get” why a map is useful, that it was absolutely the go-to example. But is it still the case? Google APIs now need a Billing Account, and an API key, which in turn needs to have domain restrictions, and other administrative elements. It’s not quite as easy as it used to be.

So we set out to look at the different examples that have been downloaded on this site. And here are the results. Interesting. Under the graph, some comments and remarks which might explain some of the data.

Most Popular Downloads

Custom Google Maps JavaScript Label Extension Example 21

Custom Dynamic Options JavaScript Extension Example 21

Didn’t expect that one to be in there at all!

Custom JSON Search JavaScript Extension Example 19

Same for this one. Maybe Search is the new Map?

Custom Entity Container Extension Example  17

Google Maps as Custom Input Control Extension 15

Ah, see, the combined score is going to be huge.

Custom JavaScript Extensions Map with Google Places and Custom Options List  12

Told you. Google Maps reigns supreme!

Custom Header as a Timer JavaScript Extension 12

Custom Year Picker JavaScript Input Extension Example 9

JavaScript Extension Entity Collect Control 7

JavaScript Entity Collect Extension Excel Data Load 6

Custom Signature Extension Example 6

Wow. This one isn’t even really an extension!

JavaScript Extension Search Examples – Airlines, Great Circle Mapping, Airports 6

Everyone loves planes. I get that.

Embed Website in Interview Label Extension 5

JavaScript Extensions with a Live Entity-based Chart with D3 5

Everyone hates D3. I get that.

JavaScript Extension Search Example – Railways 5

Not as much fun as airplanes.

Loader Image in Entity Instances Search Extension 4

JavaScript Extension fullCustomInput Example 4

JavaScript Extension Custom Label Detail Pop-up 4

Calendar Input Extension Blackout Dates 3

JavaScript Extension Search Example – Siebel REST API 3

JavaScript Extension Relationship Control 2

JavaScript Label Extension Leaflet JS Map 2

Wow. This is the free alternative to Google Maps. I would have imagined this to be more popular.

Force PDF Click Button Extension and Label  1

As you can see from the Chart, Google Maps is hanging on – but only just! It’s ex aequo with the Search Extension. However if you pool together all the Google Maps stuff, it completely wipes the floor with the competition. Definitely the most popular downloads.

Want even more downloads?

If you are interested in even more examples (including a complete Entity Collect, a Carousel, Breadcrumbs, lots of Inputs and more, then you will be interested in our new book, JavaScript Extensions for Oracle Policy Modeling.

JavaScript Extensions for Oracle Policy Modeling

JavaScript Extensions for Oracle Policy Modeling

It’s almost ready. The perfect Christmas gift (yeah, right, in bizarro-world) or New Year workout kit. The new book is due out in a few weeks, and you have the chance to win a free copy ahead of everyone else by entering our prize Survey (30 seconds) right now.

The book comes with 50 examples. You get them as Zip Files as well when you buy the book. The book covers all the different types of JavaScript Extensions that are currently available, with examples of each of them (sometimes many different examples) using easily-understandable business scenarios as the starting point, and using example projects from Oracle Policy Modeling – so you don’t need to install a Hub, or do anything special – which let’s you get started straight away.

  • Label Extensions
  • Input Extensions
  • Search Extensions
  • Options Extensions
  • Entity Collect Extensions
  • Entity Container Extensions
  • Button Extensions
  • Event Extensions
  • Navigation, Header and Footer Extensions

The OPA Hub Website Community has also stepped up and I am delighted to say that 8 examples (with credits) came from readers of this website. I am very grateful to them and encourage all of you to submit your ideas and code snippets for the next version.

Hopefully this book will appeal to non-technical people too – I wrote it in the same style as the others (Getting Started with OPA, Getting Started with OSvC) and tried to make it as accessible as possible to everyone.

Here, in avant-premiere, is the cover. And no, I’m not sure what those things are either. But they sure look exotic and tasty. I wanted a parsnip on the cover but these were available and they look good. These are important questions that you worry about late at night. The publisher’s website has been updated, watch this space for the launch date!

 

JavaScript Extensions

New JavaScript Extensions Book – Win!

New JavaScript Extensions Book – Win!

We’re pleased to say that our new Oracle Policy Automation JavaScript Extensions book is almost finished. Designed to be useful for anyone looking to understand how to extend their interviews with JavaScript Extensions. It comes with 50 worked examples and Zip Archives to download. It was written to help non-programming Oracle Policy Automation professionals understand what is possible. Professional Programmers can use the examples and extend them / adapt them according to their needs.

Win a Free Copy!

The new book is part of our program of providing useful resources and assistance to the community. Help the OPA Hub Website by filling in the survey below and enter to win a copy of the book and the free goodies we mentioned. We’re attempting to broaden our offerings to include various forms of training and assistance, and your feedback helps us a great deal. We want to serve the community in the best way possible and this is part of that process, learning about your needs.

If you enter the very short survey below and complete the last question, you will be entered into the draw – one person will be drawn at random and will win a copy of the book as soon as it is published (in the New Year 2020) and a bunch of other goodies – a baseball cap, a tee-shirt, a pen and a mug! So what are you waiting for? If for whatever reason, the embedded survey below does not work, you can also access it here.

Enter the Survey to win!

Create your own user feedback survey

Worldwide
Logo by Southpaw Projects LLC