Handling Functions with multiple return values

I’m a little confused about how function return parameters are handled syntactically.

My specific example is: I need to call a function (from C# Custom code) that has two return parameters:
- output which is type Int32
- prodCalDataSet which is type Erp.Tablesets.ProdCal.Tableset

The following is boilerplate code I have used with other function calls:

It’s not clear to me how to deal with this “AnonymousResult” and get the prodCalDataSet from the result of calling the function.

I did manage to figure out that if I use GetJsonResult (see commented out code), I can get two tokens one for the output and one for the prodCalResult, can I convert the Json token easily into a dataset then ?

Thanks, newbie

I see you are doing all of this inside of Epicor so I doubt this is going to help, but @josecgomez made some type of dynamic object in his rest helper. Not sure if there is some equivalent we can tap into inside of Epicor.

Instead of returning the Prodcal tableset, return a string by serializing the Prodcal tableset then you can deserialize it to dynamic (or Prodcal tableset again)

3 Likes

That makes sense, that’s kind of what I was thinking by converting it to JSON (a string), but how do I deserialize it back to a tableset ?

Would you be able to provide an example of serialize from and deserialize to a tableset ?

Thanks !

1 Like

It’s already serialized how you got it now.
When I get to the office I’ll show you how to get it.

2 Likes

You should be able to find some here on the group too.

Search results for ‘json deserialize’ - Epicor User Help Forum (epiusers.help)

JObject responseJson = stringResponse.GetJsonResult();

JToken productCalDataSetJson = responseJson.GetValue("prodCalDT");

Erp.BO.ProdCalDataSet prodCalDT = productCalDataSetJson.ToObject<Erp.BO.ProdCalDataSet>();
3 Likes

Thanks Kevin, can’t wait to use this a lot.

1 Like

Thanks, works like a charm, so much clearer to me than that Anonymous result stuff

1 Like

You could also use this:

JObject responseJson = stringResponse.GetJsonResult();

Erp.BO.ProdCalDataSet prodCalDT = responseJson["prodCalDT"].ToObject<Erp.BO.ProdCalDataSet>();


.

That GetAnonymousResponse Extension Method:

var localResult = stringResponse.GetAnonymousResult( new { prodCalDT = (Erp.BO.ProdCalDataSet)null} );
Erp.BO.ProdCalDataSet prodCalDT = localResult.prodCalDT; //You could just use the localResult.prodCalDT here as your object here as well

//or

Erp.BO.ProdCalDataSet prodCalDT = stringResponse.GetAnonymousResult( new { prodCalDT = (Erp.BO.ProdCalDataSet)null} ).prodCalDT;
2 Likes