Appending Multiple Elements to a Text List

I have stored two values coming from a consumed API in two local variables.

I'm doing a string manipulation between that two values then append into a text list then looping over the strings in text lists and doing some other stuff.

So, On Today, I had to create almost 30 Append actions for this. Could not find a way to append them as multiple elements to Text List, because the Text list does not have predefined structure.

This works, but I'm interested to hear any other solutions that could work better. 

Solution

Hi Daniel, how are you?

If you're looking for improving the performance of your logic, I recommend you take a look at the stringbuilder pattern: https://success.outsystems.com/Documentation/Development_FAQs/How_to_create_large_strings_with_StringBuilder.


But if you're trying to improve the logic itself, with what you described and if I got it right, something you can do is concatenate everything into a string variable, separating by a known character, and in the end of your logic, split it into a list by that character. This way you'll only be manipulating a string value and only worrying about the list in the end of the logic. You can combine this approach with the stringbuilder pattern as well.

If you want to discuss it in more details, I'd be happy to help. Just share more details about your current logic.

Solution

Hi Daniel,

I am a little unclear on what you are attempting, but I guess you have some structured data, that you are inserting into a text list.  If I'm incorrect, thats fine, you can ignore this comment.

Is it possible to change the text list to a list of a structure? That way you can keep the values you require together and reduce the number of list appends you have to do.

If not, I sometimes create a helper function that has 10 or so attributes that will do the listappend and return the list.  Note this makes a deep copy of the list, so is not efficient if you are dealing with thousands of items.

I will quite often create a structure, then a local variable as a list of that structure, then elements to that structure.

Additionally, so I do not require separate assign and listappend actions, I create a dummy structure with only a text attribute called dummy.

In the list append call I put the dummy in as the record to append, which causes the IDE to open a mapping of attributes.  It actually looks like this is no longer required, becase a plus '+' will appear when you hover over a list append on a list of structures to open the mapping to attributes.

When the mapping panel is open, you can assign the values to the structure directly.

I hope this helps.

Kind regards,

Stuart

João Melo wrote:

Hi Daniel, how are you?

If you're looking for improving the performance of your logic, I recommend you take a look at the stringbuilder pattern: https://success.outsystems.com/Documentation/Development_FAQs/How_to_create_large_strings_with_StringBuilder.


But if you're trying to improve the logic itself, with what you described and if I got it right, something you can do is concatenate everything into a string variable, separating by a known character, and in the end of your logic, split it into a list by that character. This way you'll only be manipulating a string value and only worrying about the list in the end of the logic. You can combine this approach with the stringbuilder pattern as well.

If you want to discuss it in more details, I'd be happy to help. Just share more details about your current logic.

Amazing Answer.

I used StringBuilder and StringSplit together like you suggested and it resulted strings as expected .