Which one of these options is better for perfomance and practices?

Currently im working in a web project, and i have a Request with list questions with list of answer, these structures are found in the CS module, i want to assign this request to the request with the same structures created in the IS module, wich of these ways is better to do that.

This project is a Web Application and im using Outsystems 10.

and this is the other option request of the CS Structures and then a for each iterating the request and then assign to the IS structures.

Hi,

I personally do not prefer loops, did you try directly assigning without loops or serialize?

Regards.

Hi,

If you have two structures you can simple use the assign widget and do the mapping.

If you have to two lists, you can append one to the other with ListAppendAll and do the mapping.

No need to use a for loop.

Regards,

Daniel

This is what happen because is not same Structure as i said, they have the same kind of parameters.



Prasad Rao wrote:

Hi,

I personally do not prefer loops, did you try directly assigning without loops or serialize?

Regards.



Because is not the same structure this happen.


Daniël Kuhlmann wrote:

Hi,

If you have two structures you can simple use the assign widget and do the mapping.

If you have to two lists, you can append one to the other with ListAppendAll and do the mapping.

No need to use a for loop.

Regards,

Daniel



I like the For Each, it has very high readability compared to the Assign+Mapping thing imo.

Let's see if I understand, 

you start with 2 lists, a List of Questions and a List of Answers

and you want to end up with 1 List of Records where each record has an Id, a question and List of Answers.

Is this it? 


Anyway you can do For Each AnswerItemCS, assign current item's fields to the corresponding AnswerItem fields and Append the AnswerItem on the Answer List. 

(Note: you will need an AnswerItem variable to make the assignments and an AnswerItemList variable that you will append the item to)

By doing this you convert one list to the other and after doing this you can perform the Assign you posted with "same data type required" error.


I don't know for sure what's more efficient but the Assign+Mapping will also have to loop the list and make the assignments, it just does it without us seeing it.



Filipe Silva wrote:

I like the For Each, it has very high readability compared to the Assign+Mapping thing imo.

Let's see if I understand, 

you start with 2 lists, a List of Questions and a List of Answers

and you want to end up with 1 List of Records where each record has an Id, a question and List of Answers.

Is this it? 


Anyway you can do For Each AnswerItemCS, assign current item's fields to the corresponding AnswerItem fields and Append the AnswerItem on the Answer List. 

(Note: you will need an AnswerItem variable to make the assignments and an AnswerItemList variable that you will append the item to)

By doing this you convert one list to the other and after doing this you can perform the Assign you posted with "same data type required" error.


I don't know for sure what's more efficient but the Assign+Mapping will also have to loop the list and make the assignments, it just does it without us seeing it.



I tried the same way as you said, i think is easier to see and understand, but im looking for the best way to do it i know how to fix that error i got i was just showing what happened when i just assign that why i needed the for each and list append, in both options i got the same result, but the one with the serialize is easier, but in terms of performance i have some doubts.


Hi,

If u have both structure same then u can use equal Widget and assign one structure to other as well.

Thanks

Samuel Miranda wrote:

Filipe Silva wrote:

I like the For Each, it has very high readability compared to the Assign+Mapping thing imo.

Let's see if I understand, 

you start with 2 lists, a List of Questions and a List of Answers

and you want to end up with 1 List of Records where each record has an Id, a question and List of Answers.

Is this it? 


Anyway you can do For Each AnswerItemCS, assign current item's fields to the corresponding AnswerItem fields and Append the AnswerItem on the Answer List. 

(Note: you will need an AnswerItem variable to make the assignments and an AnswerItemList variable that you will append the item to)

By doing this you convert one list to the other and after doing this you can perform the Assign you posted with "same data type required" error.


I don't know for sure what's more efficient but the Assign+Mapping will also have to loop the list and make the assignments, it just does it without us seeing it.



I tried the same way as you said, i think is easier to see and understand, but im looking for the best way to do it i know how to fix that error i got i was just showing what happened when i just assign that why i needed the for each and list append, in both options i got the same result, but the one with the serialize is easier, but in terms of performance i have some doubts.


You can also use an IF in this way, implementing what I like to call a While loop in Outsystems.

I have no idea if it's faster or not but there you go.


Filipe Silva wrote:

Samuel Miranda wrote:

Filipe Silva wrote:

I like the For Each, it has very high readability compared to the Assign+Mapping thing imo.

Let's see if I understand, 

you start with 2 lists, a List of Questions and a List of Answers

and you want to end up with 1 List of Records where each record has an Id, a question and List of Answers.

Is this it? 


Anyway you can do For Each AnswerItemCS, assign current item's fields to the corresponding AnswerItem fields and Append the AnswerItem on the Answer List. 

(Note: you will need an AnswerItem variable to make the assignments and an AnswerItemList variable that you will append the item to)

By doing this you convert one list to the other and after doing this you can perform the Assign you posted with "same data type required" error.


I don't know for sure what's more efficient but the Assign+Mapping will also have to loop the list and make the assignments, it just does it without us seeing it.



I tried the same way as you said, i think is easier to see and understand, but im looking for the best way to do it i know how to fix that error i got i was just showing what happened when i just assign that why i needed the for each and list append, in both options i got the same result, but the one with the serialize is easier, but in terms of performance i have some doubts.


You can also use an IF in this way, implementing what I like to call a While loop in Outsystems.

I have no idea if it's faster or not but there you go.


Thanks, i have tried those options, i dont like that much use a if like that, i was looking for a way to use List append or the List Append all, or the Serealize because is cleaner, and i wanted to know wich one is better for performance or good practices.


Shoeb Khan wrote:

Hi,

If u have both structure same then u can use equal Widget and assign one structure to other as well.

Thanks


Hi, wich is the Equal Widget? i dont think i have see that widget. maybe i need to reference something

Samuel Miranda wrote:

Because is not the same structure this happen.


Daniël Kuhlmann wrote:

Hi,

If you have two structures you can simple use the assign widget and do the mapping.

If you have to two lists, you can append one to the other with ListAppendAll and do the mapping.

No need to use a for loop.

Regards,

Daniel




HI Samuel,

Looks like the definition of your both the structure are same but they are defined in 2 different modules with different name i.e. why you are not able to assign them.

you can move the structure for 3rd common module and make it public to both the modules and then use this structure in your application, then you can easily assign it.

Regards,

Manish Jawla

Manish Jawla wrote:

Samuel Miranda wrote:

Because is not the same structure this happen.


Daniël Kuhlmann wrote:

Hi,

If you have two structures you can simple use the assign widget and do the mapping.

If you have to two lists, you can append one to the other with ListAppendAll and do the mapping.

No need to use a for loop.

Regards,

Daniel




HI Samuel,

Looks like the definition of your both the structure are same but they are defined in 2 different modules with different name i.e. why you are not able to assign them.

you can move the structure for 3rd common module and make it public to both the modules and then use this structure in your application, then you can easily assign it.

Regards,

Manish Jawla

Thanks Well those structures are from a Rest API of an IS module, so i can't move them. The other one is created in the CS module.


Hi,

Then its better to add values through loop and assign all attributes one by one and append in the list.

Hope this help.

Thanks

Shoeb Khan wrote:

Hi,

Then its better to add values through loop and assign all attributes one by one and append in the list.

Hope this help.

Thanks

Why? i want to know if this is a better way to do it. thanks! 

Solution

I found that is better and easier with JSONserealize is the same response, but you dont take reference from the IS module to the CW or EU. Thanks

Solution