Epicor Functions and JSON string parameters

It’s been a long day so apologies if this is a really dumb question.
I have a function that has a string parameter intended to consume information related to what will be line level details in a quote or sales order.
The parameters for the function look like this:

the “productList” is filled out by a nested array like so:

image
Is this invalid JSON or something? I think it looks fine but more eyes are helpful.

next, when I consume this parameter, I was having trouble iterating over it as it keeps throwing back the “Sorry! Something went wrong” message to my app.

I am trying to debug this bug it’s not even allowing to read the incoming productList parameter into the output parameter “msg”
image

This always results in an error.

If I se the productList param to a single, non-nested array value, it works just fine.
image

Is there something preventing a JSON array from being read into this function? Surely it’s something small, but thanks for any input

Was this working before or is it shown like this in the documentation or examples?

I have no idea how the productList property is parsed into the function or if it is even supported like this.
Another way would be to simply format the productList as a list of separated values in a single string.

In this case I’m just trying to pass the raw values from the parameters into my function and then process fr there. It works great with single string values but I’m having trouble with sending it more complex json like this example. I didn’t read any documentation regarding this so apologies if that’s a known barrier or if I’m just doing it wrong

You know what would be cool is a dynamic object type in addition to the existing data types that are allowable for the parameters

I have no idea how functions work internally so I can’t really help much.

Can you tell if the call actually reached your function? for example printing a message before actually doing anything with the productList member.

I want to know if the error comes from parsing the json or actually trying to use it, what if you do productList.ToString()?

1 Like

I’ll do a little more investigating tomorrow and try some of those things, thank you. I do know it works great with single values

Hi Aaron,
That’s the reason, the product list is a built-in ref type “System.String” and not an array or collection, so, unless Epicor adds additional types for request/response parameters, you will need to send a list as a string, for example:

“productList”: “32247001,45647010,…”
or
“productList”: “PartNum-32247001,PartNum-45647010,…”

then in your C# code you split to an array and do your iteration.

1 Like

This does ring a bell. :thinking:

I think I had to jsonify the inner objects into a string first and then jsonify the whole string object…and then do the reverse in the Function. It might be worth reporting to Epicor.

What I didn’t try was seeing if URL encoding would have helped.

Where are you processing the array of property productList in your function. That is likely where it is breaking. You have to make sure you are handling that deserialized object correctly. If you are passing the whole Json String is into your function it’s just a string. Show the code that deserializes and process the productList.

It’s POST data, URL encoding shouldn’t enter into it in this case. He was showing passing the data to the function directly from postman where it will not work either so it’s for sure on the Epicor processing side the issue lies, not with how he’s sending it.

Right. I was just wondering if Epicor is getting tripped up by the braces or brackets and encoding might prevent that issue during the Epicor parameter processing. Just throwing out ideas. :man_shrugging:

When passed as part of the URL that can happen, when it’s part of a request body tis’ more of a free-for-all. It’s passed as raw data nothing parsed.

I get that. I’m suggesting that Epicor might be handling this free-for-all poorly and looking to see how changing the payload (like Aaron did by making it a string) might change the post-POST processing.

1 Like

In this example I’m not even processing it yet. I’m just trying to figure out if it is being consumed at all into the function.
I also tried deserializing it and then displaying it in the msg output variable, but no dice.
So I tried then to not deserialize it in hopes that jt was being fed a raw json string and that fails too.
It looks like like it might be trying to parse it to a .net type without me knowing and perhaps that’s why it is not allowing it to be consumed if it’s anything other than a string or an int

I’m worried you’re right, but if this is the case it’s a pretty cruddy design if we can’t use actual json objects to pass into functions. I’ll give that a shot too

@Aaron_Moreng you need to escape the JSOn and send it as a String, then deserialize it on the other side.

[\r\n{\"PartNum\": \"32247001\"},\r\n{\"PartNum\":\"45647010\"}\r\n]

So your JSON object you send to the function should look like

{
	"soldToCustNum":8989,
	"billToCustNum":8989,
	.
	.
	.
	"productList": "[\r\n{\"PartNum\": \"32247001\"},\r\n{\"PartNum\":\"45647010\"}\r\n]",
	"ptAge":25
	
}

On the other side you’ll have to re-parse that field to turn it into an array

3 Likes

ah poo I was hoping it was easier and less ugly. I’ll try that

Something like this.

3 Likes

I wasn’t passing complicated parameters but I was returning a .Net DataSet. I’m sure it could be improved…

      // Unpack return object
      JObject objJ = JObject.Parse(body);
      string Result = objJ["oResult"].ToString();
      // rehydrate DataSet
      JObject obj2 = JObject.Parse(Result); // <- not needed, was debugging this reference
      DataSet ds = JsonConvert.DeserializeObject<DataSet>(Result);  
2 Likes

The calling app isn’t .net so i was hoping it would be a little more agnostic to that but oh well

Well the explosion is not on the calling app as much as it is on the Epicor side you are sending “illegal” JSON at least not the JSON it is expecting.

1 Like