Oracle Application Builder Cloud Service (ABCS) lets you do a lot of things in a declarative way, however for more complex validation and conditional logic you might need to resort to some basic coding in JavaScript.
I ran into such a case with an application I was developing, and figured out that the code sample from that system will be a good way to illustrate some coding techniques in ABCS.
The application I was working on allows people to register to various events. Each event has a certain capacity, so if there are too many people registered to an event, we want the rest to be added to a wait list. For each record of a person registering, we keep a reference to the event they want to attend. So the logic flow is:
In the demo video below I'm showing how to:
For reference here is the complete code from the sample:
require([
'operation/js/api/Conditions',
'operation/js/api/Operator'
], function (Conditions, Operator) {
var lab = Abcs.Entities().findById('Lab');
var id = lab.getProperty('id');
//condition is to find a lab with the id that is in the page's drop down box
var condition = Conditions.SIMPLE(id, Operator.EQUALS, $Person.getValue('ref2Combo_Box'));
var operation = Abcs.Operations().read({
entity: lab,
condition: condition
});
//if query returned value we loop over the rows and check the capacity and registration columns
operation.perform().then(function (operationResult) {
if (operationResult.isSuccess()) {
operationResult.getData().forEach(function (oneRecord) {
if ((oneRecord.Capacity - oneRecord.Registered) < 1) {
$Person.setValue('Waitlisted', true);
reject("error");
} else
{
resolve("ok");
}
});
}
}).catch(function (operationResult) {
if (operationResult.isFailure()) {
// Insert code you want to perform if fetching of records failed
alert('didnt worked');
reject("error");
}
});
});
More information on the JavaScript APIs used here are in the Oracle ABCS Documentation.