Skip to main content

APEX Interactive Report: Adding a Clickable Icon to perform actions - Part 1

Updated 4 min readMarkdown
APEX Interactive Report: Adding a Clickable Icon to perform actions - Part 1

In this blog, I explained how to add a clickable icon to an interactive report column and redirect to a page. However, sometimes, we need the icon to perform a specific action when clicked on icon. This is particularly handy, especially for carrying out bulk operations. For example, in my project, we needed to create a feature for the warehouse where users could mark products as received while receiving the delivery of the shipment.

Let's explore how to achieve this.

For this demonstration, I'm using the OEHR_PRODUCT_INFORMATION table. To keep things simple, I've added a Status column to the table, which we'll update when the icon is clicked.

First, we have to create a report using query.

Next, modify the attributes of the newly added MARK_AS_RECEIVED column as follows:

  • Type: Link

  • Heading: Update

  • Alignment: Center

  • Column Alignment: Center

  • Link:

    • Type: URL

    • URL: javascript:void(null);

  • Link Text:

      <span class="t-Icon fa fa-gears markReceived" data-id=#PRODUCT_ID#  aria-hidden="true"></span>
    

    Note: I used the "markReceived" class, which we'll use later as jQuery selector and I added a custom attribute called "data-id" to store the product Id. Later on, we'll use both of these values in the dynamic action to update the product's status.

Save the changes and run the report. Now, you'll see a new column called "Mark As Received" in our report with the gear icon. However, clicking on it won't do anything yet; we still need to add a dynamic action to update the status.

Now, to create Dynamic Action on click of the icon, go to the Dynamic Action tab and create a new dynamic action for a Click event.

  • Name: Mark Product as Received

  • Event: Click

  • Selection Type: jQuery Selector

  • jQuery Selector: .markReceived

markReceived is the same class we used above in the link text attribute prefixed by a dot (“.”)

Create a hidden item P4_PRODUCT_ID.

Next, we will create three True Actions: One is to get the product id and store it in a P4_PRODUCT_ID hidden item, the second is to update the status of the product and mark it as received, and the third is to refresh the report.

  1. Get Product Id

    • Name: Get Product Id

    • Action: Set Value

    • Set Type: JavaScript Expression

    • JavaScript Expression: $(this.triggeringElement).data('id')

    • Selection Type: Item(s)

    • Item(s): P4_PRODUCT_ID

    • Fire on Initialization: No

      JavaScript Expression $(this.triggeringElement).data('id') is used to get the value of custom data attributes (e.g., data-id) set on the selected element( in this case, the triggering element is the icon on which we click and it will give use the product it that we have set above using data-id custom attribute)

  2. Update Product Status

  • Name: Update Product Status

  • Action: Execute Server-side Code

  • Language: PL/SQL

  • PL/SQL Code:

    •                     UPDATE OEHR_PRODUCT_INFORMATION
                          SET status = 'Received'
                          WHERE product_id = :P4_PRODUCT_ID;
      
  • Items to Submit: P4_PRODUCT_ID

  • Fire on Initialization: No

  1. Refresh Report
  • Name: Refresh Report

  • Action: Refresh

  • Selection Type: Region

  • Region: Receive Products

  • Fire on Initialization: No

That's it.

Now when you click on the gear icon in the "Mark as Received" column, it will update the status of the product in the table and mark it as 'Received'.

But wait!!!!!!

You may have observed that the dynamic action only functions once when the page is loaded, and then it doesn't work again when you try to click on icons to mark other products as received. Upon reloading the page, it works once more before stopping again.

This happens due to the Event Scope settings of the Dynamic Action.

When you create a dynamic action, the default event scope is "Static." To ensure it functions correctly in our scenario, you need to set it to "Dynamic."

Check this blog for the detail explanation about event scope.

And finally, we are done!!

Now, when you click on the icon, you'll notice that the product status updates to "Received."

Everything is functioning correctly as expected, but users can still see the icon on the report even after receiving the product and can click it repeatedly to mark the product as received over and over again. This is not a good design and user experience.

Let's revise our requirement: Instead of having separate columns for "Status" and "Mark as Received," let's merge them into a single column. We'll display a "check" icon if the product has been received, and a "gear" icon if it hasn't.

Check the next blog post where we'll dive into how to implement this.

No comments yet. Be the first to comment.