Array of Objects as Paramater

I’m using an automation to pass an action an array of objects as a parameter. I’m having trouble with the syntax for makeParameter.

The question seems similar to this post from 2021, but the solution does not appear to be the same:

Here’s the code snip:

const EmployeeSchema = coda.makeObjectSchema({
  properties: {
    name: { type: coda.ValueType.String },
    email: { type: coda.ValueType.String },
    manager: { type: ManagerSchema},    
    // Add more fields as necessary
  },
  displayProperty: "name",
});

pack.addFormula({
  name: "AssignStaffToContract",
  description: "Assign staff to a Harvest contract",
  parameters: [
    coda.makeParameter({
      name: "SchoolManager",
      description: "List of school managers",
      type: coda.ParameterType.Array,
      items: EmployeeSchema,
    }),

I get the following build error:

  • formulas[3].parameters[0].type: Required
  • formulas[3].parameters[1].type: Required

Bonus question:
Can I make the schema recursive? Instead of building ManagerSchema, can I just have manager be EmployeeSchema?

Thanks!
Josh

Ohhh :frowning:

“Pack formulas can return structured data as, but it’s not possible to pass them as parameters”

1 Like

For your use case, it seems that you would just need the employee ID.

One (ugly) way around this is to pass the object as JSON. If it’s just for you, that’s fine, but makes things a bit less user-friendly for the average Coda user.

In case you DO need JSON AND you want to make it user-friendly, you could also create multiple versions of the same function. One version takes JSON and another takes the ID.

AddStaffToContract and AddStaffContractWithJson

That’s probably unnecessary for your use case, but it’s something a lot of pack makers don’t think about.

You’re not always stuck with just one way to skin the potato.

1 Like