Howdy all,
I have 2 function backed actions
Each one is supposed to do the same thing:
- take existing property1 (where source = user edits)
- take existing property2 (where source = user edits)
- Identify existing property3 (where source = user edits)
- Set property3 = concat (property1, property2)
Function backed action 1 works
import { OntologyEditFunction } from "@foundry/functions-api";
import { BilletAssignment, Awardv1Event, EventAssignment, Objects } from "@foundry/ontology-api";
export class MyFunctions {
@OntologyEditFunction()
public async updateEventAssignmentTitle(EventAssignment: EventAssignment): Promise<void> { // updated
if (!EventAssignment.billetAssignmentId || !EventAssignment.eventId) {
throw new Error("EventAssignment is missing required fields");
}
// Get the billet assignment and event objects using objects.search
const billet_assignment = await Objects.search().billetAssignment().filter(m => m.assignmentId.exactMatch(EventAssignment.billetAssignmentId!)).all()[0];
const event = await Objects.search().awardv1Event().filter(b => b.eventId.exactMatch(EventAssignment.eventId!)).all()[0];
if (!billet_assignment || !event) {
throw new Error("Billet assignment or event not found");
}
// Create new title by concatenating lastName and billetName
let newTitle = `${billet_assignment.maybeABetterTitle_} - ${event.eventName}`;
// Update the betterTitle_ property
EventAssignment.betterTitle_ = newTitle; // updated
}
}
function backed action 2 does not compile
import { OntologyEditFunction } from "@foundry/functions-api";
import { CollateralDutyAssignment, CollateralDuty, BilletAssignment, Objects } from "@foundry/ontology-api";
export class MyFunctions {
@OntologyEditFunction()
public async updateCollateralDutyAssignmentTitle(collateralDutyAssignment: CollateralDutyAssignment): Promise<void> { // updated
if (!CollateralDutyAssignment.idCollateralDuty || !CollateralDutyAssignment.idBilletAssignment) {
throw new Error("CollateralDutyAssignment is missing required fields");
}
// Get the CollateralDuty and BilletAssignment objects using Objects.search()
const collateral_duty = await Objects
.search()
.collateralDuty()
.filter(d => d.collateralDutyId.exactMatch(collateralDutyAssignment.idCollateralDuty!))
.all()[0];
const billet_assignment = await Objects
.search()
.billetAssignment()
.filter(b => b.assignmentId.exactMatch(collateralDutyAssignment.idBilletAssignment!))
.all()[0];
if (!collateral_duty || !billet_assignment) {
throw new Error("Collateral Duty or Billet Assignment not found");
}
// Create new title by concatenating ___ and ____
let newTitle = `${collateral_duty.dutyName} - ${billet_assignment.maybeABetterTitle_}`;
// Update the betterTitle_ property
CollateralDutyAssignment.properties.futureBetterTitle = newTitle;
}
}
errors are as follows
I am sure I am missing something basic?
My best bad guess is that I recently created the main object type CollateralDutyAssignment (so maybe the properties need to “permeate” through the ontology?)
I triple checked my property API names.
thanks for any help!