Business Process : Force PDF Download in OPA

After last week’s business case put forward about Calendar Blackout dates, this week we can thank Arnaud D and Sylvie A from Switzerland for their excellent use case. This week we will be discussing the idea of letting a user progress to the end of an Interview, only if they have clicked to download a PDF file. So, can we Force PDF Download in OPA?

There is not really a technically feasible way to prove that a user actually read a PDF. But if we can force them to download it, at least we know they have gotten that far!

The business case is easily applied to many industries, for example where terms and conditions or a contract are generated and tacit approval needed before the user continues. Or, more simply, you need some way to encourage people to read the BI Publisher thing you spent all those weeks developing.

It is also a good opportunity for us to investigate the new custom Button extensions available in Oracle Policy Automation 19A. So this won’t work in 18D or earlier. The approach we are going to take will involve two different extensions. Let’s go!

Input Extension

The input extension is needed because we wish to capture the value of a Boolean attribute for our demonstration. Navigating forwards will only be allowed if this Boolean is true.

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
/*  Generated by the OPA Hub Website 29/03/2019 19:35
Educational Example of Custom Input Extension for Oracle Policy Automation
I will remember this is for demonstration purposes only.
 */
OraclePolicyAutomation.AddExtension({
	fullCustomInput: function (control, interview) {
		if (control.getProperty("name") == "xInput") {
			return {
				mount: function (el) {
					console.log("Starting customInput Mount");
					var div = document.createElement("input");
					div.id = "myInput";
					div.value = interview.getValue("my_flag");
div.setAttribute("style", "visibility: hidden");
el.appendChild(div);
console.log("Ending customInput Mount");
$(".opa-document").click(function(){
console.log("Clicked Link");
control.setValue(true);
});
},
update: function (el) {
console.log("Starting customInput Update");
 
console.log("Ending customInput Update");
},
validate: function (el) {
console.log("Starting customInput Validate");
 
console.log("Ending customInput Validate");
},
unmount: function (el) {
if (control.getProperty("name") == "xInput") {
console.log("Starting customInput UnMount");
 
interview.setInputValue("my_flag", $("#myInput").val());
var myInput = document.getElementById("myInput");
myInput.parentNode.removeChild(myInput);
console.log("Ending customInput UnMount");
}
}
}
}
}
})

So what’s going on here? Basically we are putting a click event on a PDF download. Notice line 17 : this adds a click event.  So as soon as the custom Input is loaded, an event is added to another control using jQuery. When the link is clicked, we update our flag to true. We use the style selector “.opa-document” to find the link. If you have more than one link, you will need a more precise method of finding it. Other than that, the custom input itself is invisible, and simply reads the current value of the flag into the control.

Button Extension

The other extension, for a nextButton, uses jQuery to display a dialog when you try and leave the screen before clicking on the link (the flag is false). Otherwise it lets you navigate without issues.

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
OraclePolicyAutomation.AddExtension({
	customNextButton: function (interview) {
		let button,
		caption;
 
		return {
			mount: function (el) {
				const screen = interview.currentScreen();
 
				button = document.createElement("div");
				button.setAttribute("title", "Print Your PDF First");
				button.setAttribute("class", "opa-back");
				button.setAttribute("role", "button");
				button.setAttribute("style", "	text-overflow: ellipsis; white-space: nowrap; line-height: 1; cursor: pointer; padding: 0.7em 1.2em; border: none; text-decoration: none; -webkit-appearance: none; flex: 0 0 auto; text-align: center; color: rgb(255, 255, 255); border-radius: 6px; background: rgb(20, 116, 191); font-size: 16px; font-style: normal; font-weight: normal; margin-left: 6px; visibility: visible; outline: none;");
 
				caption = document.createTextNode(screen.getNextCaption());
				button.appendChild(caption);
 
				var dialog = document.createElement("div");
				dialog.setAttribute("id", "dialog");
				dialog.setAttribute("title", "Warning");
 
				var dialogtext = "Please download your document first.";
				el.appendChild(dialog);
 
 
				button.onclick = function (evt) {
					evt.preventDefault();
					if (interview.getValue("my_flag") == true) {
						interview.submit();
					} else {
						$("#dialog").dialog();
						$("#dialog").text(dialogtext);
						console.log("Not Yet ");
						console.log("Flag Value is " + $("#myInput").val());
					}
				}
 
				el.appendChild(button);
			},
			update: function (el) {
				const screen = interview.currentScreen();
 
				caption.textContent = screen.getNextCaption();
 
				if (screen.hasNextButton())
					button.removeAttribute("disabled");
				else
					button.setAttribute("disabled", "disabled");
			},
			unmount: function (el) {}
		}
	}
});

So what’s happening? The early part of the mount is simply painting a nice button on the screen. We could of course not display the button at all, but the User Experience might be better if we display it always, just prohibit using it in certain circumstances. Starting around line 19 we create the dialog and make it ready for use.

Line 27 includes the button click routine which either displays the dialog, complete with a message, or just lets you navigate as normal.

The other lines in the unmount are just taken from the example in the online help, where if this is the last Screen, no next button is available. But our business case is based on it not being the last.

Force PDF Download : Animated GIF

In the animated GIF above, you can see what it looks like.

The Project Zip is in the shop. Have fun!