Skip to Content

Functions

Execute Foundry functions (queries) with executeFunction, pass objects and object sets as parameters, and read struct, object, and object set results.

Foundry docsFunctions

Functions published to the Ontology, called queries in the API, appear in your generated SDK next to object types and actions. client(myFunction).executeFunction(params) runs one on the server and resolves to its typed return value.

The samples use these functions, which stand in for functions in your own SDK:

FunctionParametersReturns
countEmployeesNoneinteger
getEmployeeMetricsdepartment: stringStruct { headcount: integer }
summarizeTeamteam: ObjectSet<Employee>string
getTopEarnersdepartment: string, limit?: integerObjectSet<Employee>
getManageremployee: EmployeeEmployee

Execute a function

src/metrics.ts
import { countEmployees, getEmployeeMetrics } from "@my-app/sdk";
import { client } from "./client";

const total = await client(countEmployees).executeFunction();

const metrics = await client(getEmployeeMetrics).executeFunction({ department: "Engineering" });
console.log(`${metrics.headcount} of ${total} employees are engineers`);

executeFunction takes one object with a key per parameter, or no argument when the function has no parameters. Nullable parameters are optional. It rejects with a PalantirApiError when the function fails or times out on the server; see Errors.

If your SDK was generated with a pinned function version, the client calls that version. Otherwise it calls the latest published version.

Parameter values

Parameter typePass
PrimitiveA value of the parameter's TypeScript type. Dates and timestamps are ISO 8601 strings. long accepts a number or a string.
ObjectA loaded object, its primary key, or { $apiName, $primaryKey }.
InterfaceAn object loaded through the interface, or { $objectType, $primaryKey }, where $objectType is the concrete object type.
Object setAn object set, such as client(Employee).where({ ... }). The server receives its definition, not its objects.
List, setAn array, or a Set for set parameters.
StructAn object whose keys are the struct's fields.
MapAn object keyed by the map's keys. For object keys, use each object's $objectSpecifier.
AttachmentAn attachment RID, a File, or the result of createAttachmentUpload. The client uploads it first.
Media referenceA MediaUpload, a Media from an object, or a MediaReference.

Pass an object set to let the function work on a filtered set without loading it in the client:

src/summarize.ts
import { Employee, summarizeTeam } from "@my-app/sdk";
import { client } from "./client";

const summary = await client(summarizeTeam).executeFunction({
  team: client(Employee).where({ department: "Sales", startDate: { $gte: "2025-01-01" } }),
});

Return values

Return typeYou get
PrimitiveThe value. long is a string; dates and timestamps are ISO 8601 strings.
List, setAn array. Set results are typed Set<T> in the generated SDK but arrive as arrays; wrap them with new Set(result) before using Set methods.
StructA plain object.
MapA plain object keyed by the map's keys. Object keys become object specifier strings.
ObjectAn object reference with $apiName, $objectType, and $primaryKey. It has no properties.
Object setAn object set. Load it with fetchPage, asyncIter, or aggregate.
AttachmentAn Attachment. See Attachments and media.
Media referenceA Media. See Attachments and media.
Two-dimensional aggregation{ key, value }[]
Three-dimensional aggregation{ key, groups: { key, value }[] }[]
Nullable, when the function returns nothingundefined

Union return types are not supported: the client throws Union return types are not yet supported.

Object results

A returned object is a reference, not a loaded object. Load it by primary key to read its properties:

src/manager.ts
import { Employee, getManager } from "@my-app/sdk";
import { client } from "./client";

const employee = await client(Employee).fetchOne(12345);
const managerRef = await client(getManager).executeFunction({ employee });

const manager = await client(Employee).fetchOne(managerRef.$primaryKey, {
  $select: ["fullName", "jobTitle"],
});

Object set results

A returned object set is like any other. Filter, sort, page, and aggregate it before loading:

src/topEarners.ts
import { getTopEarners } from "@my-app/sdk";
import { client } from "./client";

const topEarners = await client(getTopEarners).executeFunction({ department: "Sales", limit: 10 });

const page = await topEarners.fetchPage({
  $select: ["fullName", "salary"],
  $orderBy: { salary: "desc" },
});

In React

useOsdkFunction from @osdk/react executes a function, caches the result by its parameters, and can refetch when objects it depends on change. See Functions in React.

On this page