Other OutSystems sites...
OutSystems Website
About Agility Blog
OutSystems Network
Login
Signup
Forums
Academy
Forge
Ideas
Forums
›
Guides & How-tos
›
[Tip] How to correctly iterate a Record List inside an Extension
Outsystems Certified Discussion
[Tip] How to correctly iterate a Record List inside an Extension
OS-Certified
Extension
João Portela
Rank: #25
Posted on 2011-05-04
thumbs_up_ico
12
thumbs_down_ico
0
reply
post_link_ico
Hi guys,
In the last few months I've been seeing lots of Extensions with incorrect patterns used for iterating Record Lists.
These wrong patterns can produce wrong and unexpected behaviors/results, the most common being missing some entries when doing the iteration.
This post shows how to correctly iterate a Record List in an extension.
The following code snippet illustrates the correct pattern:
try {
// Call Record List "StartIteration" to ensure the iteration starts from the beginning of the list
recordList.StartIteration();
// Record List "Eof" property indicates if we're in the end of the list
while (!recordList.Eof) {
// access "CurrentRec" to retrieve current record information
string attrName = recordList.CurrentRec.ssSTMyEntity.ssName;
// call "Advance" to move to the next record in the list
recordList.Advance();
}
} finally {
// in the finally, call "EndIteration" to indicate that we're no longer iterating the record
// we must call this function to allow other record list operations, e.g., list-append, list-remove, etc
recordList.EndIteration();
}
If you are using extensions developed in your company and have actions that use Record Lists, and are having unexpected behavior, you should look into the source code to check if the correct iteration pattern is being used, and fix it if that is the case.
If you have any question or comments, please let me know.
Regards,
João Portela
Rui Eugenio
Rank: #197
Posted on 2011-05-04
thumbs_up_ico
4
thumbs_down_ico
0
reply
post_link_ico
By the way, the Java code is very similar:
try {
// Call Record List "
startIteration
" to ensure the iteration starts from the beginning of the list
recordList.
startIteration
();
// Record List "Eof" property indicates if we're in the end of the list
while (!recordList.
isEof()
) {
// access "
currentRec
" to retrieve current record information
string attrName = recordList.
currentRec
.ssSTMyEntity.ssName;
// call "
advance
" to move to the next record in the list
recordList.
advance
();
}
} finally {
// in the finally, call "
endIteration
" to indicate that we're no longer iterating the record
// we must call this function to allow other record list operations, e.g., list-append, list-remove, etc
recordList.
endIteration
();
}
Regards,
Rui Eugénio
Paulo Tavares
Rank: #5
Posted on 2011-05-04
thumbs_up_ico
0
thumbs_down_ico
0
reply
post_link_ico
Great tip guys. Definitely one to go to the Guides and How Tos forum section.
Regards,
Paulo Tavares
Antonio Xeira
Rank: #249
Posted on 2012-11-08
thumbs_up_ico
0
thumbs_down_ico
0
reply
post_link_ico
Hello all
And what about in the opposite direction?
Fill a Record List inside an extension and pass it to OS?
Is there an How to?
Antonio
João Portela
Rank: #25
Posted on 2012-11-09
thumbs_up_ico
4
thumbs_down_ico
0
reply
post_link_ico
ExtensionTopic.xif
Hi António,
Follows a sample how to insert a record (entity/structure) in a record list, in a extension:
public void MssExportLists(out RLMyEntityRecordList ssMyEntityList, out RLMyStructureRecordList ssMyStructureList) {
// entity record list creation
ssMyEntityList = new RLMyEntityRecordList(null);
// entity record creation
RCMyEntityRecord ssMyEntityRecord = new RCMyEntityRecord (null);
ssMyEntityRecord.ssENMyEntity.ssParam1 = "value 1 of entity record";
//ssMyEntityRecord.ssENMyEntity.ssParam1 = "value 1 of entity record";
// append entity record to the entity record list
ssMyEntityList.Append( ssMyEntityRecord);
// structure record list creation
ssMyStructureList = new RLMyStructureRecordList(null);
//structure record creation
RCMyStructureRecord ssMyStructureRecord = new RCMyStructureRecord(null);
ssMyStructureRecord.ssSTMyStructure.ssParam1 = "value 1 of entity record";
//ssMyStructureRecord.ssSTMyStructure.ssParam1 = "value 1 of entity record";
// append structure record to the structure record list
ssMyStructureList.Append(ssMyStructureRecord);
} // MssExportLists
Relevant information:
when creating a Record object (RC<name>Record), always use the construcutre with null parameter, this constructior performs internal initializations (the constructor without parameter won't do)
use the "Append" function of the record list to append a single record
I've also attached a sample extension.
Notice: I've created this extension in Integration Studio 7.00.14 . In other versions/revisions there could be changes in the record/structure/record-lists internal structure.
Regards,
João Portela
Gonçalo Martins
Rank: #35
Posted on 2012-11-09
thumbs_up_ico
0
thumbs_down_ico
0
reply
post_link_ico
Hi João and Rui,
Excellent performance tips..
Share more tips of this kind..:)
Cheers,
Gonçalo Martins
Antonio Xeira
Rank: #249
Posted on 2012-11-09
thumbs_up_ico
0
thumbs_down_ico
0
reply
post_link_ico
Awesome.
It is working.. :-)
Quick Reply
Notify me by email when someone answers to my post
attachment
Choose File
No file chosen
Submit
Login to reply
Something on your mind?
Login to Start a Discussion
RELATED DISCUSSIONS
How to downgrade solution code upgraded to Visual Studio 2010
HOWTO use .Net or Java data structures in the OutSystems apps (Hastable, etc)
Tip: Extensions using .NET 3.5 fail compilation in Integration Studio
SQL Server database error: 'PRIMARY' filegroup is full
[J2EE] How to increase OutSystems Services log level for troubleshooting
FIND MORE
Top Forums Posters
Gonçalo Martins
Ricardo Silva
Charles Colaço
João Rosado
André Vieira
Arnold Grippeling
Gerry
Robert Chanphakeo
JD
Justin James
See leaderboard
Online Training
On-demand video lessons to help you learn at your own pace.
Learn More