You can use a Webhook and the API to copy data from an updated records to an existing record in another table.
This example uses two identical tables called "People" and "PeopleEcho". Both tables contains four identical fields named "Name", "Age", "DropDown", and "Count". Admittedly this example is simple and contrived, but it illustrates how you can use the same approach in more complex cases.
Every time an existing record is updated in the "People" table, the webhook is triggered. The webhook uses the API to update the corresponding record into the "PeopleEcho" table. This ensure that the two records have identical field values.
Do this as follows:
- Go to the Manage > Integrations > IN pane and enabled the input integration.
- Go to the Behavior > Workflow pane and add a "Webhook" rule.
- In the webhook "Target data" property choose the "People" table.
- In the webhook "Update event" property choose "UPDATES_ONLY".
- In the webhook "Url" property enter:
Where the App Id following "apps/" is the "App Id" from the Manage > Integrations > IN pane.
The value following "tables/" is the name of the target table. In this case, "PeopleEcho".
- In the webhook "HTTP Verb" property enter "Post".
- In the webhook "HTTP Headers" property enter:
Where the access key value is the "Access Key" from the Manage > Integrations > IN pane. The "Access Key" must be enclosed in quotes.
- Create a "JSON Body Template" that looks like this:
"Timezone": "Eastern Standard Time"
This JSON Body Template copies the value of the "Name" field of table "People" to the "Name" field of table "PeopleEcho". Ditto for the other three fields.
This example, is simply copying the entire record from "People" to "PeopleEcho" but you could do other things. You could copy a subset of the fields by omitting one or more field names from the JSON Body Template. Fields that you omit are not changed.
You must include values in the key fields of the updated table. These key values are used to locate the record to be updated.
Creating the JSON Body Template
If you click the "Create" button following the "JSON Body Template" property, AppSheet will create an initial JSON Body Template which you can then modify. The template is based on the fields of the table you specify in the "Target data" property.
The following technique can simplify template creation.
- Temporarily change the "Target data" property to the table you want to use for the template.
- Click "Save" to save the temporary change.
- Click the "Create" button to create the template.
- Restore the "Target data" property to its original value.
- Click "Save" to save all changes.