Function parameters

Quick one - is there a way in an Epicor Function to iterate over the parameters instead of using them all individually?

1 Like

If you pass a serialized string and parse it with a custom code block, yes

1 Like

It’s easier than that if you pass in a DataSet too. But for simplicity when giving the signature to another team to work with, it would be nice to JUST have a set of parameters, in which case it would be great to be able to iterate over them.

I did hope Parameters[index] might work, but it doesn’t.

1 Like

Out of curiosity, what’s the use case?

The first stages of a custom integration that’s going to grow.

I’ve had a fair bit of success using Functions as the Epicor API for these types of things, and a lot of it becomes more manageable the more standardised each function can be. By using naming conventions and suchlike, a lot of the code can be reused unchanged, and data differences managed outside the functions by people who don’t know coding.

But except for passing in a DataSet to the function, there doesn’t seem to be any way around using parameters by name, which spoils that reusable approach.

1 Like

In my understanding, Epicor Functions parameters are just dynamic user created JSON objects and as such are unordered, so accessing by index is not possible. I am having trouble envisioning a scenario where a serialized string, which is a little hacky but works well, wouldn’t work for passing a collection. I think the data set approach is for .NET to .NET calls with the intent to hydrate a dataset consumed by a business object etc. Hard to say without knowing all the ins and outs, of course.
There is certainly no reason why one couldn’t use the same parameter names in their functions across multiple functions. But collections are tricky

You’d think DataSets were highly specific, but in real-world use they make very nice JSON. The concepts of the two dovetail very nicely (generic DataSets, that is, not the BO ones). The only real downside is that if you just have a single set of parameters, the DataSet has unnecessary layers.

1 Like

Similar question… Is the way to iterate over the parameters of a method like double Add(double x, double y, bool roundResult)? (without reflection definitely).
EFx uses Parameter Object pattern to simplify code generation only. And it can be changed (for example to use Azure Functions / AWS lambdas as an implementation). You have to treat all elements of a signature as individual items.