Update customer details (PUT)
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.
The customer details are loaded using the customer id as the inputs from the list-customer . 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 , 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.
This code sample builds upon the previous List customers (GET) step, to develop a complete and functional solution.
REST | Detail |
URL | https://[your_rest_service]/api/customers |
Operation/Method | PUT |
The REST APIs PUT operator is used in a 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.
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.
- 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 initialValue property for each field in the form using an expression to return the customer data for that field.
- Add an execute-entity action to call the function that will update the customer record in the local table (using method: 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 for id: uses the inputs again to specifiy the customer record that must be updated.
For performance and offline support the data is synced from the REST service as soon as the app is opened or recieves focus. This is achieved by calling the global action in the OnFocus and onLoad events.