Create a customer (INSERT)
Best practice for production apps is to use REST as the data layer to access data and not directly integrate to SQL using the SQL data provider. The SQL data provider will be squiggled in blue to indicate it is not recommended, together with a message to use REST instead. See REST endpoints from Azure SQL for more information.
Scenario
This example uses a default jig with a form that executes an SQL command to create a new customer record.
Resources
Scripts for creating Azure SQL tables and stored procedures: Database Scripts.
This sample depends on List customers (SELECT).
Jigx Code
The Azure SQL Docs solution is on GitHub.

How it works
The
execute-entityaction 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.The example below uses an
execute-entityaction and maps both theparametersof the jig function and the SQLite data in the action's configuration.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.
Functions
A store procedure-based version of create-customer.jigx
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.
# Jigx SQL function executing a stored procedure to create a new customer record.
provider: DATA_PROVIDER_SQL
connection: customer.azure # Use manage.jigx.com to configure a SQL connection
method: execute #Use SQL stored procedure to interact with the data in SQL
query: |
procedure: sp_InsertOrUpdateCustomer
# The stored procedure parameters are automatically populated by Jigx with the
# matching function parameters.
parameters:
CustomerId:
type: string
location: input
required: true
FirstName:
type: string
location: input
required: true
LastName:
type: string
location: input
required: true
Email:
type: string
location: input
required: true
PhoneNumber:
type: string
location: input
required: true
AddressLine1:
type: string
location: input
required: true
AddressLine2:
type: string
location: input
required: false
City:
type: string
location: input
required: true
ZipCode:
type: string
location: input
required: true
State:
type: string
location: input
required: true
Country:
type: string
location: input
required: trueA query-based version of create-customer.jigx
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.
Jigs
Modify the list customers jig
The listCustomers.jigx file must be modified to include a jig-level action, allowing a new customer to be added.
When pressing the Add customer action button at the bottom of the list customers jig, Jigx will navigate to the newCustomer jig.
A new customer id is created and used as a parameter in the
GoToaction. ThecustomerIdparameter is passed to the newCustomer jig. The generated id is used as the unique identifier when creating both the SQLite record and the new record in Azure SQL in the newCustomer jig.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.
The new customer jig
Use an
execute- entityaction 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
falseto avoid seeing the dialog even when data has been saved.
Last updated
Was this helpful?