> For the complete documentation index, see [llms.txt](https://docs.jigx.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.jigx.com/examples/readme/actions/sync-actions/start-sync-scope.md).

# start-sync-scope

Action starts or restarts a specific sync scope. The scope completes once all defined sync-entity actions/datasources have finished.

## Examples and code snippets

* In this example, three entities (database tables) are synced using `action.sync-entities`, namely:
  1. earthquake (REST)
  2. hike (Dynamica Data)
  3. penguins ( Dynamic Data)
* The `action.start-sync-scope` is used to write the status of the database tables to the local **\_syncScope** table. In turn the **\_syncStatus** table is updated with the sync operation.
* A datasource is configured against the **\_syncScope** and **\_syncStatus** table, and the details are returned in a list (for visibility in this example).
* The `action.start-sync-scope`  is used to start the sync scope. The results of the sync operation is visible in the list.

{% tabs %}
{% tab title="start-sync-scope" %}

```yaml
title: Sync-scope examples
type: jig.default

children:
  - type: component.section
    options:
      title:
        text: Scope
        fontSize: medium
        color: color3
        isSubtle: false
        isBold: true
        numberOfLines: 1

      children:
        - type: component.list
          options:
            # Bind data from the sync-scopes datasource
            data: =@ctx.datasources.sync-scopes
            maximumItemsToRender: 8
            item:
              type: component.list-item
              options:
                # Display the sync scope state (syncing, synced, failed, interrupted)
                title:
                  text: =@ctx.current.item.state
                # Display the details JSON structure as subtitle  
                subtitle:
                  text: =@ctx.current.item.details
                  fontSize: regular
                  numberOfLines: 3
                # Show the sync scope ID on the right side of the list item  
                rightElement:
                  element: text


  - type: component.section
    options:
      title:
        text: Status
        fontSize: medium
        color: color10
        isSubtle: false
        isBold: true
        numberOfLines: 1
      children:
        - type: component.list
          options:
            # Bind data from the sync-status datasource
            data: =@ctx.datasources.sync-status
            maximumItemsToRender: 8
            item:
              type: component.list-item
              options:
              # Display the sync scope state 
                title: =@ctx.current.item.state
                # Display the datasource table that the state applies to.
                subtitle: =@ctx.current.item.entity
                # Add a tag to show the status of the sync-scope.
                tags:
                  - text: =@ctx.current.item.state
                    color: primary
                # Show the id of each sync scope status. The id is used in the action to
                # identify the sync status that must be deleted.     
                rightElement:
                  element: text
                  firstLine: =@ctx.current.item.id

actions:
  - numberOfVisibleActions: 3
    children:
      # Action to start a new sync scope.
      - type: action.start-sync-scope
        # Specify a unique identifier for this sync scope action. 
        instanceId: sync-all
        options:
          # List the individual instanceIds of each sync (sync-entities)
          # that the sync scope applies to.
          instanceIds:
            - sync-quakes
            - sync-enviro
          title: Start sync

```

{% endtab %}

{% tab title="sync-entities" %}

```yaml
onFocus:
  type: action.action-list
  options:
    isSequential: true
    actions:
      - type: action.sync-entities
        instanceId: sync-quakes
        options:
          provider: DATA_PROVIDER_REST
          entities:
            - entity: earthquakes
              function: earthquake-data
      - type: action.sync-entities
        instanceId: sync-enviro
        options:
          provider: DATA_PROVIDER_DYNAMIC
          entities:
            - default/hike
            - default/penguins
```

{% endtab %}

{% tab title="datasources" %}

```yaml
datasources:
  sync-status:
    type: datasource.sqlite
    options:
      provider: DATA_PROVIDER_LOCAL
      entities:
        - _syncStatus
      query: |
        SELECT
          id, 
          provider, 
          entity, 
          functionId, 
          timestamp, 
          state, 
          error
        FROM [_syncStatus]
        ORDER BY provider

  sync-scopes:
    type: datasource.sqlite
    options:
      provider: DATA_PROVIDER_LOCAL
      entities:
        - _syncScope
      query: |
        SELECT 
          id, 
          state, 
          timestamp, 
          lastSyncedAt, 
          lastStartedAt, 
          lastFailedAt, 
          notStarted, 
          syncing, 
          synced, 
          failed, 
          details 
        FROM [_syncScope]
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.jigx.com/examples/readme/actions/sync-actions/start-sync-scope.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
