Data Providers
...
REST
Create an app using REST APIs

Update multiple records in a single REST call

11min

Why would you want to update multiple records in a single REST call?

API Rate Limits - Many APIs enforce rate limits on the number of requests a client can make. Updating multiple records in a single call reduces the number of API requests made and avoids hitting rate limits.

Improved performance - Updating multiple records in a single call reduces the round-trip time between the client and server, improving overall performance.

How does this work

  • To update multiple records in a single REST call, use the execute-entities action to call the REST function.
  • It is important to know what method your function call is using. For example, using PUT will overwrite all values in the record, while using PATCH will only update the new or changed values in the record.
  • There are two ways to configure the execute-entities action.
    • Use functionParameters for values that must be evaluated statically across all the records.
    • Values that are dynamic per record are configured in the data property.
functionParameters
data

  • The properties defined in the data property are determined by the REST call. This means that if the only required property is id you can simply use id, such as: data: [email protected].{"id":id}[] However, if you have multiple required properties in the REST call you need to define all of them under data, such as: data: [email protected].{"id":id, "firstName":firstName, "lastName":lastName, "companyName":companyName}[]
  • Using JSONata expressions can further simplify updating mutiple records, for example, using the following expression will update all records in the customer list to Bronze. data: =ctx.datasources.customers ~> | $ | { "customerType": "Bronze "} | See the Jsonata transform operator for more information.

Scenario

This example lists all customers without a label (CustomerType property). Using the execute-entities action all customers without a label are updated to show a Bronze label.

Update multiple records
Update multiple records


How is this scenario configured

  1. The customer list is loaded from the customers datasource, the query returns all records WHERE customerType IS NULL.
  2. An execute-entities action is configured to update multiple records with a single REST call. The update function calls the REST APIs PATCH operation.
  3. The execute-entities action is configured using functionParameters to update the customerType property to Bronze. This is a static value and will be the same for all the customers in the list.
  4. The execute-entities action is configured using data to define the required REST properties for the customers' records. In this example, id, firstName, lastName and companyName are required parameters in the REST function.
  5. When the Update records button is pressed all customers with no customerType property (label) is updated to Bronze.

REST API

REST

Detail

URL

https://[your_rest_service]/api/customers

Operation/Method

PATCH

function

The REST APIs PATCH 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. Take note of the required parameters in the function as these are required in the data property of the execute-entities action.

rest-update-customer.jigx


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.

load-data.jigx


jig (screen)

  • Create a customers list jig where the customer datasource query is configured to return all customers with no label.
  • Add an execute-entities action to call the function that will update all the customer records in the local table (using method: update) and in the REST service (function: rest-update-customer). Define the functionParameter property to update the customerType property to Bronze. Configuring the data property is used to configure the properties that are required to update all records in the list.

An alternate option would be to use the following expression under data, removing the need for functionParameter: data: =ctx.datasources.customers ~> | $ | { "customerType": "Bronze "} |

update-customerType.jigx


index

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.

index.jigx