Update customer details (PUT)
Scenario
Add the ability to update a customer's details by pressing on the customer in the list of customers which loads that specific customer's details in a form. You can edit the fields and press the Update Customer button.

How does this work
The customer details are loaded using the customer id as the inputs from the list-customer jig. An update function to call the REST APIs PUT operation is configured. The function and function parameters are referenced in the execute-entity action in the jig, which will update the customer's details when the Update Customer button is pressed on the form. A Post operation is performed in the REST service.
REST API
URL
https://[your_rest_service]/api/customers
Operation/Method
PUT
Function
The REST APIs PUT operator is used in a Jigx function with body parameters to specify the exact columns to be updated for the record. The inputTransform specifies how the data should be structured or formatted when being sent to the REST service. This transformation process ensures that the data adheres to the expected schema or format required by the REST service for processing the request.
provider: DATA_PROVIDER_REST
# Updates data in the REST Service.
method: PUT
# Use your REST service URL.
url: https://[your_rest_service]/api/customers
# Direct the function call to use local execution between the mobile device
# and the REST service.
useLocalCall: true
format: text
parameters:
accessToken:
location: header
required: true
type: string
# Use manage.jigx.com to define credentials for your solution.
value: service.oauth
id:
type: int
location: body
required: true
firstName:
type: string
location: body
required: true
lastName:
type: string
location: body
required: true
companyName:
type: string
location: body
required: true
address:
type: string
location: body
required: false
city:
type: string
location: body
required: false
state:
type: string
location: body
required: false
zip:
type: string
location: body
required: false
phone1:
type: string
location: body
required: false
phone2:
type: string
location: body
required: false
email:
type: string
location: body
required: false
web:
type: string
location: body
required: false
region:
type: string
location: body
required: false
customerType:
type: string
location: body
required: false
jobTitle:
type: string
location: body
required: false
#Define the customer data that must be updated
# in the record in the REST Service.
inputTransform: |
{
"custId": id,
"firstName": firstName,
"lastName": lastName,
"companyName": companyName,
"address": address,
"city": city,
"state": state,
"zip": zip,
"phone1": phone1,
"phone2": phone2,
"email": email,
"web": web,
"region": region,
"customerType": customerType,
"jobTitle": jobTitle
}Action (global)
Create a load-data.jigx file under the actions folder. This file is configured with an action that syncs the data from the REST service, by calling the function, to the local Sqlite table. The action file is referenced in the index.jigx file to load the data when the app is opened or is in focus on the device.
Jig (screen)
On the list of customers jig configure an
on-pressaction in theswipable: leftevent that adds the View button to the list and links to the update-customer jig.Add a form component to load the customer details with each field's instanceId containing the same name as the body parameters in the function.
For the state field configure a dropdrown with an expression to get the list of states for selection.
Configure an
initialValueproperty for each field in the form using an expression to return the customer data for that field.Add an
execute-entityaction to call the function that will update the customer record in the local table (usingmethod: update) and in the REST service (function: rest-update-customer). Use an expression to specify the value for each of the function's parameters. Note that the customer id already exists and the expression forid:uses theinputsagain to specifiy the customer record that must be updated. Theparametersupdates the record in the REST service, while thedataproperty updates the record in the local database.
Index
For performance and offline support the data is synced from the REST service as soon as the app is opened or receives focus. This is achieved by calling the global action in the OnFocus and onLoad events.
Last updated
Was this helpful?