How to convert your spreadsheet to web application
Converting your spreadsheet to a web application: Actions and Events
Co-Author: Szabolcs Toth
In case you missed the introduction, you can begin your journey with APEX, by following this link: How to convert your spreadsheet to web application with APEX.
After creating your first APEX application you can begin interacting with the data in various ways, to help you get the most out of your application there are actions and events you can leverage to carry out a set of operations, more about those below.
Some of the available events are:
- Page Load - Triggered when the page is loaded
- Change - Triggered when there is a value change made
- Click - Triggered on a mouse click
- After Refresh - Triggered after the page is refreshed
- and the list goes on...
If the event condition is satisfied you can carry out an action, some of the available actions are:
- Show - Makes a certain element of the UI appear
- Close Dialog - Closes a modal dialog
- Set Value - Sets a value of a certain element/field
- Execute Java-Script/Server-Side Code
- and the list goes on...
With the above powerful combination of choosing when an event should be executed to selecting the correct action, you are able to achieve any scenario required for your business.
Creating a new Dynamic Action
When new vacations are taken, you want to dynamically adjust the remaining vacation days amount.
1. Create a Dynamic Action, by navigating to the left-side pane of the Page Designer.
2. After the dynamic action is created you can configure the conditions based on which the event is evaluated to True.
When:
Event: When is this event going to trigger?
Selection Type: What is the condition for the event to be triggered?
Items: Which items should trigger the event?
3. If the condition is met you can proceed to executing an action.
Then:
Action: What should be done once the “When” condition is evaluated to true.
PL/SQL Code:
BEGIN UPDATE PEOPLE SET REMAINING = REMAINING - :P5_TAKEN WHERE :P5_NAME = NAME;
END;
Items to Submit: Which fields do you want to commit to memory?
Items to Return: Which fields do you want to return that are affected by the executed code?
Note: The colon “:” is used to fetch the variable values from memory, you need to submit the values of these variables before using them.
If the Vacation “Taken” field changes, the amount of remaining vacation days is dynamically updated to reflect the current status, hence preventing additional manual work.
Action!
Now let’s see it in action by changing the number of days taken, the remaining vacation days will automatically be updated.
1. Open the People Report view and select any entry to be edited.
2. Set the Taken amount to 4.
Note: Since the PL/SQL is being executed when the value of days ‘Taken’ is changed, this means that the Submit button is not necessary to execute the code. This is important to understand in order to time all events correctly when designing your application.
3. After the changes are applied, we can see the reflected change in the Report.
That's it, the value is correctly changed to 17 by deducting 4 from 21.
Coming up:
In the next part of this series you will learn how to connect tables, scripts and events together using the knowledge obtained thus far to make the application more intuitive and user friendly!
That would be all for this chapter, stay tuned for new chapters every Monday!