palantir-foundryfoundry-functions

How can I edit a linked object set in a Foundry Function?


I have an Object Type A, which has a many to many relation to Object Type B. I am trying to implement an OntologyEditFunction in TypeScript that retrieves all objects of type B that are linked to an object of type A, and then edits the returned objects. My code so far looks something like the following:

@OntologyEditFunction()
public async editLinkedObjects(objA: ObjectTypeA): Promise<void> {
   // Get all objects of type B that are linked to objA
    const linkedObjects = objA.objectTypeB.all();
    
   // Edit linked objects...
}

I noticed that the .all() function returns a readonly array (i.e. the return type of linkedObjects is a readonly ObjectTypeB[]). Given this, how can I modify linkedObjects such that I can apply edits to it?


Solution

  • Although .all() returns a readonly array, the individual objects within the returned array are not readonly. In other words, you should still be able to iterate over linkedObjects and apply edits as you would expect!

    If for some other reason you need linkedObjects to be a mutable array, you can do so by creating a copy of it using ES6 array spread syntax as shown below:

    const linkedObjectsMutable = [...linkedObjects]