Optional params and vararg params in a single formula

Hi @Mikolaj_Pastuszko - Welcome to the Coda community! Your assessment is correct, that once you add any vararg parameters you must specify all optional parameters. This is because vararg parameters can only be addressed positionally, not by name. There are probably ways to change the Coda Formula Language to address this in the long term, but at the moment this is an unavoidable consequence.

The approach I’ve recommended to other Pack makers is to move your vararg parameters to a separate helper formula, which bundles them up into JSON, and passes that JSON to a new optional parameter of your main formula. For example:

AddInvoice(My Account, "vat", 111, 111, 
  items: Items("abc", 10, 123.45, 20))

You could make the Items() formula use varargs, so you could specify multiple items at once:

AddInvoice(My Account, "vat", 111, 111, 
  items: Items("abc", 10, 123.45, 20, "def", 20, 45, 10))

But for this use it isn’t the easiest to read. It might make more sense to pass a List() of single Item() results.

AddInvoice(My Account, "vat", 111, 111, 
  items: List(Item("abc", 10, 123.45, 20), Item("def", 20, 45, 10)))

But if you expect these items to come from a table it probably makes more sense to make each parameter an Array or SparseArray type, so that the user could pass an entire column at once:

AddInvoice(My Account, "vat", 111, 111, 
  items: Items(ItemsTable.Name, ItemsTable.Quantity, ItemsTable.TotalPriceGross, ItemsTable.Tax))

@Leandro_Zubrezki’s Quickbooks Pack ran into this same issue, and he went with something sort of like the 2nd option I showed.

2 Likes