Is it possible in Palantir Foundry to create a temporary object record in typescript to return values to Workshop for display, without having to save the record to ontology? Below is what I've tried - every attempt works as expected in the repository debugger but does not return the expected results from the function. I suspect this is something to do with how ontology edits are read/applied and probably related to why we have to return void from @OntologyEditFunction. Just don't know enough about the inner workings here to understand why this isn't working or if there is something else that would work.
In a typescript function decorated as @Function:
@Function()
public getFilteredRuns(): ScheduleRuns[] { //Object Type: ScheduleRuns
//Attempt 1: Create a new temp object. Works as expected in debugger but returns a null result
let testNew : ScheduleRuns = Objects.create().scheduleRuns("testId")
testNew.name = "All Schedules"
testNew.startTime = Timestamp.now()
testNew.buildDuration = "5h 43m 34s"
let r1 : ScheduleRuns[] = [];
r1.push(testNew)
console.log(r1) //Displays new object with updated properties in the debugger
return r1 //Actually returns null
//Attempt 2: Filter for one object and update it's properties. Displays correct updates in console but doesn't return them from function
let test = Objects.search().scheduleRuns().filter(s => s.buildRid.exactMatch("0")).all()[0];
test.name = "All Schedules"
test.startTime = Timestamp.now()
test.buildDuration = "5h 43m 34s"
test.avgDuration = "233333333333333333s"
let r1 : ScheduleRuns[] = [];
r1.push(test)
console.log(r1) //Displays correct updates in console
return r1 //Returns object with original values, ignores property updates above
//Attempt 3: Clone? Same, appears in console correctly but doesn't return updated object
let test = Objects.search().scheduleRuns().filter(s => s.buildRid.exactMatch("0"))
let rMutable : ScheduleRuns = test.all()[0];
let cloned = Object.assign({}, rMutable);
cloned.displayName = "Why"
cloned.name = "All Schedules"
cloned.startTime = Timestamp.now()
cloned.buildDuration = "5h 43m 34s"
console.log(cloned)
return cloned
}
It sounds like you should be using a Scenario with a "regular" function that creates an object just like you normally would with a function. This has the trade-off that someone with the right permissions could call this function outside the Workshop app and/or apply the scenario within the app, but perhaps that's OK for this use case.
Alternately, you could create a copy-cat object type that you use solely for display purposes. You could let users create real object instances and then rig up an Object Monitor with an Action to run periodically to delete any object instances (sort of like a garbage collection mechanism).
A third option would be to simply return the raw values you care about and display them in Workshop, though you may have to use different widgets to do that than you're currently using.
If the Scenario solution doesn't work and you're leaning towards the copy-cat object, I would pause to reconsider this approach as it is a bit of an anti-pattern.