Object To Recordlist

Object To Recordlist

  
Hi,
Please see my attachment.In that i have build two actions
1.XML DOCUMENT_LOAD and
2.XML DOCUMNET _SELECTNODE

Now i have to pass the result of XML DOCUMENT_SELECT NODE into FOREACH .
But XML DOCUMNET_SELECTNODE IS of object datatype and in FOREACH ITS asking for recordlist.
So how do i pass the result of XML DOCUMNET_SELECTNODE INTO FOREACH.

Regards,
CR
Hi CR,

You cannot convert an Object back to anything else, unfortunately. The best you can do is pass a known record list to an action in an extension, and have the extension fill it, like the XML Records extension does.

Kilian Hekhuis wrote:

Hi CR,

You cannot convert an Object back to anything else, unfortunately. The best you can do is pass a known record list to an action in an extension, and have the extension fill it, like the XML Records extension does.


Hi Killan,

I wanted to take the recorlist returned by the extension module and bind it to a grid on the UI. Challenge is, since the type of the RecorList parameter is "object" and the grid takes RecordList as the binding parameter, I'm unable to display my records to the UI. Is there a solution you're aware of for this?


Thanks!

Vinay

Hi Vinay,

You are replying to a topic that's already almost 3 years old. That's in general not a good idea, and instead I would like to ask you to start a new topic in the future.

That said, no, you cannot change an object into anything else. Once it's an object, it's an object. However, if the Extension merely does something to an existing List or Record List (like the XML Records I mentioned, or the SortRecordList Extension), the list that was passed as input is changed (it is passed by reference), so you can use that list.

What kind of Extension are you using? Is it one you wrote yourself?

Kilian Hekhuis wrote:

Hi Vinay,

You are replying to a topic that's already almost 3 years old. That's in general not a good idea, and instead I would like to ask you to start a new topic in the future.

That said, no, you cannot change an object into anything else. Once it's an object, it's an object. However, if the Extension merely does something to an existing List or Record List (like the XML Records I mentioned, or the SortRecordList Extension), the list that was passed as input is changed (it is passed by reference), so you can use that list.

What kind of Extension are you using? Is it one you wrote yourself?

Hi Kilian,

Thanks for your response. Yes. I created an extension method which basically uses reflection to call any server action based on the espace and action name supplied to it. And as you can imagine, I want to keep the signature of this method generic, as opposed to strongly typing its parameters. So I had an output parameter in it of type object which could return a Record or a RecordList.

As a solution of this I made a change in the method to json serialize the response and changed the return type to text. I’m then able to de-serialize it in the module I’m consuming the response.


Thanks,

Vinay


Hi Vinay,

Using JSON is indeed a possibility, albeit a bit on the slow side. Alternatively, if you work with Lists (this doesn't work for Records), you don't need an Output Parameter: modifying an input List will automatically change the List in the calling Action, as Lists are passed to Extensions by reference.

Kilian Hekhuis wrote:

Hi Vinay,

Using JSON is indeed a possibility, albeit a bit on the slow side. Alternatively, if you work with Lists (this doesn't work for Records), you don't need an Output Parameter: modifying an input List will automatically change the List in the calling Action, as Lists are passed to Extensions by reference.

Absolutely. That’s the first thing I tried and was thrilled to see the RecordList coming back even if I had my output parameter was definedas ‘object’. My joy didn’t last longer when I figured that there’s no way for me to take that object type out parameter returned by my extension method and bind it to a grid, because apparently the gird requires a RecordList as its binding parameter. Let me know if I’m misunderstanding something. Is there a way to get around this? I totally agree about your concern regarding performance when using serialization.


Thanks,

Vinay


Hi Vinay,

Like I tried to explain before, you do not need an output parameter, as Lists and Record Lists are passed by reference to an Extension Action. If you look at e.g. the XmlToRecordList Action from the XmlRecords Extension, it doesn't even have any Output Parameters, yet converts the Xml to a RecordList:

This is because the RecordList Input Parameter is changed, so there's no need for an Output Parameter. You could do the same: allow an Input Parameter of type List or Record List, use reflection inside the Extension to do something with it, and the changed List will be available to the calling program.

Kilian Hekhuis wrote:

Hi Vinay,

Like I tried to explain before, you do not need an output parameter, as Lists and Record Lists are passed by reference to an Extension Action. If you look at e.g. the XmlToRecordList Action from the XmlRecords Extension, it doesn't even have any Output Parameters, yet converts the Xml to a RecordList:

This is because the RecordList Input Parameter is changed, so there's no need for an Output Parameter. You could do the same: allow an Input Parameter of type List or Record List, use reflection inside the Extension to do something with it, and the changed List will be available to the calling program.

Hi Kilian,

May be I'm missing something here but the problem I see is not with getting the data back in the form of RecordList, but with consuming my extension method in Service Studio Be it an output parameter or input parameter that returns a RecordList, the Data Type of the parameter that gets the data is defined as "Object" and when I try to consume it to display the data in a grid, I'm unable to do so because the datatype expected there is RecordList. Btw, I'm using TableRecords control to display my records in UI. 

Following your suggestion, here's what I did:

Changed the Response output parameter to Input in my extension method:

But I still can't bind the response to the Source Record List parameter of TableRecords as it expects a RecordList.


I noticed that in your Server Action XmlToRecordList, the RecordList parameter is also defined as Object. So how do you consume it in Service Studio if you need to bind the data to a control that expects type RecordList? Is there a Cast or Convert method that you use there?


Thanks,

Vinay




Hi Vinay,

You define, in Service Studio, a Variable of the desired List type. You pass that as input parameter (again, ad nauseam, not an output parameter) to the Extension Action. The type of that Input Parameter should be Object, so you can pass different types of List and use reflection inside the Extension. Use the built-in ToObject Function to convert the List to an Object (so use ToObject(myList) as the Input Parameter value).