Refresh Interactive Grid after save

This article discusses how to ensure an Interactive Grid (IG) refreshes only after a successful database update when using a Dynamic Action triggered by the Save event. It explains the problem of unwanted refresh prompts due to validation errors and provides a solution by using a Client-side Condition that checks if the `status` attribute within the data object is "success" before executing the refresh.

Sometimes when we do an update on a table on the client side, an update on the database side has to be done. For example, a table containing information about things that are valid in a certain period.

When a new row is entered in the table, with a start date of November 1st, we want the previous row to have an end date of November 1st automatically. This can be done in the Save process of the Interactive Grid, or in a database trigger. In a default Interactive Grid, the grid is unaware of the changes, so the changed row with start date October 1st and end date November 1st is not shown.

The solution is to add a Dynamic Action, acting on the Save [Interactive Grid] event. This event is triggered when the IG is saved.

As Action we execute a Refresh of the IG region.

As a result the updated data is shown directly after a save:

A problem arises when we try to save, but due to a validation error the data are not saved. Because the Save button is pressed, the Save event is triggered, and the grid tries to refresh. But there still is changed data, so a popup shows, asking if we want to continue.

So how can we solve this? We would expect that some condition on the Dynamic Action could be the solution, but what to put in there? A hint is given by the help text on the Client-side Condition JavaScript Expression:

There are some attributes related to the Dynamic Action, but from here it is not apparent if some attribute gives information about an error that is or is not raised. But if we look at the debug information in the browser console, we can see more information about the Dynamic Action:

Here we see that within the data attribute, there is a status attribute that has the value “success”. If we press the Save button with invalid data entered, raising an error, we can see the status attribute filled with the value “fail”.

So now we have the solution: only execute the Dynamic Action when the status is “success”, so the IG is refreshed only after a successful Save. We have to put in a Client-side Condition with the expression

this.data.status == 'success'

The Dynamic Actions with and without the Client-side Condition can be replayed at https://apex.oracle.com/pls/apex/r/kwintup/put-post-blog/refresh-ig-after-save (login with demo/andre).

1
Subscribe to my newsletter

Read articles from André van der Put directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

André van der Put
André van der Put