Autorun AI Docs

3. Get Record


get(slug, options?)

async · returns { records, totalCount, rowCount }

Reads records from an entity, with optional filtering, sorting, and paging.

Prop

Type

const result = await context.functions.get("clients");

log(result.records.length);  // up to 100
log(result.totalCount);      // how many exist in total

Returned value

Prop

Type

{
  "records": [
    { "ID": 1, "Name": "Acme Corp", "Email": "contact@acme.com", "IsActive": true },
    { "ID": 2, "Name": "Globex Inc", "Email": "info@globex.com", "IsActive": true }
  ],
  "totalCount": 254,
  "rowCount": 2
}
get() returns 100 records, not all of them

take defaults to 100. On an entity with more rows than that, get(slug) silently returns the first page — no error, no warning. Compare records.length against totalCount, and either raise take or page through the results.

const page = await context.functions.get("clients", { pagination: { skip: 0, take: 1000 } });
if (page.rowCount < page.totalCount) {
  log("Still " + (page.totalCount - page.rowCount) + " records unread");
}

Records are flat objects keyed by column name. There is no Attributes wrapper. Lookup fields arrive expanded as objects, and dates arrive as strings.


getById(slug, id)

async · returns object | null

Reads one record by primary key. Resolves to null when nothing matches — it does not throw.

Prop

Type

const product = await context.functions.getById("products", 42);
if (!product) throw new Error("Product 42 no longer exists");

log(product.Name);

Unlike get, this returns the record itself rather than a wrapper. Lookups, lookup arrays, and multi-select fields are all expanded.


Filtering

A filter is either a single condition or a group.

const pending = await context.functions.get("orders", {
  filter: { field: "Status", operator: "equal", value: "pending" }
});

A group has a condition and a predicates array.

const mine = await context.functions.get("servicesbought", {
  filter: {
    condition: "AND",
    predicates: [
      { field: "Client", operator: "equal", value: context.claims.userId },
      { field: "Status", operator: "equal", value: "1" }
    ]
  },
  pagination: { skip: 0, take: 50 }
});

Predicates may themselves be groups, so any boolean expression is possible.

// Status = open AND (Priority = high OR Amount > 10000)
const urgent = await context.functions.get("tickets", {
  filter: {
    condition: "AND",
    predicates: [
      { field: "Status", operator: "equal", value: "open" },
      {
        condition: "OR",
        predicates: [
          { field: "Priority", operator: "equal", value: "high" },
          { field: "Amount", operator: "gt", value: 10000 }
        ]
      }
    ]
  }
});
The keys are condition and predicates

A group is recognised by the presence of predicates. Legacy code used { operator: "and", filters: [...] } — those keys are ignored, and the filter silently degrades to matching everything. There is also no isComplex flag; if you still pass one it is harmless but does nothing.


Filter operators

Operator names are case-insensitive, and most have a short alias. An unrecognised operator silently falls back to equal rather than raising an error, so check your spelling.

OperatorAliasesMeaning
equaleqEqual to
notEqualneq, neNot equal to
greaterThangtGreater than
greaterThanOrEqualgte, geGreater than or equal
lessThanltLess than
lessThanOrEquallte, leLess than or equal
likecontainsContains substring
startsWithswBegins with
endsWithewEnds with
in—Matches any value in a list
notInninMatches none of a list
all—Multi-select only: row has every listed value
isNullnull, is_nullValue is empty
isNotNullnotNullValue is set

For in, notIn, and all, pass an array as the value:

const active = await context.functions.get("orders", {
  filter: { field: "Status", operator: "in", value: ["pending", "processing", "shipped"] }
});

isNull and isNotNull ignore value — omit it.


Sorting

Sorting is single-field. Three forms are accepted:

// 1. A string: "Field_direction"
sort: "CreateDate_descending"

// 2. An object
sort: { field: "Amount", direction: "descending" }   // "name" also works instead of "field"

// 3. An array — the first usable entry wins, the rest are ignored
sort: [{ field: "Amount", direction: "descending" }]

Any direction beginning with desc counts as descending; anything else is treated as ascending. Without a sort, results come back newest first (CreateDate descending).

Passing several entries in the sort array does not produce a multi-column sort — only the first is applied.


Searching

searchTerm runs a free-text match across the entity's searchable fields and combines with filter:

const results = await context.functions.get("clients", {
  searchTerm: "acme",
  filter: { field: "IsActive", operator: "equal", value: true },
  pagination: { skip: 0, take: 20 }
});

Paging through everything

const all = [];
let skip = 0;
const take = 500;

while (true) {
  const page = await context.functions.get("orders", {
    filter: { field: "Status", operator: "equal", value: "pending" },
    pagination: { skip: skip, take: take }
  });

  all.push(...page.records);
  if (all.length >= page.totalCount || page.rowCount === 0) break;
  skip += take;
}

log("Read " + all.length + " orders");

Keep an eye on the process timeout when looping — raise it with @timeout if needed.