Convert Structure list to record list?

Convert Structure list to record list?

  

I have an integration function that takes a Record List of type Text as input.

When I try to pass it a List of Text structures in Service Studio 10 I get the error:
"Expected Text Record instead of Text."

How do I create a list of Text-structure Records to pass to my function?

You can create a Text List or a Text Record List. Instead of passing a "Text List" try to pass a "Text Record List", maybe that's the issue?

I don't know what is the difference between "List" and "Record List", seems the same thing

Here are the relevent parts:

In Integration Studio:

This is the variable definition:


And this is the expression and error message:

Oh!  YOu were right!

I had the variable defined as List of Text,  changing it to List of Record(Text) fixed it!

Thanks, this had me badly stalled.

Nice to know that was enough to solve it.

I don't know what's the difference between "List of" and "List of Record", seems to be the same thing. Can someone explain the difference?

As I understand it, List of <structure>  is a list of structures, which are temporary in memory things.
List of <record> <structure> is a list of records whose fields match those of the given structure.

The Structure/Record thing IS an odd distinction I'm still trying to wrap my head fully around.

Solution

I'll try to shine some light on the difference between Record Lists and Lists. In the olden days, before version 9, there were only Record Lists. A Record List is a list or Records. You can think of a Record as a container of one or more Structures or Entity Records (yeah, en Entity Record is actually not a Record). Typically, if you have a query (SQL or Aggregate), you'll output multiple Entity Records. These are grouped together in a Record. So the output of a query is always a Record List.

The downside of a Record or Record List is that you'll always have to name both the Record name and the Structure or Entity name if you want to reference an attribute. Say you have a Record variable with name MyData, containing a single structure called MyStruct with an attribute called MyValue, you need to type MyData.MyStruct.MyValue. This makes sense if the same Record also contains a structure called MyStruct2, so you can also say MyData.MyStruct2.MyOtherValue for example. But if there's only a single structure, having to type MyStruct every time is laborious. With Record Lists, the path gets even longer: MyDataList.Current.MyStruct.MyValue.

Secondly, the Records of old could only contain Structures, Entity Records and/or other Records. Not "simple types" like Text, Integer or Decimal. So if you needed a list of integers, you needed to create a structure with a single, integer, attribute, to be able to do that.

Starting with version 9, this all changed with the introduction of "simple" Lists or just Lists. These Lists can contain Structures, Entity Records and simple types directly, without wrapping them in a Record or, in case of simple types, also first in a structure. This also makes it easier referencing the attibutes: in the example above, having a Record of MyStruct, you can reference MyValue simply with MyData.MyValue (or MyDataList.Current.MyValue in case of a List). For lists of simple types, MyList.Current yields the value (instead of the MyList.Current.MyIntegerStruct.Value of old).

Now, in Service Studio, dealing with Record Lists and Lists is made pretty transparent. When assigining, or when passing as parameter, Lists are converted to Record Lists and back when needed (and vice versa). It's still good to make sure you only need Record Lists when really needed, because conversion gives overhead, especially with long lists. Also note that conversion is not available when calling a Function from an expression.

For extensions, dealing with Record Lists has a specific API available. In fact, Integration Studio doesn't even know Lists of simple types, only Record Lists. Some extensions, like XMLRecords or SortRecordList deal with generic Record Lists, i.e. the Structure is not defined in the extension itself. They typically use reflection to find out what the structure of the Records are. Dealing with Lists this way is far from trivial (the elements have a different internal structure), so not all extensions are reworked to support this.

I hope this clarifies it a bit. If not, let me know.






Solution

What is the equivalent of ListAppend in a For Loop?

I have an entity record list from an Attribute/ Query and want to append values returned a list for all records returned by the query.

Since I cannot use ListAppend in a For Loop, how can I do this?

I need this as I'm trying to create a timeline of event dates.

Your help will be appreciated.

Seth wrote:

What is the equivalent of ListAppend in a For Loop?

I have an entity record list from an Attribute/ Query and want to append values returned a list for all records returned by the query.

Since I cannot use ListAppend in a For Loop, how can I do this?

I need this as I'm trying to create a timeline of event dates.

Your help will be appreciated.

Hi Seth,

You have the option to use ListAppendAll, when not iterating over the list, or ListAppend if you are looping over the list.

I'm not sure if I am understanding your problem clearly. Why can you not use ListAppend in a for loop?

Let me know,

Justin


Hi Seth,

Apparently, you are confusing two things. When iterating over a List, you cannot modify that list, i.e. you can't ListAppend(All) to it, you can't ListDelete or ListInsert it etc. But it is perfectly possible to use those actions on another list, one that is not iterated over.

Note that if you are on P10 (i.e. version 10 of the Platform), there's a whole bunch of new List actions that you can use to create a new list from a list without iterating over it.

Thank you Justin and Kilian for your assistance.

I refrained from using ListAppend in the For Loop as I read from OutSystems online Learning material found below that you cannot use ListAppend in a For Loop.

http://www.outsystems.com/help/servicestudio/9.1/index.htm#t=Language_Reference%2FSystem_Actions_and_Functions%2FListAppend_Action.htm

I listened to you and decided to use it as advised and it worked. I guess Outsystems needs to update the online learning material's Remarks as shown above.

Much appreciated

Hi Seth,

I agree the help file is not very clear, but it says whay I also said: you can't use a ListAppend on a list being iterated over. The litteral text is:

"You cannot execute this action when you are managing a List inside a For Each loop."

"managing a List" is indeed very unclear language, and it also omits that you can't Append to the "managed" list, but you can to other lists. So that's the rule: no changing a list that's used in the For Each, but you can ListAppend to other lists*.

*Note that if you assign a List variable to another List, both point to the same list. Use ListDuplicate if you really need a copy.