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
Add new customer


How it works

  • 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.
  • The example below uses an execute-entity action and maps both the parameters of the
    
    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

The

 function below is listed twice, once for executing a stored procedure and once for executing a query.

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.

create-customer.jigx


A 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.

create-customer.jigx


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
    
    ,
    
    will navigate to the newCustomer
    
    .
  • A new customer id is created and used as a parameter in the GoTo action. The customerId parameter is passed to the newCustomer
    
    . 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
    
    .
  • 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. 
listCustomers.jigx


The new customer jig

  • 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.
newCustomer.jigx