Quantcast
Channel: Oracle Blogs | Oracle Shay Shmeltzer's Blog
Viewing all articles
Browse latest Browse all 200

Oracle ABCS - Traversing Relationships, Conditional Navigation, Query and Update with JavaScript

$
0
0

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:

  1. Check how many open spaces are available for the event we are trying to register for.
  2. If there is space in the event, save the new person data, and show a success message.
  3. If there isn't space, update the person "Waitlisted" field to be true, save the data, and show a message saying that the person is on the wait list. 

In the demo video below I'm showing how to:

  • Define declarative conditional flow of steps based on results from custom code
  • Traverse relationships between custom object through code
  • Execute a conditional query and run through the results from a custom object with code
  • Set the value for a property of a custom object through code

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.


Viewing all articles
Browse latest Browse all 200

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>