sort_record_collection
Use this action to put the records of a record collection from an earlier action in order.
Read the live config shape of each action type from GET /v1/automation/meta/action before you build on it.
In the automation editor, this action is Sort collected records in the Record collections family. Its group is action, and it works with every trigger but needs an earlier action that creates the record collection.
Send it in the actions array of Create an automation or Update an automation. An update replaces the whole array, so include the other actions.
Example
An earlier action collected deals from database app 42. This action sorts them by Amount, highest first, and then by Close date:
{
"type": "sort_record_collection",
"config": {
"record_collection": { "kind": "variable", "source": "action", "action_type": "record_collection", "app_id": 42 },
"sorts": [
{
"variable_def": { "kind": "variable", "source": "field", "field_id": 4055, "field_type": "number", "previous": false, "collection": true, "triggering": false },
"direction": "desc"
},
{
"variable_def": { "kind": "variable", "source": "field", "field_id": 4061, "field_type": "single_date", "previous": false, "collection": true, "triggering": false },
"direction": "asc"
}
]
}
}
Config
| Property | Type | Description | Example value |
|---|---|---|---|
record_collection | reference | Required. The collection to sort, created by an earlier action. The schema lets you save without it, but validation then reports action_invalid. | { "kind": "variable", "source": "action", "action_type": "record_collection", "app_id": 42 } |
sorts | array of sort entries | The sort order, applied in the order given. Empty when left out. | [{ "variable_def": { … }, "direction": "asc" }] |
To find the field IDs for sorts, see App and field IDs.
Sort entries
Each entry in sorts is an object:
| Property | Type | Description | Example value |
|---|---|---|---|
variable_def | reference | Required. The field or record metadata to sort by. It must belong to the collection's database app, with "collection": true. | { "kind": "variable", "source": "field", "field_id": 4055, "field_type": "number", "previous": false, "collection": true, "triggering": false } |
direction | enum | Required. asc for ascending, desc for descending. | "desc" |
id | string | Stable ID of the entry. Tape creates one when you leave it out and returns it on read. | "sort-1" |
To sort by record metadata, use a meta reference with "collection": true: record ID (app_record_id), created on (created_at), created by (created_by), last modified on (last_modified_at) or last modified by (last_modified_by). For example: { "kind": "variable", "source": "meta", "meta_type": "created_at", "app_id": 42, "collection": true }.
General behavior
record_collectionhas no default. Without it, Tape saves the action, and validation reportsaction_invalid.- A
record_collectionwithout a matching earlier action fails validation withaction_variable_missing. - Without
sorts, Tape stores an empty list, and the action doesn't change the order. variable_defanddirectionare required in every sort entry. A missing one returns400.- A sort key outside the collection's database app fails validation with
action_variable_missing. - A
metasort key without"collection": true, or withrecord_id, fails validation withaction_variable_missing. - Tape applies the entries in order. Each later entry breaks ties of the entries before it.
- Tape sorts the collection in place. Later actions that reference it get the new order.
Requirements
- To add or change this action through the API, your token needs the
automations:editcapability. See Capabilities. - You must administer the workspace that the automation's database app belongs to.
- An earlier action in the automation must create the collection in
record_collection, for examplecollect_app_records.