One of the most requested concepts is the ability to load options for an attribute from a database or from some other abstraction layer – for example from a REST API, into a Custom Options Extension.
This can be achieved using Oracle Integration Cloud or, as in this case, simply using an interview.fetch(). This fetch demonstration uses Oracle B2C Service as an example.
The goal is to present to the user, a list of service products. Then the user must choose a product. But the products need to be loaded from Oracle B2C Service.
To achieve this we need to consider the following :
- The list of products will be loaded into the Custom Options Extension
- The fetch() will be asynchronous so we need to manage this
The key effect here is that the Custom Option Extension has two variants. The first, the most common, expects an array of objects to be passed directly back to the extension as the options response. But look carefully at the official definition from the online documentation:
OraclePolicyAutomation.AddExtension({
customOptions: function(control, interview) {
return {
options: <array or function>,
controlType: <optional>
}
});
It says “options: <array or function>” above. So what about using a function? The advantage is that the function gives us the capability to hand off the “processing” of the list to a function, and when the function has completed, we can show the values to the user. There are other advantages such as displaying a “please wait” icon when the value is null – if you intend to update the page for example when the results have been retrieved.
So our simple example with an attribute right here:

Turns into this at runtime:

The code is relatively simple to understand:
// Custom Options Extension Example from Intelligent-Advisor.com
// Educational Purposes Only - September 2022
OraclePolicyAutomation.AddExtension({
customOptions: function (control, interview) {
if (control.getProperty("name") == "xOptionsParent") {
console.log("Custom Options Extension found " + control.getProperty("name"));
return {
options: myProducts(interview,control),
controlType: "Dropdown"
}
}
}
});
function myProducts(interview, control)
{
var headers = {
"OSvC-CREST-Application-Context": "GetProducts",
"Content-Type": "application/json"
}
var myProducts = [];
var opts = {
connectionName: "YOURCONNECTIONNAME",
relativeUri: "/serviceProducts/",
method: "GET",
headers: headers
}
try {
interview.fetch(opts)
.then(function (response) {
let promise = response.json().then(function (json) {
for (i = 0; i < json.items.length; i++) {
myProductInstance = new Object();
productName = json.items[i].lookupName;
textforOption = productName;
myProductInstance.text = textforOption.toString();
myProductInstance.value = textforOption.toString();
myProducts.push(myProductInstance);
}
console.log("List of products now ready " + JSON.stringify(myProducts));
console.log(response.status + " " + myProducts.length);
});
});
} catch (e) {
console.log(e.message);
} finally {
return myProducts;
}
}
// End of Custom Options Extension Example
We call the myProducts() function to provide the content of the Custom Options Extension options list. Then we make a standard interview.fetch() to retrieve the data. This is using version 1.4 of the Oracle B2C Service REST API, so we have to add the context header to our call. We retrieve the products, and create an object for each product with a text and value property. Then we push the object into an array. The array is returned to the Custom Options Extension.
Of course this assumes you have set up an Interview Extension Connection on your Hub and that your Oracle B2C Service instance has been configured to allow REST API calls from wherever your interview is. The example is in the Online Store.
Thanks for posting Richard!
This is really elegant and for me timely as I’ve been working with FETCH the last few weeks.
Cheers!