Actions

sync-entities

4min

This action can be used to sync your local database with your live database on the server. There are multiple ways to set up a sync-entities action within a

:

  1. Under action button
  2. In action list
  3. In onPress/onChange events (if the component has these options)
  4. In onRefresh/onFocus
  5. Dynamically sync multiple entities

sync-entities can't be used if you using Static Data.

Examples and code snippets 

sync-entities in action

Sync-entities action
Sync-entities action


In this example, when tapping the Sync entities button the action.sync-entities is used to show a list of employees.

Example: The full example of sync-entities in action you can find in GitHub.

sync-entities-action.jigx


sync-entities in the action list

sync-entities action
Sync-entities action


In this example the action.sync-entities is used to linkt to the a different

.

Example:

The full example of sync-entities in an action list you can find in GitHub.

sync-entities-actionlist.jigx


sync-entities in onPress/onChange event

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

Example:

The full example of sync-entities in onChange you can find in GitHub. The full example of sync-entities in onPress you can find in GitHub.

sync-entities action with onPress
Sync-entities action with onPress

sync-entities-onPress.jigx
sync-entities-onChange.jigx


sync-entities in onRefresh/onFocus

sync-entities action with onRefresh
sync-entities action with onRefresh


Example:

See the full example of sync-entities on onRefresh action in GitHub.

If you want to use onLoad or onFocus just change the onRefresh to onLoad or onFocus.

sync-entities-onRefresh.jigx
sync-entities-onFocus


Dynamically sync multiple entities

When building a solution, the number of entities to sync and the parameters for each are not always known; for example, when syncing the attachments, files, or documents for a message, there can be zero, one, or more. It is necessary to dynamically specify a list of the entities, functions, and function parameters to return from the database using an expression.

Considerations

  • The expression is specified in the action.sync-entities action either as a local action in the
    
    or as a global action.
  • Dynamic sync-entities apply to the REST, OneDrive, and Salesforce data providers.
  • Any of the following can be synced dynamically: entity, functions, and function parameters.

Expression structure

  • The basic expression structure is =$.map(array, function).
    • Specify the array you will consult, i.e., a datasource @ctx.datasources.{datasourceName}.
    • For the function, specify ($item).
    • Example of the basic structure =$map(@ctx.datasources.{datasourceName}, function($item)).
  • After defining the basic structure, map out relevant properties from the array to the relevant entity/function/parameters and specify the dynamic entry using the $.item property, e.g., "calenderId": $.item.id. This will run through all the records in the datasource and perform a sync-entities action for each record in the table.
sync-entities-action


Example sync-entities dynamically for calendars (full input source)

To return all records from the input source use $item.id. In this example, a

 has two lists; the first list shows all the user's calendars, and the second list uses the ids from the first list to return all the events for all the calendars. A summary component shows a count of the number of events.

Sync calendars and events
Sync calendars and events

full-calendar-list
sync-dynamic-ds-rest
get-calendar-event-list


Example sync-entities dynamically for a selected calendar

To return all records for a selected calendar use =$map(@ctx.action.parameters.selected, function($item) in the global action. In this example, a

 has a dropdown to select the calendar and a Show events button syncs the entries in the selected calendar. A summary component shows a count of the number of events in the selected calendar.

Sync events for the birthday calendar
Sync events for the birthday calendar

my-events
sync-dynamic-selected-rest
get-calendar-event-list




Updated 24 Jul 2024
Doc contributor
Did this page help you?