Data Providers
Microsoft Azure SQL
Create a customer (INSERT)
9min
Scenario
This example uses a default with a form that executes an SQL command to create a new customer record.
Resources
Jigx Code
The Azure SQL Docs solution is on GitHub.
Add new customer
- The execute-entity action allows you to specify the function parameters and their values, as well as the data properties for the SQLite table. You have more granular control over the values being saved and can include expressions.
- To improve the user experience, data displayed after it has been created or updated should be updated in the local SQLite database and the backend system in the same action.
- If the data is only submitted to the backend system, it must be synced back to the device before the local tables are updated, and the information can be displayed. This can cause a significant lag and latency in the user's experience.
- The example below updates the data in Azure SQL and the SQLite database on the device when the user presses the Save button. This is the best practice for building responsive user experiences when working with remote data. See the Data lifecycles in Jigx section of the documentation for a detailed explanation.
The stored procedure in the example was designed to create a new record in Azure SQL if no matching id is found. If the id already exists, the Azure SQL record is updated. The same stored procedure is used for creating a new customer and updating a customer.
The SQL query version of create-customer.jigx below only creates a new record. It does not contain update like the stored procedure above. The only reason for this difference is to provide an alternative example and SQL logic.
- The listCustomers.jigx file must be modified to include a jig-level action, allowing a new customer to be added.
- The id is used across the SQlite and Azure SQL tables to ensure that the record in the local SQLite customer table and Azure SQL customer table are in sync and have the same value.
- Use an execute- entity action to submit the values of the components to the SQL stored procedure and save the new customer to the local SQLite database.
- To save the values of the components on a form, the form is unaware of the saved state, and isDiscardChangesAlertEnabled needs to be set to false to avoid seeing the dialog even when data has been saved.
Updated 21 May 2024
Did this page help you?