Refreshing Record Backed Grid After writeToDataStoreEntity

Certified Lead Developer

I have an interface that displays an interface with a form if a local variable is true, else it shows an interface with a grid. The desired behavior is once the user creates an item using the form, the grid will automatically update to display the new item in the grid. It does not do this. The user has to click the grid refresh button to see the new item.

The form saves the item using writeToDataStoreEntity in the saveInto of the submit button. On success, it changes the value of the boolean which causes the grid to appear to the user.

The grid is a record-backed grid. Changing the grid to use a DSE or changing the form to use a record are not allowed. A process model is also not allowed.

Placing the recordData in a local variable and using refreshAfterVarChange does not update the recordData. Using the refreshOnVarChange parameter in the grid does not refresh the data. Placing the grid interface in a local variable with refreshOnVarChange also does not cause the recordData to update.

Since I am changing the boolean only after the writeToDataStoreEntity is successful, I assume the data has been saved to the database before the boolean changes. I would also assume that once the boolean changes, the refreshOnVarChange would cause a!recordData(..) to run again causing the record to retrieve the newly saved item. 

Can someone explain why the above logic is wrong and offer a suggestion for how to update the record data?

Below are the relevant parts of the code:

PARENT INTERFACE:

local!viewForm: false,

if( viewForm, rule!myForm(viewForm: local!viewForm), rule!viewGrid(viewForm: local!viewForm))

GRID INTERFACE:

a!cardLayout(contents: link: a!dynamicLink(saveInto: a!save(ri!viewForm, true)),

a!gridField(refreshOnVarChange: ri!viewForm, data: a!recordData(....))

FORM INTERFACE:

a!buttonWidget(saveInto: a!writeToDataStoreEntity(onSuccess: a!save(ri!viewForm, false)

  Discussion posts and replies are publicly visible

  • 0
    Certified Associate Developer

    Your grid in not refreshing because in refreshOnVarChange you directly passed rule input instead of local variable, refreshOnVarChange only works when a local variable change. See the definition below.

    refreshOnVarChange (Any Type): Refreshes the grid data each time any of these specific variables change. This allows you to refresh the grid data when a variable that is not referenced in the grid configuration is updated. You can define either using a single variable (e.g. refreshOnVarChange: local!var1) or a list of variables (e.g. refreshOnVarChange: {local!var1, local!var2}).

    Solution 1- 

    In the grid interface you have to save ri!viewForm value in a local variable, and also set that if ri!vewForm in null then it set fasle, else true, and then use that local variable in refreshOnVarChange.

    Solution 2- 

    If you are not wanna go with Solution 1 approach, then you have to to remove the child interfaces and code both the form and grid interfaces itself into a parent interface in the if condition and now you can use local!viewForm into refrehOnVarChange Directly.

    Please let me know if the solution works for you, thanks
  • 0
    Certified Lead Developer
    in reply to pranjalj6261

    Thanks for your reply. I updated the code, but it does not work. Here is the update.

    GRID INTERFACE

    local!viewForm: if(a!isNullOrEmpty(ri!viewForm), false, true),

    a!gridField(data: refreshOnVarChange: local!viewForm, data: a!recordData(....))

  • 0
    Certified Lead Developer

    SOLVED: I solved this issue by creating a counter variable and using the counter variable for the refreshOnVarChange rather than the boolean. I still do not understand why the boolean didn't cause the refresh. The boolean definitely was being updated and worked to display the correct interface. If anyone understands why the boolean didn't work, please let me know.

    Below are the changes I made to get the code to work:

    PARENT INTERFACE:

    local!viewForm: false,

    local!refreshCounter: 0,

    if(

    viewForm,

    rule!myForm(viewForm: local!viewForm, refreshCounter: local!refreshCounter),

    rule!viewGrid(viewForm: local!viewForm, refreshCounter: local!refreshCounter),

    )

    GRID INTERFACE:

    a!cardLayout(contents: link: a!dynamicLink(saveInto: a!save(ri!viewForm, true)),

    a!gridField(refreshOnVarChange: ri!refreshCounter, data: a!recordData(....))

    FORM INTERFACE:

    a!buttonWidget(

    saveInto: a!writeToDataStoreEntity(

    onSuccess: {

    a!save(ri!viewForm, false),

    a!save(ri!refreshCounter, ri!refreshCounter +1)

    }

    )

    )