16
Views
12
Comments
Solved
Problem with copying structure from webservice
Question

Hey

This might be a little tricky to explain/understand but I'll try my best,

I am consuming a webservice called GetVouchers which returns me this structure

What I need to do, is make a copy of this exact structure so I can expose it to my CS module (WebService is in IS module), I don't want to expose the webservice direct structure into the CS (client details and best practice I guess), so I need to make a copy of the structure, and in the action that I have in the IS where I call the API, I assign the response from the service to my new structure.

So, I did that, created this structure which is an exact copy


The fields (Vouchers_ItemToCS is a list in both the webservice and my structure).

And when I try to assign the response from the API to the new structure:


It's the exact same list, exact same fields, I can't understand the error.

Rank: #246
Solution

It is best practice to use your own structure, even if it is in fact an exact copy. 

So, then you need to create a function that will translate each sublist of the structure into your copied structure.

I don't think this will affect your performance that much. the function should look like: 

TranslateWebListX(weblisttoconvert) with output parameter being the structure of your copied structure sublist.

Hi Fabio,

I think you have to use the ListAppendAll() instead since you won't be able to do a direct assignment due to as mentioned, the platform detects that they are not the same data type not unless you replace the name of the structure for that in the CS module as exactly "AddressListItemWS".

Hope this helps,

Thank you and kind regards,

Chris

Rank: #3634

Hi Chris, thanks for the reply,

I actually had tried the ListAppendAll but unfortunately, I get the same error because it is a list inside a list I guess

And I can't replace the structure name to the same name because they are both in the same eSpace both in the IS, the difference is one structure is public (the one going to the CS) and the other one is not (the one that comes from the API)


Bare in mind,

The API returns a list of vouchers, and each voucher has a list of addresses.


But thanks for the help anyways!

Hi Fabio,

One option that I can think right now is that you create a Server action as function type, input parameter is the AddressListItemWS, then output parameter will be a type AddressListItemToCS. Inside that server action, do a ListAppendAll.

Thank you and kind regards,

Chris

Rank: #3634

Hey chris, that would be too heavy cause the list contains a lot of records and all are needed in the preparation :/

Hi Fabio,

Good morning!

Apologies, I guess I ran out suggestions. But allow me to share the below post:

https://success.outsystems.com/Support/Enterprise_Customers/Maintenance_and_Operations/Designing_the_Architecture_of_Your_OutSystems_Applications/05_Integration_Patterns_for_Core_Services_Abstraction

Thank you and have a nice day...

Kind regards,

Chris

Rank: #246

Hi Fabio,

https://www.outsystems.com/forums/discussion/68022/problem-with-copying-structure-from-webservice/#Post272163

Has given the solution you need to follow. I don't think it will affect performance that much.


You could also make the rest-structure public and reuse it, since you are using an exact copy of it for your business logic. But this means your IS module will be referenced and therefore i would never recommend it.




Rank: #287

Hi  Fábio Rodrigues

 I don't understand your question

1, I don't want to expose the webservice direct structure into the CS (client details and best practice I guess)

2, What I need to do, is make a copy of this exact structure so I can expose it to my CS module (WebService is in IS module), 

1 and 2 look's like a contradiction.

Sorry, If I missunderstand.


Kind Regard

Rank: #3634

Hi Tom, 

The client doesn't want to expose the structure created by the web service, so we create an exact copy of it, and that's the one we reference. 

Rank: #246
Solution

It is best practice to use your own structure, even if it is in fact an exact copy. 

So, then you need to create a function that will translate each sublist of the structure into your copied structure.

I don't think this will affect your performance that much. the function should look like: 

TranslateWebListX(weblisttoconvert) with output parameter being the structure of your copied structure sublist.

Rank: #287

Hi Fábio

Sorry, Maybe because Englisht is not my native language, I still not understand your issue.
What's mean about client forbid you to expose the structure?
What's the difference?  if you expose a copy  of exactlly same structure.

Best Regards

Rank: #3634

Hey Stefano, sorry for not replying earlier but I was not on the computer,

I just tried your solution and it worked, I was thinking I had to iterate the list and call the function for every record in the list, but what you said works wonders, thanks :)

Hi Fabio,

Good morning!

That's what I'm telling you the other day (Stefano's solution). Anyways, glad it's working at your end.

Regards,

Chris