X

Shay Shmeltzer's Oracle Development Tools Tips

  • May 3, 2019

Working with ArrayDataProviders in JavaScript Functions in Visual Builder

Shay Shmeltzer
Director of Product Management - Oracle

Storing data in ArrayDataProviders (rather than SDP) is useful whenever you want to further modify the data on the client side - for example if you are looking to create updatable tables in your UI. A common follow up question is "how can I do additional processing/updates on all the records I'm storing in the ADP" - this is what this blog is about.

Since the records are now stored on the client side, you can access them through JavaScript. You can, for example, write a page level module function to loop over the set of records and modify them. For example in the video below I'm using this little function to raise the salary of all the employees:

  PageModule.prototype.arrayModifier = function(array){
    console.log(array.length + " is what we got")
      for (var i = 0; i < array.length  ; i++ ) {
        array[i].salary = array[i].salary+2;
        console.log("salary after " + array[i].salary);
    }
    return array;
  }

Into this function you'll pass the array of data from the ArrayDataProvider - you can do this in the parameter mapping of the function pointing to the data object like this:

ADP Data as Parameter

Once your function finished its processing of the data, you'll want to update the ArrayDataProvider back to reflect the changes you did. To do this you can use the action called "Fire Data Provider Event". This function has the option to do mutate events (update, insert, delete). You can read the doc about this and other actions parameters here. For the update you simply need to provide the array of updated data like this:

ADP Update Mutation Parameter

That's it. You can see all the pieces of this process working together in the video below:

 

Join the discussion

Comments ( 2 )
  • Antonio Peixoto Monday, May 6, 2019
    Hi,
    Could you please, help me with problem in VBCS.
    When use FIre Data Provider, option mutate, know a error bellow.

    /vb/types/ArrayDataProvider]: unable to dispatch the mutation event due to inadequate information [object Object]
  • Shay Monday, May 6, 2019
    Antonio - the right place to ask questions like this would be our forum: https://cloudcustomerconnect.oracle.com/resources/e610f4723c/summary
    Where you can also provide more information on the steps you took and the parameters you passed.
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.