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
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Cutting-Edge Object Detection for Autonomous Vehicles: Advanced Transformers and Multi-Sensor Fusion
  • Writing DTOs With Java8, Lombok, and Java14+
  • Graph API for Entra ID (Azure AD) Object Management
  • A Comprehensive Guide to IAM in Object Storage

Trending

  • Driving DevOps With Smart, Scalable Testing
  • How Kubernetes Cluster Sizing Affects Performance and Cost Efficiency in Cloud Deployments
  • How to Build Real-Time BI Systems: Architecture, Code, and Best Practices
  • Data Lake vs. Warehouse vs. Lakehouse vs. Mart: Choosing the Right Architecture for Your Business
  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 user avatar
Shay Shmeltzer
·
Nov. 23, 17 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
7.0K Views

Join the DZone community and get the full member experience.

Join For Free

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, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Cutting-Edge Object Detection for Autonomous Vehicles: Advanced Transformers and Multi-Sensor Fusion
  • Writing DTOs With Java8, Lombok, and Java14+
  • Graph API for Entra ID (Azure AD) Object Management
  • A Comprehensive Guide to IAM in Object Storage

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!