One of core features of Functions is they can easily access data that has been integrated into the Foundry Ontology. The Ontology provides semantic modeling of data for your organization, which makes it easy to access structured data and reuse logic across use cases.
This tutorial assumes that you have created and set up a TypeScript repository. If you haven't yet, complete the Getting started tutorial first.
Any object or link types you want to use in your Function must be imported into the Project that contains your repository. Clicking into the Resource Imports side bar shows you the object types which have been imported into the Project.
Your organization may not have the Airport and Flight objects. Use any object types you have access to when following along.
To import additional object types, you will need to select the Add button in the Resource Imports side bar. If no ontology has been selected you will be prompted to select an ontology. If you have at least one imported ontology type, the selected ontology will automatically be resolved.
Once an ontology is selected, a search modal will appear. Your ontology will depend on the object types available in your organization. Start by selecting a few object types and link types that connect them. In this example, we'll import the Airport and Flight objects, in addition to the link type between them.
Choose Confirm selection to import the ontology types into the project. Code Assist will automatically be restarted to regenerate code bindings to reflect the new object and link types you have imported.
In your code, you may now import ontology types from the @foundry/ontology-api
package. If you’re using a private ontology, the package name will instead be @foundry/ontology-api/<ontology-api-name>
.
If you are using a private ontology, replace @foundry/ontology-api
with @foundry/ontology-api/your-private-ontology-api-name-here
in all the following examples.
Next, let's write a Function using an object type you just imported. Your code will depend on the object types, properties, and link types available to you. Switch back to the Code tab, and try importing one of the object types you just added:
Copied!1
import { Airport } from "@foundry/ontology-api";
Then, write a Function that takes that object as input:
Copied!1 2 3 4
@Function() public myObjectFunction(airport: Airport) { airport. }
Once Code Assist has started, simply type airport.
to see autocomplete for the properties and link types available to you:
In this example, we use a template string ↗ to combine the city
and country
fields on an Airport into a human-readable location:
Copied!1 2 3 4
@Function() public airportLocation(airport: Airport): string { return `${airport.city}, ${airport.country}`; }
Experiment with the APIs based on your own ontology and write a Function that returns a value based on your object type.
Open the Functions helper, toggle to Live Preview, and choose the Function that you wrote above. To run an object-backed Function in Live Preview, you have to import the backing datasource for the object type. Click the warning icon next to the Run button:
Then, use the dialog to import the backing datasources for your object types:
After you've imported the datasources, choose an object and click Run to see results:
The permissions on object types in Live Preview are determined by the TypeScript repository's permissions on the backing datasources underlying each object type. When testing Functions that create notifications, the recipients' permissions are not enforced. For this reason, a Function that creates a notification may succeed in Live Preview but fail when used by an Action elsewhere in Foundry.
Learn more about configuring notifications for Actions.
Publish the new Function by committing your code and publishing a new tag using the Branches tab. Once your Function has been published, you can test it using the Functions helper.
After the Function has been published, you can start using it in other applications throughout the platform.
This tutorial just scratches the surface of what you can do with Functions on Objects. To learn more, try these resources: