execute-entity

Execute-entity can save, update, or delete data in a single row from a database, depending on the chosen method. Each datasource type (Dynamic / SQL / REST) will have a different syntax for updating, saving, and deleting data.

For the Dynamic datasource, values will be saved under the data option. For SQL/REST datasource, values will be saved under the Parameters option.

Configuration options

An execute-entity action can be used in multiple areas:

  1. Under the action button

  2. In action list

  3. In onPress/onChange events (if the component you are setting up has these options)

  4. In onRefresh/onFocus

Offline remote data handling

Dealing with offline remote data is fundamental to ensuring data synchronization and consistency between the mobile app and the remote data source, allowing users to continue using the app and performing actions without interruption. Offline remote data handling explains how to configure solutions to deal with data when the device is offline using the queueOperations property available in execute-entities and provides examples and code samples.

Examples and code snippets

Execute-entity in action

Execute enitity
Execute enitity

In this example, execute entity is used in action with the create method. This example results in creating a new record with the First name, Last name, Email, and Phone number information. Execute entity is called by the press of the Save details button on the bottom.

Example: See the full example of execute-entity in GitHub.

execute-entity-action
actions:
  - children:
      - type: action.execute-entity
        options:
          title: Save details
          provider: DATA_PROVIDER_DYNAMIC
          method: create
          entity: default/form
          data:
            firstname: [email protected]
            lastname: [email protected]
            email: [email protected]
            phone: [email protected]
          onSuccess:
            type: action.go-back

Execute-entity in action list

Execute entity in action-list
Execute entity in action-list

By pressing the Save details button the execute-entity action will be followed by the go-to action.

Examples: See the full example of execute-entity in GitHub.

execute-entity-action-list
actions:
  - children:
      - type: action.action-list
        options:
          isSequential: true
          title: Save details
          actions:
            - type: action.execute-entity
              options:
                provider: DATA_PROVIDER_DYNAMIC
                method: create
                entity: default/form
                data:
                  firstname: [email protected]
                  lastname: [email protected]
                  email: [email protected]
                  phone: [email protected]
            - type: action.info-modal
              options:
                modal:
                  title: Details successfully saved
                  buttonText: View list
                  element:
                    type: icon
                    icon: cog-approved
                    color: primary
                onConfirmed:
                  type: action.go-to
                  options:
                    linkTo: ja-execute-entity-onPress

Execute-entity in onPress/onChange event

Execute-entity in onPress
Execute-entity in onPress

Here is the example of execute-entity in onPress/onChange event in list-item.

Examples: See the full example using onChange in GitHub. See the full example using onPress you in GitHub.

item:
  type: component.list-item
  options:
    title: [email protected]
    subtitle: [email protected]
    description: =(@ctx.current.item.modify = 0 ? 0 :@ctx.current.item.modify) & ' time/s changed.'
    leftElement:
      element: avatar
      text: ""
      uri: [email protected]
    onPress:
      type: action.execute-entity
      options:
        provider: DATA_PROVIDER_LOCAL
        method: update
        entity: default/employees
        data:
          id: [email protected]
          modify: =($number(@ctx.current.item.modify) + 1)

Execute-entity in onRefresh/onFocus

Execute entity
Execute entity

Here is the example of execute-entity in onRefresh/onFocus.

See the full example using onRefresh in GitHub. See the full example using onFocus in GitHub

onRefresh:
  type: action.execute-entity
  options:
    provider: DATA_PROVIDER_DYNAMIC
    method: update
    entity: default/employees
    data:
      id: [email protected]
      modify: [email protected] >= 10 ? 1 :($number(@ctx.datasources.employee-detail-dynamic.modify) + 1)

Deleting data using execute-entity

Here is an example of deleting different data using execute-entity. There are always 2 options for how you can delete a record:

  1. Using SQL Select

  2. Using JSONata function

In the first two examples, you can see the same situation where you are deleting all the records where the name equals Jane.

The third example shows how to delete the first 3 records from your datasource.

datasource:
  people:
    type: datasource.sqlite
    options:
      provider: DATA_PROVIDER_DYNAMIC
      entities:
        - entity: people
      query: |
        SELECT
          id,
          '$.name',
          '$.surname',
          '$.address'
        FROM [people] WHERE '$.name' LIKE 'Jane'

actions:
  - type: "action.execute-entity"
    options:
      entity: people
      method: delete
      provider: DATA_PROVIDER_DYNAMIC
      data:
        id: [email protected]

Last updated

Was this helpful?