Passing in a dictionary as a string from AIP Logic into Typescript function. Trying to add the objects to the object type, but struggling. This is my code:
import { Function } from "@foundry/functions-api";
import {DeliveryNote } from "@foundry/ontology-api";
export class DeliveryTest {
@Function()
public addDeliveryNoteObjects(existingObjects: DeliveryNote[], deliveryString: string): DeliveryNote[] {
const delivery = JSON.parse(deliveryString);
const newObjects: DeliveryNote[] = delivery.Materials.map((item: any, index: number) => {
return {
primaryKey_: (existingObjects.length + index + 1).toString(),
company: delivery.Company,
deliveryDate: delivery["Delivery Date"],
deliveryInfo: delivery["Delivery Info"],
material: item.Name,
quantity: item.Quantity
};
});
console.log('New Objects:', newObjects);
return existingObjects.concat(newObjects);
}
}
when I use this example (just one material for simplicity):
{“Company”: “ABC”,“Delivery Date”:“November 7, 2024”,“Delivery Info”: “Materials for xyz.”,“Materials”:[{“Name”:“12-inch PVC Pipes”,“Quantity”:“100 units” }]}
I get this:
Found unexpected value for function return type.
Error Parameters: {
“value”: “{"primaryKey_":"1","company":"ABC","deliveryDate":"November 7, 2024","deliveryInfo":"Materials for xyz.","material":"12-inch PVC Pipes","quantity":"100 units"}”,
“returnType”: “object”
}
SafeError: Found unexpected value for function return type
at t [as constructor] (FunctionsIsolateRuntimePackage:2:1347290)
at new t (FunctionsIsolateRuntimePackage:2:562103)
at Object.t.unexpectedValueForType (FunctionsIsolateRuntimePackage:2:1100630)
at Object.object (FunctionsIsolateRuntimePackage:2:1053027)
at Object.visit (FunctionsIsolateRuntimePackage:2:645471)
at validateAndTransformResult (FunctionsIsolateRuntimePackage:2:1050335)
at FunctionsIsolateRuntimePackage:2:1051761
at Array.map ()
at Object.list (FunctionsIsolateRuntimePackage:2:1051748)
at Object.visit (FunctionsIsolateRuntimePackage:2:645415)
and log output is
LOG [2025-04-01T10:18:47.651Z] New Objects: [ { primaryKey_: ‘1’,
company: ‘ABC’,
deliveryDate: ‘November 7, 2024’,
deliveryInfo: ‘Materials for xyz.’,
material: ‘12-inch PVC Pipes’,
quantity: ‘100 units’ } ]
The new object seems ok but something is not happy re adding the object to ontology…