How can I configure an action that creates a variable number of objects?

233 Views Asked by At

I am looking to create an action type that can be used to create a variable number of objects of a given object type. In other words, a user should be able to use this action to create 3 objects at once, 5 objects at once, etc.

I tried to accomplish this using the action configuration UI in OMA, but ran into the following issues:

  1. I noticed that in the “Rules” section, it is only possible to define a static number of objects to be created. In the example shown in the screenshot below, you’d only be able to create 2 objects rather than a variable number. Showing static number of objects edited by actions
  2. Similarly, there is no way to specify a variable number of parameters in the “Form” section, which would be necessary to capture the primary keys for each object the user would like to create. I thought of specifying a string parameter that takes in multiple values as an alternative, but that wouldn’t work because there is no way to assign a single value from this parameter to an object property.

How should I go about accomplishing this?

1

There are 1 best solutions below

0
On BEST ANSWER

It would be possible to create a variable number of objects using a function backed action! In particular, you could take the following steps:

  1. Create a new function that takes in a list of primary keys as input and creates an object for each primary key in the list. The code for this function could look something like this:
@Edits(ObjectA)
@OntologyEditFunction()
public createMultipleObjects(primaryKeys: string[]): void {
   // Loop through pkeys and create a new object for each pkey
   primaryKeys.forEach(k => {
        Objects.create().objectA(k)
   });
}

You can also reference the following documentation for more guidance on how to define Ontology edit functions.

  1. Create an action in OMA that calls the function that you defined in step 1. You will need to define a multi-value string parameter for this action, which will be passed as an input to the function.

You can refer to the following documentation (https://www.palantir.com/docs/foundry/action-types/function-actions-getting-started/) for a step by step guide on how to configure a function backed action.