2
votes

I have a page with two regions, an interactive report and a form.

I have a dynamic action on the report, when I click on a row, it sets the value of an item to the id of the row.

How can I refresh the form, to get the value related to the (Id) in item?

2

2 Answers

2
votes

As far as I know, form regions don't refresh, up to APEX 19.2 anyway. You'd probably want to use an Execute PL/SQL action to get the values for the form items. Here's a complete example.

  1. Create a new blank page. My page was 26. You'll need to update the following to the page number you have.
  2. Create a new region. Set Title to Employees, Type to Interactive Report, Table Name to EMP, and Static ID to emps-reg.
  3. Select the EMPNO column of the report and set Static ID to empno-col.
  4. Create another new region. Set Title to Employee Details, Type to Form, and Table Name to EMP.
  5. Select the P26_EMPNO item (created automatically after the last step). Enable the Primary Key setting under Source.
  6. Create a Dynamic Action. Set Name to Employee row clicked, Event to Click, Selection Type to jQuery Selector, jQuery Selector to #emps-reg table:eq(1) tr:not(:eq(0)), and Event Scope to Dynamic.

    Setting Event Scope to Dynamic will keep the Dynamic Action working after the report has been refreshed.

  7. Select the Action that was created by default in the previous step. Set Action to Set Value, Type to JavaScript Expression, and JavaScript Expression to $(this.triggeringElement).find('td[headers="empno-col"]').text().

    The JavaScript expression will start with the tr that was clicked and traverse down to the td element that has the employee's empno and return that value.

  8. Right-click the P26_EMPNO item in the form region and select Create Dynamic Action. This will create a Dynamic Action with the event settings correctly configured. Set Name to P26_EMPNO changed.
  9. Select the Action created by default in the previous step. Set Action to Execute PL/SQL Code, then enter the following code in PL/SQL Code:

    select ename, job, mgr, hiredate, sal, comm, deptno
    into :P26_ENAME, :P26_JOB, :P26_MGR, :P26_HIREDATE, :P26_SAL, :P26_COMM, :P26_DEPTNO
    from emp
    where empno = :P26_EMPNO;
    
  10. In the same action, set Page Items to Submit to P26_EMPNO. This will transfer the value in the primary key item to session state prior to executing your code.
  11. In the same action, set Page Items to Return to P26_ENAME,P26_JOB,P26_MGR,P26_HIREDATE,P26_SAL,P26_COMM,P26_DEPTNO. This will return the current values in session state to the items in the page.

Because you're populating the items via Ajax, you may need to add additional code for things that would normally be specified in the form item, like date or number formatting.

0
votes

You can create a Dynamic Action (DA), which triggers when the ID in the item is changed and then refreshes the form.

Create a DA. Set the "Event" of the "When" attribute of the DA to "Change", the "Selection Type" to "Item" and then select the item where you save your ID.

Set the True Action to "Refresh" and chose "Region" as "Affected Elements", then select the specific Region you want to refrseh, which is your form.

Now when the value of the ID item changes, the form will be refreshed.