Retrieve more than one column from an object set using Typescript

How can you retrieve more than one column when searching an object set. I can return one column using filters etc. but I cannot see how to return more than one column. I want to return a list of regions, markets, submarkets and then use SET to obtain a distinct list. Thanks.

1 Like

You can retrieve more than one column from an Object type. Here’s an example three columns:
import { Function } from “@foundry/functions-api”;
import { Objects } from “@foundry/ontology-api”;

interface MultiColumnResult {
column1: string;
column2: number;
column3: Date;
}

export class MyFunctions {
@Function()
public async getMultipleColumns(): Promise<MultiColumnResult> {
try {
const result = await Objects.search()
.dataset(“:rid{value=“ri.foundry.dataset”}”)
.select(obj => ({
column1: obj.column1,
column2: obj.column2,
column3: obj.column3,
// Add more columns as needed
}))
.all();

  return result;
} catch (error) {
  console.error("Error in getMultipleColumns:", error);
  throw error;
}

}
}

Hope this helps

Hi – I tired the code below, but it does not allow me to use the “.dataset “
image

The only options after the Objects.search(). are the actual objects sets I imported. The error is “Property ‘dataset’ does not exist on type ‘ObjectSetsImpl’.typescript(2339)”

The code looks like this -
try {
const result = await Objects.search()
.dataset(“:rid{value=“ri.ontology.main.object-type.xxxxxx-xxxx-xxxx-xxxxxxx”}”)
.select(obj => ({

The functions and objects selections appear the same in my import statements – Any other suggestion you might have would be appreciated – Thanks.

The general shape of the proposed logic (create a struct interface and populate it from the results of an object search loaded with .all) is correct, but I’m not sure where the Object search syntax with a dataset and RID comes from - that isn’t part of the Functions ontology API and seems maybe like an LLM hallucination.

You can find the docs and simple examples of using the Objects search endpoint to filter and load a list of objects here.

It’d probably structure this as:

  1. Define an object set using the Objects().search syntax
  2. Load those objects with .all()
  3. Map through (can do this async if you like but probably fast regardless) each object and populate a struct, resulting in a list of structs with one per object.
  4. Return the list of structs
1 Like

Yep it refers to the dataset, if you want data from the Objec types (Object set) use:
const result = Objects.search()
.“Use the “API name” that you can find in the Ontology manager/ObjectType/overview”()
.select or…
.filter or…

An example: const result = Objects.search()
.sePlo()
.filter(plo => plo.projectId.exactMatch(var2))
.filter(plo => fpo.financialdate.range().gte(startDate).lte(endDate));

Hope this else otherwise let me know

Thanks - I was using the filter on the object set. I did create an interface and gave it 3 columns of string - the objects search retrieved the column data but all three gave me time out errors in addition to the 10K limit. I will have to use pipeline builder to create what I need unless there are other suggestions - Thanks all for your input.

1 Like