...
Overview
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 save data in a table with a Stored Procedure.
Preconditions
Step 1: Create a Table
Open SQL Server Management Studio and run the following script:
Code Block | ||
---|---|---|
| ||
CREATE TABLE HelloWorld_UsersUsersDemo ( FirstName NVARCHAR(120), LastName NVARCHAR(120), DomainDescription NVARCHAR(128), UserDescription NVARCHAR(128), Email NVARCHAR(128), ) GO |
Once the table is created, automatically the ID attribute will be generated by default including the procedures to manage the information stored in the Database for this table. These are the set of store proceduresOne of the best Wayfast features is its Database framework which takes care of repetitive tasks to make Dev’s life easier and make development process super fast.
When a table is created Wayfast adds an ID attribute to make sure that consistency in the database can be enforced. At the same time it will create three stored procedures to manage classic CRUD operations: CREATE, REMOVE, UPDATE AND DELETE. After creating the aforementioned table you can see the following stored procedures in your DB:
spWF_HelloWorld_UsersUsersDemo_CreateOrUpdate
spWF_HelloWorld_UsersUsersDemo_Delete
spWF_HelloWorld_UsersUsersDemo_Get
For this example exercise we will use “spWF_HelloWorld_UsersUsersDemo_CreateOrUpdate
”.
Info |
---|
NOTE: Keep in mind that if you alter these stored procedures and then alter the table structure these SPs will be generated again and you will loose your changes. |
Let’s go back to Wayfast Editor and Update Wayfast DB Model.
...
A popup is displayed, click on “Synchronize” button. Now the stored procedure created in database will be available to connect with dataset.
...
Step 2: Setup the page
Let’s create a page called “HelloWorldUsers” before creating an action.
...
Click on “Submit” button and we are now ready to create the structure.
Step 3: Setup the Dataset & Controls
Our page should get the information from the table HelloWorld_UsersUsersDemo
using a dataset like we learnt in the latest lesson.
...
Navigate to “Data Binding” tab and point the Dataset to spWF_HelloWorld_UsersUsersDemo_Get
. This information will let the page to display automatically the information that we will insert using an action.
...
Click on “Submit” button
...
Let’s move to the controls that we need on this page to display and insert new users. We are thinking on the following structure according to the table that we created in the database:
LABEL: This control will display our header title
INPUTBOX: This control will allow us to insert data into our database. In this example, we are going to create 5 controls, 1 per each attribute in our
HelloWorld_Users
database table (FirstName, LastName, DomainDescription, UserDescription and EmailDescription)GRID_COLUMN: This control will display the values that we have stored into our database. Again, we repeat 1 per each attribute in our
HelloWorld_Users
database table (FirstName, LastName, DomainDescription, UserDescription and EmailDescription)BUTTON: This control will trigger the new user created and it should be connected to the “Insert” action that we are looking in the example
We can create one inputbox control for reference and then we can repeat the steps for the others needed. Select the “Inputbox” control and click on “New” button. A popup will be displayed to fill the information related to new control.
...
In each entry, we need to include the “HelloWolrdUsers” “HelloWorldUsersDemo” dataset and layout details where we can display the fields on page.
...
Click on “Submit” button and the control will be created. Repeat this step for each inputbox required.
...
Let’s add 1 grid column example to complete the page’s structure.
...
Again we need to include the “HelloWolrdUsers” “HelloWorldUsersDemo” dataset. These columns are going to retrieve the readable information from Database.
...
This button will be named as “Add New User”. In the example, everytime every time that user input the “FirstName”, “LastName”, “Domain”, “UserName” and “Email” data and then click on this button, the new data will be added in HelloWorld_UsersUsersDemo
table.
...
We can identify the “Link to Page” option in case we want to redirect the application to another screen or keep it open, in this example, we are going to continue showing the same page.
...
Finally we have the structure finished, click on “Preview” button and check what we created so far
...
How to include Actions in Controls?
We did a lot of work so far, now we are ready to learn the impact functionality that “Actions” feature make on the controls that we generated and how interact with our application.
...
Search for spWF_HelloWorld_UsersUsersDemo_CreateOrUpdate
in the “Stored Procedure” search field. Remember that this was created in database at the beginning of this lesson. Add the parameters “&FirstName”, “&LastName”, “&DomainDescription”, “&UserDescription” and “&EmailDescription” parameters that are connected to the database HelloWorld_UsersUsersDemo
table . One important thing to notice, Wayfast associate the entry parameters using an “&” sign instead “@” sign.
...
Complete the inputbox fields and click “Add New User” button to insert the new data on the HelloWorld_Users
table. If we check on the SQL, the new values are updated:
...
However, we are not able to see the data refreshed on screen. Let’s see what we can do in this case to make the inserted values on the page.
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.
...
Let’s test the app
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
...
Layout is displayed on screen with the input fields created and the button to add the new values in “HWD“HelloWorld_Roles” UsersDemo” table on database.
Following this the instructions, we can easily build and connect any form page to fill information in minutes.
...
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.