Visual Builder

Get Involved. Join the Conversation.


    Stephen Bryant
    Update an Array from JavascriptAnswered
    Topic posted May 1, 2019 by Stephen BryantBronze Trophy: 5,000+ Points, tagged Action Flows, Custom Code, Layout, UI 
    239 Views, 16 Comments
    Update an Array from Javascript
    Update an Array from Javascript after assigning field values in one column


    I create the following screen included below.

    I've created a function that iterates over the array and assigns a sequence number in one field for every row.  The sequence number is generated using a range.  This range will represent check numbers.  The idea is to update all payment rows with the check number.

    range -     10  to 20

    rows         check number

    1               10

    2                11

    3               12

    10             20

    I can get this to work in pure javascript in Sublime but I am unable to get it to work in VBCS.

    The function accept two parameters from the Page (paymentArray, lowNumber).

    In the action chain, I grab the variables, pass them to the function, and attempt to update the array, assign the result to the ADP and refresh the ADP but it is not working.  I am not sure how to reference the array nor update the array correctly.

    Here is my code for the function 

    PageModule.prototype.assignCheckNum = function (invArray, lowEnd) {
      var PaymentDescription = 0;
      for (var i = 1; i <= invArray.length; i++ ) {
        if ( i == 1) {
          invArray.PaymentDescription = lowEnd;       
        } else {
          invArray.PaymentDescription = lowEnd + 1;
          lowEnd += 1;            
        return invArray;


    Any help is appreciated.








    Best Comment



    • David Konecny

      How do you update ADP? Do you modify directly property? I heard that in most recent VBCS/JET release that should work but in the past that was not supported and you'd have to use Fire Data Provider action. What I used in the past and what worked was calling Fire Data Provider action with type set to "mutate" and in "update" param I would pass new modified array.


    • Shay Shmeltzer

      Are you using assign variable to take the returned value from the function (invArray) and assigning it to the items array in the ADP?

      • Stephen Bryant


        Yes, I have done that.  Is the code I provided valid?  Can I have variables as I have defined in the code for VBCS?   I am looking for a deeper understanding of variables in custom functions.  

        It looks like the syntax, "invArray.PaymentDescription" is the problem.  The update never happens since the variable, lowEnd is undefined.  If I remove the "invArray.PaymentDescription" line and replace it with, "alert(lowEnd)", I can see the initial value (the starting point).  I'm not sure what the syntax should be.  I've tried data[i] and whole bunch of others but it is not working.



        • Shay Shmeltzer

          Are you passing the whole ADP as a parameter to the function or just the array of data from the ADP?

          I think it would be better to just pass the data array as shown in the pic.

          And then use code like this to access the fields:

          PageModule.prototype.arrayModifier = function(array){
              for (var i = 1; i <= array.length; i++ ) {


          • Stephen Bryant


            Okay, I am a lot further now.  I can generate the correct payload with the function calling it and assigning the variables the way you indicated.  I now the array is updated as I can see the numbers for each row in the array correctly applied for each record (that is the check number is on the correct record as the payment number).  However, I am having troubling updating the array.  In the screen, it only displays the first number for all rows and not the sequence of numbers.

            The action chain is as follows:

            -Call Module Function and pass in the Array and First Check Number.

            -Fire Data Provider Event (mutation) to update the Array (takes the results of the Module Function Call).

            In the screen, only the first number shows for all records.

            Any ideas?  I did not think I needed to loop since the function was returning the updated data array.





      • Stephen Bryant


        Thanks for putting the video together.  I don't know what to tell you.  All the data provided by the function is perfect.  I can see the updated array data in Chrome Dev Tools.  I can even see the data right the point of the Fire Data Provider Event Update action.  Everything looks good but it still only assigns the first check number every row.  

        See my screenshot of the payload.  I've populated the Payment Description with the Check Number.  The Check Number and Payment Description are both Strings so there is no difference there.  All rows get updated with the first Check Number which is 2.  The table I am updating is based on the same ADP I am updating.  

        This is really a mystery.



      • Stephen Bryant


        Good news man!  I deleted and recreated the table that was tied to the ADP.

        It all works now!

        Sometimes the old "turn it off and turn it on" trick is the solution!

        Thanks for all your help,