DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Testing Business Programs Without Constructing Domain Objects
  • Momento Migrates Object Cache as a Service to Ampere® Altra®
  • Why I Ditched Redis for Cloudflare Durable Objects in My Rate Limiter
  • Real-Object Detection at the Edge: AWS IoT Greengrass and YOLOv5

Trending

  • PII Detection Before RAG Ingestion: Screening Documents in C#
  • Part 1: Building Governed MCP Tool Services With Quarkus LangChain4j and Goose
  • OpenCode: Setting Up an Open-Source AI Coding Assistant
  • How You Clear Your HTML5 Canvas Matters

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. Languages
  4. Query-Based Conditional Navigation in Oracle VBCS

Query-Based Conditional Navigation in Oracle VBCS

Want to introduce logic into your navigation? Here is how you can let queries dictate where your users go when using Visual Builder Cloud Service.

By 
Shay Shmeltzer
·
Nov. 23, 17 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
7.3K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

A couple of threads on the Oracle Visual Builder Cloud Service forum asked about writing code in buttons in VBCS that compares values entered in a page to data in business objects and perform conditional navigation based on the values. In a past blog, I showed the code needed for querying VBCS objects from the UI, but another sample never hurts, so here is another demo...

For this demo I'm going to show how to do it in a login flow — assuming you have a business object that keeps usernames and passwords, and you want to develop a page where a user types a user/pass combination and you need to verify that this is indeed a valid combination that exists in the business object.

(In reality, if you want to do user authentication in VBCS, you should use the built-in security frameworks and not code it this way. I'm just using this as an example.)

Here is a quick video of the working app — with pointers to the components detailed below.


The first thing you'll do is create the business object that hosts the user/pass combination — note that in the video since "user" is a reserved word, the ID for the field is actually "user_" — which is what we'll use in our code later on.

Next, you'll want to create a new page where people can insert a user/pass combination — to do that, create a new page of type "Create". This page will require you to associate it with a business object, so create a new business object. We won't actually keep data in this new business object. In the video and the code, this business object is called "query".

Now design your page and add the user and pass fields — creating parallel fields in the query business object (quser and qpass in the video). You can then remove the "Save" button that won't be used, and instead add a "validate" button.

For this new button, we'll define a new custom action that will contain custom JavaScript code. Custom code should return either a success state using resolve(); or failure using reject();.

Based on the success or failure, you can define the next action in the flow. In our case, we are showing either a success or error message:

Now let's look at the custom JavaScript code:

require(['operation/js/api/Conditions', 'operation/js/api/Operator'], function(Conditions, Operator) {
    var eo = Abcs.Entities().findById('Users');
    var passid = eo.getProperty('pass');
    var userid = eo.getProperty('user_');
    var condition = Conditions.AND(
        Conditions.SIMPLE(passid, Operator.EQUALS, $QueryEntityDetailArchetypeRecord.getValue('qpass')),
        Conditions.SIMPLE(userid, Operator.EQUALS, $QueryEntityDetailArchetypeRecord.getValue('quser'))
    );
    var operation = Abcs.Operations().read({
        entity: eo,
        condition: condition
    });
    operation.perform().then(function(operationResult) {
        if (operationResult.isSuccess()) {
            operationResult.getData().forEach(function(oneRecord) {
                resolve("ok");
            });

        }
        reject("none");
    }).
    catch(function(operationResult) {
        if (operationResult.isFailure()) {
            // Insert code you want to perform if fetching of records failed
            alert('didnt worked');
            reject("error");
        }
    });
});


Explaining the code:

  • Lines 2-4: getting the pointers to the business object and the fields in it using their field id.
  • Lines 5-8: defining a condition with AND, referencing the values of the fields on the page
  • Lins 9-11: defining the operation to read data with the condition from the business object
  • Line 12: executing the read operation
  • Line 14-18: checking if a record has been returned, and if it has, then we are ok to return success — there was a user/pass combination matching the condition.
  • Line 19: otherwise we return with a failure.

One recommendation while coding JavaScript, use a good code editor that will help highlight open/close brackets matches. It will save you a lot of time.

For more on the VBCS JavaScript API that you can use for accessing business components, see the doc.

Object (computer science)

Published at DZone with permission of Shay Shmeltzer. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Testing Business Programs Without Constructing Domain Objects
  • Momento Migrates Object Cache as a Service to Ampere® Altra®
  • Why I Ditched Redis for Cloudflare Durable Objects in My Rate Limiter
  • Real-Object Detection at the Edge: AWS IoT Greengrass and YOLOv5

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook