X

Shay Shmeltzer's Oracle Development Tools Tips

Conditional Navigation based on Queries in Oracle Visual Builder Cloud Service

Shay Shmeltzer
Director of Product Management - Oracle

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 exist 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 use, 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:

success flow

Now lets 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 would save you a lot of time.

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

Join the discussion

Comments ( 4 )
  • Srijeeta Sengupta Monday, September 17, 2018
    Hi Shay
    We are trying to build a SaaS extension.
    We have a Supplier contact who will login to VBCS and perform certain transactions which will trigger a SaaS transaction.
    Once the supplier contact logins in with the username and password (which is validated with VBCS credentials) we want to use the user name (email id of the user) to look up the supplier name. This will allow us to fetch the relevant supplier records from SaaS for the particular supplier alone.
    So if Supplier A logins , with email id of SupplierA@gmail.com then s/he should not have access to records relevant for Supplier B (email id SupplierB@gmail.com)

    Please advise how we can achieve the same.
  • Shay Monday, September 17, 2018
    Srijeeta - a better place for these type of questions is the VBCS community here: https://cloudcustomerconnect.oracle.com/resources/e610f4723c/summary
    In general, assuming you are using the new VBCS, you can define a filterCriterion for the table that is based on a system variable that we provide with the current username. More on filterCriterions here - https://blogs.oracle.com/shay/filtering-a-table%2C-list-or-other-collections-in-oracle-visual-builder-cloud-service
  • aina Friday, February 8, 2019
    I am trying to create the same thing as above in visual builder. I could not proceed with the custom code as its not taking the api and throwing errors there. could you please explain if I need to modify anything for vbcs as the code looks specific to abcs.
  • Shay Shmeltzer Friday, February 8, 2019
    Aina,
    At this stage you shouldn't be building new applications in VB using the old "Classic" approach, rather you should be using visual apps as the development approach.
    In that new architecture it is very easy to add an action chain to a button that will use a condition to decide where to navigate to based on some parameters in your page or action.
    If you are having challenges with that post your question on our forum at: https://cloudcustomerconnect.oracle.com/resources/e610f4723c/summary
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.