I want a column in my object table to populate with a value computed by my function. But when I go to the table’s Column Configuration, that function doesn’t load, but it loads in the variable section so I know its deployed properly. How do I mitigate this? Is it a certain decorator missing in my code or some other step?
Hey,
It’s the return type! The + Add column button in the Object table widget’s configuration panel will only show a list of functions whose return type is FunctionsMap<X, Y> where X is the API name of the same Object Type used/displayed in the table and Y is the data type of the values you’re trying to display.
Here’s example usage:
Starting Object Type (i.e., People)
name | age
Abby | 24
Bob | 22
Charles | 29
And you want to display this + a column (i.e., ageNextYear) in Workshop’s Object Table widget, your code would look like this:
import { Function, FunctionsMap, Integer } from "@foundry/functions-api";
import { People } from "@foundry/ontology-api";
export class MyFunctions {
@Function()
public computeAgeNextYear(
subsetOfPeople: People[] // equivalent to Array<People>
): FunctionsMap<People, Integer> {
const map = new FunctionsMap<People, Integer>(); // empty hash map
// Loop through each object in the subset
subsetOfPeople.forEach((person) => {
// 1. You can refactor your current function here or write whatever logic is required
let value = person.age + 1;
// 2. Then simply assign the new value for the new column
map.set(person, value);
});
return map;
}
}
Once you commit changes and publish a new version, it will be visible in Workshop and you’ll end up with something like this:
name | age | (youCanRenameThis)
Abby | 24 | 25
Bob | 22 | 23
Charles | 29 | 30