Not able to access grid view instanceValues because the grid view object is the changed item, rather than the grid on function trigger

  1. My goal: I am trying to get the instanceValues from a grid view everytime an item changes within the grid.

  2. Issue: I am building a dynamic form, where uses need to setup fees parameters, depending on type of a contract a user have.

    • Contract type A, will have FeeType1, FeeType2, FeeType4
    • Contract type B, will have FeeType2, FeeType3, FeeType4, FeeType6

    The idea is to ask the operator to enter the right set of fees depending on the contract of the concerned user. A fee is represented by a name, and numerical value (percentage).

    So to build thing dynamically I got the idea to use the grid view, in which I pass an array of fees, and then the ui builds it self.

    Then in each grid item, I have a number input, to set the right value of the fee.

    Then I am using a function that basically get all the instanceValue, everytime one item changed.

    ```
    console.log('instanceValues', gridView1)

    return gridView1.instanceValues.reduce((acc, el) => {
    acc[el.primaryKey] = el.percent1;
    return acc;
    }, {})
    ```

    When I test the function it is perfectly returning the object, but when it is triggered by a change of input it throws an error with:

    ``
    can't access property "reduce", gridView1.instanceValues is undefined
    ``

  3. Steps I've taken to troubleshoot:
    I’ve added a console.log to see what I am getting as gridView1 object and interestingly, when I test the function as standanalone I get:

    ``
    {pluginType: "ListViewWidget2", heightType: "fixed", layoutType: "grid"…
    ``

    but when it is triggered by the change in input I get:

    ``
    {item: Object, i: 1, scrollIntoView: "_RETOOL_JS_API_", setHidden: "_RETOOL_JS_API_", scrollToIndex: "__RETOOL_JS_API_
    ``

    which represent the item that changed rather than the gridView1 it self.

    Isn’t weird?

    Is it a bug? do you see anything I am doing wrong? is there an alternative to make it work?

  4. Additional info: (Cloud or Self-hosted, Screenshots)

    We are on Cloud version.

    And we a screenshot of what I am trying to do:

I’ve found a way to fixed that is by setting a variable, that I update everytime a fee is updated.

It will give the same result, it just less elegant.

May you still check the reason why I am getting the item rather than the grid view?

You should be able to reproduce it, since I’ve reproduced it.

Thanks in advance.

Hi @adrdra, I wasn't able to replicate this myself, however I did find this thread where Miguel recommends refreshing the page after enabling instance values. It was for a list view but it's worth trying? Proper management of instance values within a listView component