At our Palantir workshop, we utilize a form to input values that are then added to an Ontology object. Recently, I've been tasked with validating the combination of userId, startdate, and states from the form inputs to check if they already exist or not. When we submit the form, a typescript function is triggered, but I am new to Typescript and seeking guidance on how to accomplish this.
import {
@OntologyEditFunction,
LocalDate,
Integer,
Users,
Double,
FunctionsMap,
Function,
} from "@foundry/functions-api";
import {
Objects,
ObjectSet,
ObjectWeUse,
} from "@foundry/ontology-api";
@OntologyEditFunction()
public async createSkus(
userId: string,
is_Sku_Pending?: string,
partition?: string,
startdate?: LocalDate,
all_states?: string,
states?: string[], //selects multiples values
): Promise<void> {
let final_states;
if (all_states && all_states === "All") {
final_states = U.all_usa_states; // A pre defined const string array
} else if (all_states && all_states === "All but UT") {
final_states = U.all_usa_states_without_utah; // A pre defined const string array
} else {
final_states = states;
}
for (let i = 0; i < packages.length; i++) {
let sku= Objects.create().ObjectWeUse(U.uuidv4());
sku.userId= U.uuidv4();
sku.states= final_states;
sku.strs = startdate;
sku.partition = partition
sku.isSkuPending = is_Sku_Pending;