...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
Overview
On this lesson, we will explain Actions in Wayfast. This are events that allow us to trigger application interactions including communicating with a database, an API or executing a DLL. In this example Wayfast Actions allow executing process or communicating with external systems incluiding databases, APIs or executing DLL methods. In this lesson we will review how to create an action to store information save data in a database.
How to create a Table and Stored Procedure in Project DB?
It’s important to reinforce the idea that all the Project’s information come from the database through Stored Procedures (SP) and these data is readable in the Application through the Controls. This document will show that there’s another way to interact with the DB information creating Actions that can modified the information in our database.
As precondition, we need to create a new table in SQL to verify the interaction between Dataset, Controls and Actions. table with a Stored Procedure.
Step 1: Create a Table
Open SQL Server Management Studio and run the following script:
Code Block | ||
---|---|---|
| ||
CREATE TABLE HWDHelloWorld_HR_RolesCandidates ( NameFirstName nvarcharNVARCHAR(50128), [Role]LastName nvarcharNVARCHAR(50128), Email nvarcharNVARCHAR(50128), Age SMALLINT ) GO |
This table has 3 columns “Name”, “Role” and “Email”. Then we can proceed to create a Stored Procedure related to “HWD_Roles” that will insert new values and consequently will select and display the new input information.
Code Block | ||
---|---|---|
| ||
CREATE PROCEDURE spHWD_Roles_Insert
@Name nvarchar(50),
@Role nvarchar(50),
@Email nvarchar(50)
AS
BEGIN
INSERT HWD_Roles(Name, [Role], Email)
SELECT @Name, @Role, @Email
END
GO |
Once that the new Table and Stored Procedure are created, we can go to Wayfast applicationWayfast database framework will automatically create a set of store procedures.
For this example we will use “spWF_HelloWorld_HR_Candidates_CreateOrUpdate”.
Let’s go back to Wayfast Editor and Update Wayfast DB Model.
Click on “End Task” button related to Project’s requirement.
...
A popup is displayed, click on “Synchronize” button. Now the stored procedure created in database will be available to connect with dataset.
How to create Controls to interact with Application?
Preconditions
Let’s review what are the necessary controls to make the interaction between the app and a database:
...
Turn to Layout tab and establish the order to display this control. We are going to place it next to the inputboxes. Click on “Submit” button
...
How to add Actions in Controls?
Wayfast allow us to create a new action at the same time that we create the control. Now that we have “Create” button, let’s edit the this control and create a new action. In the “Edit Control” popup, click on “Actions” tab
...
After completing the required fields, clicks on “Submit” button, the new action is linked to the “Button” control.
...
How to update Database with an Action?
One of the common scenarios in the interaction between dataset and actions is the one where the database is updated with new input values but it's not reflected on screen at the moment that was triggered. Let’s analyze what we need to check and how the new action is connected to the Dataset.
...
Let’s check the results in the example.
How the Application works after all the definitions?
Now that the page is setup with Dataset, Controls and Actions, we can verify that the interaction is working as expected. Wayfast allow us to make a preview by click on “Preview” button at the top right corner
...
Info |
---|
In case we want to verify that the functionality is working as expected in database, open the SQL Server Manager and check if the table has the new input values inserted through the app. |
Recap
In the first part, we revised the preconditions to create pages with a basic structure (dataset and controls) and then we learnt how to create new actions that can be related to these Controls previously added. In the second part, we verified how the interaction is executed in the application and how this can be edited to adjust the interaction regarding what we display and what we insert in the database.