Visual Builder

Get Involved. Join the Conversation.

Topic

    Stephen Bryant
    Compare Amount in UI Field to Business Object dataAnswered
    Topic posted May 24, 2019 by Stephen BryantBronze Trophy: 5,000+ Points, tagged Business Objects, Custom Code, Groovy, UI, Validation 
    67 Views, 5 Comments
    Title:
    Compare Amount in UI Field to Business Object data
    Summary:
    Verify funds are available for a transaction
    Content:

    Hello,

    I have a transaction screen where I want to verify that funds are available for a given transaction before saving.

    The amount of the current transaction is compared to the amount of a predecessor transaction.  If the predecessor transaction has other transactions booked against it, those transactions must also be included in the amount available calculation.

    For example, the data in the Business Object may look like this:

    docNumber          fromDocNumber      Amount

    transA                   ----                           $1000

    transB                  transA                       200

    transC                  transA                       100

    Amount available is $700

    The next Transaction comes in for 500.  Checking for funds would iterate through the Business Object and summarize the remaining amount and make the compare of $700 and $500.

    I can do this in JavaScript in Sublime but I fail to get it to work in VBCS.

    I tried a Field Validation rule on the BO but I cannot access the existing data in the BO, only the current transaction data.  I would like to create an array/list in the Field Validation Rule but cannot get to the existing data.

    If I create a JavaScript function on the page, I cannot iterate over the Business Object to summarize the data.

    Can anyone provide guidance?

    Thanks,

    Steve

    Version:
    19.1.3

    Best Comment

    Shay Shmeltzer

    You can have an object function in the BO layer that iterate over rows to get you a total.

    Examples:

     create an object function for a business object

    and https://blogs.oracle.com/vbcs/service-methods-for-business-objects-in-visual-builder

     

    Comment

     

    • Shay Shmeltzer

      You can have an object function in the BO layer that iterate over rows to get you a total.

      Examples:

       create an object function for a business object

      and https://blogs.oracle.com/vbcs/service-methods-for-business-objects-in-visual-builder

       

      • Stephen Bryant

        Shay,

        Thanks for your response.

        I followed the documentation and your videos and as I understand it, these are post operations.  In my case, I need to compare an amount to summarized amounts (based on my function) in the business object.  The problem I am having is I cannot seem to pull up any data.  I am using println to verify this.

        Here is my simple attempt at pulling data:

        def vo = newView('fvBeTrxHdrs');
        vo.appendViewCriteria("docNumber = '"+docNum+"'");
        vo.executeQuery();

        r = vo.hasNext();
        println r;

        r keeps coming up false.

        Please keep in mind I only need to get amounts to do a compare.  If it must be a post action, I could create a column indicating that the document passed funds checking if that will make this thing work.  For now, I am concerned I cannot even get the data.  The BO, parameters and variables are all defined and valid.  Any ideas?

        Thanks,

        Steve

         

         

      • Stephen Bryant

        Shay,

        I am able to pull the data I need to make the calculation however, I am doing that with two functions and then comparing the results via a visual builder action.

        However, I would like to make one call to one function and simply receive a Pass/Fail response.

        Below are the two functions that are working that are used in the visual builder action.  That all works. 

        The only difference between the two functions is the object column in the view criteria.  I call each function separately and pass in the one document parameter.

        The third function attempts to pass two parameters (docNum and fromDocNum) and then append the view criteria but that does not work. 

        Is it better to do this with two separate functions?  Or is one function better practice?  

        This is my first time using groovy so i appreciate any advice you can provide.

        Thanks,

        Steve

        This function gets the original doc amount where I am passing in the document number (docNum) and view criteria assigns the docNum to the docNumber column in the object.

        def vo = newView('fvBeTrxHdrs');

        addBindVariable(vo, 'VarDocNum');

        setBindVariable(vo, 'VarDocNum', docNum);

        vo.appendViewCriteria('docNumber = :VarDocNum');

        vo.executeQuery(); 

        def totalAmt = 0; 

        while (vo.hasNext()) {

          def row = vo.next(); 

          totalAmt += row.docTotal; 

        }

         return totalAmt;

        This function gets the spending amount where I am passing in the document number (docNum) and view criteria assigns the docNum to the fromDocNum column in the object. 

        def vo = newView('fvBeTrxHdrs');

        addBindVariable(vo, 'VarDocNum');

        setBindVariable(vo, 'VarDocNum', docNum);

        vo.appendViewCriteria('fromDocNum = :VarDocNum');

        vo.executeQuery(); 

        def totalAmt = 0; 

        while (vo.hasNext()) {

          def row = vo.next();  

          totalAmt += row.docTotal; 

        return totalAmt;  

        The third function attempts to update the appendViewCriteria with both columns but I cannot get that to work.  I am passing in both parameters but still cannot get it to work. 

        def vo = newView('fvBeTrxHdrs');

        addBindVariable(vo, 'VarDocNum');

        addBindVariable(vo, 'VarFromDocNum');

        setBindVariable(vo, 'VarDocNum', docNum);

        setBindVariable(vo, 'VarFromDocNum', fromDocNum);

        vo.appendViewCriteria(('docNumber = :VarDocNum') || ('fromDocNum = :VarFromDocNum'));

        vo.executeQuery(); 

        def totalAmt = 0; 

        while (vo.hasNext()) {

          def row = vo.next();  

          totalAmt += row.docTotal;

        }

        return totalAmt;

         

    • Stephen Bryant

      Shay,

      Once again, I figured out.  I am all set.  Sometimes I think just being involved in your threads gets me where I need to be even if you do not respond!

      No worries man and thanks for all your help.

      Steve