How to access linked objects through typescript functions for Workshop?

Hi all,

I am trying to develop some typescript functions that I can expose to Workshop for my particular application.

At the moment, I am not understanding how to access linked objects through the typescript functions in my code repository.

An example of what I am hoping to do:

I have a notional “Constellation” ontology that has RSO’s linked to each entry based on the RSO id. So for instance, the MUOS Constellation has the MUOS 1-5 RSO’s linked to it.

What i’d like to be able to do is to pass in a single RSO (or object set of RSO’s) and return the linked Constellation object that it is associated with.

ex: If I pass in MUOS-1 (RSO), I should get out MUOS (single constellation object).

Any thoughts or suggestions on this would be greatly helpful!

Thanks,

Hi @brianpatrick3 , I don’t know the exact API names of the object types in your Ontology, but hopefully these examples can help serve as a starting point for what you need.

  1. Pass in a single RSO and return the singly linked Constellation object (note that the link access could be undefined if the RSO does not have a linked Constellation):
import { Function } from "@foundry/functions-api";
import { Constellation, Rso } from "@foundry/ontology-api";

export class MyFunctions {

    @Function()
    public getLinkedConstellation(rso: Rso): Constellation | undefined {
        // The linked Constellation is a property of the RSO.
        return rso.constellation.get();
    }
}
  1. Pass in an object set of RSOs and get all of their linked Constellations:
import { Function } from "@foundry/functions-api";
import { Constellation, ObjectSet, Rso } from "@foundry/ontology-api";

export class MyFunctions {

    @Function()
    public getLinkedConstellations(rsos: ObjectSet<Rso>): ObjectSet<Constellation> {
        // The generated method will begin with "searchAround".
        return rsos.searchAroundConstellation();
    }
}

Additionally, we have some docs here that expand on the different ways linked objects can be accessed.

@timurm

Thank you for the quick response! I was able to get this to work with Object links for 1 to 1 type.

I am not able to get this to work for a many to 1 link for some reason.

Here is a snippet of how the objects are setup with notional data:

Flanker Run:

Flanker Updates:

The following is the link that I have setup between the objects:

Lastly, the following is the code that I am trying to implement to get all of the FlankerUpdates from a single FlankerRun:

image

I am getting an error that "property flankerUpdate does not exist on type FlankerRun, even though the API for the link type seems to suggest it does.

If you see anything wrong with my setup, please let me know.

Thanks in advance!

UPDATE:

The missing piece here was that when you import an ontology using the resource imports menu, you ALSO have to import the link between the ontologies that you want to traverse in the typescript function.

image

Once you import the ontology and the links that you want to be able to access, you can then follow the steps described by @timurm above.