My workflow involves having a form to create an instance of Object A. In this form, the user needs to select an instance of Object B to link it to. I’ve created it as a form, however since the link is defined on primary key, it is not very helpful.
The user only sees long, random strings. It would be much better if the user could select based on the titles of Object B, not the keys. However we need to use Object B’s key to establish the foreign key for Object A.
My question is whether there’s a built in way to do this in the form customisation of Ontology Manager, or will I need to create a specific Workshop submodule to power this?
Ideally we would be able to do this via Ontology Manager but currently I don’t know how.
In the action form (Parameters page of your Action Type):
add a new parameter
set its type to “Object reference” (near top-middle of page)
in the dropdown that appears just underneath, select Object Type B
The Object reference type will display the title key value, but it will write the primary key value when the action is submitted.
You may need to add a second rule in the Rules page of your Action Type (likely the Add link rule) and then map the relevant parameters.
If you have trouble getting this to work, the TypeScript v1 function is pretty straightforward and looks something like this:
import { Edits, OntologyEditFunction } from "@foundry/functions-api";
import { Objects, ObjectTypeA, ObjectTypeB } from "@foundry/ontology-api";
import { Uuid } from "@foundry/functions-utils";
export class MyFunctions {
@Edits(ObjectTypeA, ObjectTypeB)
@OntologyEditFunction()
pubic createObjectA(
objectTitle: string,
linkedObjectB: ObjectTypeB
): void {
const newObject = Objects.create().objectTypeA(Uuid.random());
// use dot notation to access properties and assign them values
newObject.name = objectTitle;
// add the link
newObject.objectTypeB.add(linkedObjectB);
}
}
Relevant Documentation for TypeScript link creation: https://www.palantir.com/docs/foundry/functions/api-ontology-edits#updating-links
You would then create a function-backed Action in OMA after committing changes + releasing a new tag version and the form will automatically add an Object dropdown field/parameter in the form which will show the title key of the instance of Object Type B, but still write the primary key value.