Pass a dataview to a function for further processing

I was going to reply to the post Passing a View to a Function by @hmwillett but the bot accused me of “Necroposting”. I am able to pass the data but it seems like a hack and I would like to be able to access the Dataview data properly. Currently I am able to pass the data view by using this #_JSON.stringify({Table1:trans.dataView('SpecialItemsView').viewData})_#. I am mauaully adding the “Table1:” before the trans.dataView… because c# uses the table name. I got the idea for the #_ ..._# syntax from this post. It works but doesn’t seem like it is the proper way to access data from the view. Does anyone have experience with this?

c# function

try {
  DataSet ds = Newtonsoft.Json.JsonConvert.DeserializeObject <DataSet>(this.dsString);
  DataTable dt = ds.Tables["Table1"];
  dt.Rows.Add("Steve");
  this.output = ds;
} catch (Exception ex) {
  this.error = ex.Message;
}
1 Like

This actually seems to work now from that post you linked.

1 Like

This is cool

1 Like

Gotcha. Thanks for the response. Do you know if there is a better way to access the data from the view other than this #_JSON.stringify(trans.dataView('SpecialItemsView').viewData)_# ? I am using this in other places. For instance I am assigning the data in the SpecialItemsView to the text box “Result”. I am also putting this in the erp-function->Method Parameters->Field Value to be passed to the function as a parameter type “String”. If I CTRL+ALT+V ,in dev tools, and expand my SpecialItemsView I see the column “Name” and the rows.

c

1 Like

Why not just bind the dataset returned from the function and then bind your result textbox to SpecialItemsView.Column name?

2 Likes

I think that would give me the individual value per row. I am needing a list/array of the contents of the grid. Ex. [{Name:"one"},{Name:"two"},{Name:"three"},{Name:"four"}]. I can then shape it, if needed, to something like one~two~three~four or whatever. Can I bind to the viewData not just one column?

Not really.
If you’re looking for aggregate data like that, I would build the string in your function and return that aggregate string instead of a dataset.

What exactly is it you’re trying to accomplish in the end?

1 Like

I am working on a product configurator we are starting to build. We are storing “non-standard” items( items not in a predefined list or combo box) in a grid view that we can use when building our “bill of materials”. I am going to set the value of a text box to be a list of “Special Items” that we may or may not need to order. I like your idea of returning a string from my function for the text box. I could actually return both in 2 separate response parameters. One dataset to populate the grid the other formatted for a string like this one~two~three~four. I suppose I need to continue to use #_JSON.stringify(trans.dataView('SpecialItemsView').viewData)_# to get the data from the view to pass as a parameter to the function?

Toooottttally glossed over that you’re SENDING the dataset to the function. Stand by.

2 Likes

Okay–I wasn’t able to get it working with the erp-function widget, but I did get it working with the rest-erp widget.

image

3 Likes

Thanks for taking time to help. I am about to leave work so I will try this on Monday. By the way is the difference between erp-function and rest-erp the payload you send from the client?

1 Like

The difference is the function widget can only do functions.
The rest widget can make any BO call.
I’m pretty certain the function widget is just a dumbed down version of the rest one.

2 Likes

I can’t wait to have an environment to try all of your tips and tricks and how-to demos in @hmwillett

Hopefully will be installed in the next month!

1 Like

@hmwillett how can we send data or rows or selected row from a custom panel card grid to the function??

I would try using the row-copy widget and copy the current row to a new dataset and send that whole dataset containing the single row to your function.

This is fantastic Hanna - thank you!

1 Like