Wednesday, February 07, 2018

How do I Refresh a Region or Report after a Dialog is Closed?

I was going to write this blog post back in December 2017, as this question comes up frequently.  And even though there are numerous examples available in the Sample Database Application and other sample applications, and it's even in the documentation, the solution still isn't always readily apparent.

I received this question from an internal employee today:
"When I edit the page and update the row and save and close the modal page, existing report doesn't refresh the page with revised value.   It was working on another page, but not working on this new page (I built last week).  Couldn't find a way to refresh it as soon as I close the modal window with saved data."
He has a report and a form in his application, and the form opens up in a modal dialog.  He simply wants the report on the parent page to refresh after the modal dialog is closed.  Simple, right?



For anyone well-versed in APEX, you'll find this blog post superfluous.  But for everyone else who is looking for the quick explanation, as I've received this question 3 times in the past couple months, here it is.

  1. On the report page, create a new Dynamic Action and enter the following attributes:
    • Name: <provide a meaningful name>
    • Event: Dialog Closed
    • Selection Type: Region
    • Region:<choose your report region>

  2. Select the True action of the Dynamic Action and enter the following attributes:
    • Action: Refresh
    • Selection Type: Region
    • Region: <choose your report region>

That's really all there is to it.  If you have multiple regions on the parent page, you could add multiple True actions for the dynamic action.  If the triggering event of the modal dialog is a button instead of a region, you could specify that as your Selection Type for the triggering event.  If there are multiple regions on the page which could open the modal dialog, you could even use a jQuery Selector and reference multiple elements as your Selection Type for the triggering event. 

For example, if you're converting a non-modal form and report to use a modal form, and you wish to refresh the report after the modal dialog is closed (after creating a new record), you'll need to associate the triggering event with the button.  The steps would be:
  1. On the report page, create a new Dynamic Action and enter the following attributes:
    • Name: <provide a meaningful name>
    • Event: Dialog Closed
    • Selection Type: Button
    • Region:<choose your button, for example, your Create button>

  2. Select the True action of the Dynamic Action and enter the following attributes:
    • Action: Refresh
    • Selection Type: Region
    • Region: <choose your report region>

You should get this behavior out of the box when creating an application with a report and form, or adding a report and form to your application.  But if you're manually adding components, then it's really quite easy and straightforward to add this functionality to your APEX app.

If you install the Sample Database Application, you'll find numerous examples of this dynamic action refresh operation after the close of a modal dialog.  And it is briefly documented in this tip.

1 comment:

Unknown said...

Great note - this basic stuff i usually confusing for beginners :)
I would add, that this will work only on Report type Regions with "Partial page refresh" option set in Reports attributes. This is a common mistake that I'm seeing - either developer tries to refresh non Report region or the "Partial page refresh" is not set.

Regards,
piotr