Error retrieving elements of an ObjectSet

Hello! I have a basic filter, based on the documentation example that is not working as expected.

import { Objects, Farm } from "@foundry/ontology-api";
...
export class CommunicationsFunctions {
    @Function()
    public test(): Array<Farm> {
        const farms =  Objects.search()
            .farm()
            .filter(farm => farm.createdAt.range().gt(Timestamp.fromISOString('2000-01-01')))
            .all();

        return farms // farms = []
    }
}

I do have imported Farm as a Resource

Created At is a searchable Timestamp

We do have farms after 2000

If I remove the .all() I’m able to see that the dataset contains values

image

But I still need to interact with the ObjectSet in an array fashion, so I guess I can’t skip the .all()

Any ideas why a populated objectSet is returning 0 results on the .all()?

Thank you,
Tie

Hi Tie,

The code looks good, so there must be something else going on.

Do you get the same issue if you run the code below? If you just click on the “Select object set”-field and then click out of it, the entire set will be selected.

import { Objects, ObjectSet, Farm } from "@foundry/ontology-api";
import { Function, Timestamp } from "@foundry/functions-api";
...
export class CommunicationsFunctions {
    @Function()
    public test(farms: ObjectSet<Farm>): Array<Farm> {
        const farms =  farms.filter(farm => farm.createdAt.range().gt(Timestamp.fromISOString('2000-01-01'))).all();

        return farms // farms = []
    }
}

Also, just to double check – you have imported Function and Timestamp from functions-api?

Issue solved. I should have added a file reference at project level to the dataset used by the ontology.

I’ll leave this post as a reference for those in the same situation.
Also I have an open ticket asking for a error to be thrown by the @foundry/ontology-api informing the missing reference before producing that weird behavior. In case the error comes to production I’ll delete the post since it will be no longer necessary