Iterate through a Buismess Object


Author
Message
Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
I am trying to set up a piece of code just to loop through a BO. Took the code below from training class manual but  cant get intellisense on BoType

foreach  (BoType bo in myBo,GetEnumerable() )
{ MessageBox.Show(.....); }

Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Gerald,



This is something I use a lot Smile Here is the vb version:



For Each record As bizTransactionItems In Me.BizTransactionItems1.GetEnumerable()

record.QBInvoiceRefID = .RefId

record.QBInvoiceNumber = .RefNumber

Next record





Where "record" is the object based on the main class of the business object, not the instance in the form. and Me.BizTransactionItems1 is the instance class in the form. Whatever you do with "record" it is actually happening in Me.BizTransactionItems1 real time, except that GetEnumerable() will keep the record pointer "CurrentRowIndex" updated for you, so don't need to worry about it. w00t



Enjoy!!!!

Edhy Rijo

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Edhy right on the money, as usual. Wink



Here is the C# code you might use.



Sample #1: Looping through a BO dropped on a form. Assume you have a BO you've built called MySpecialBO. You've dropped an instance on a form and the instance is named MySpecialBO1.

foreach(MySpecialBO boRow in this.MySpecialBO1.GetEnumerable())

{

  //-- Do something with boRow. Each loop will move it to next row in data table,

  //   only you can use the strongly typed properties to access data.

}




Sample #2: Looping through the BO within the BO itself. We'll use MySpecialBO again, but this time we're doing this inside an instance method.

foreach(MySpecialBO boRow in this.GetEnumerable())

{

  //-- Do something with boRow. Each loop will move it to next row in data table,

  //   only you can use the strongly typed properties to access data.

}

Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
Edhy and greg..many thanks for your replies.

I am getting a ...ideBo1 is a field but is used as a type compile error message. ideBo1 is an instance of the BO on the form and is fine in all other processing.  Must be something very simple but I cant see it ??

foreach (ideBO1 boRow in this.ideBO1.GetEnumerable())
{ MessageBox.Show(ideBO1.IDE_STKREF); }


Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Gerard,



It should be:



foreach (ideBO boRow in this.ideBO1.GetEnumerable())

{ MessageBox.Show(ideBO1.IDE_STKREF); }


Edhy Rijo

Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
Hi Edhy. Thanks for that. I did not see that is was the Business Object as opposed to the instantiated Business Object that goes with the Foreach. Its compiling now.

regards, Gerard

Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Gerard,



Glad it is working for you. Tongue



I've been there many times when the .GetEnumerable() was introduced by Trent 2 years ago and I was fairly new to all .Net, but now I use this all over, it is easy, fast and reliable since it will not affect the actual CurrentRowIndex of the BO instance in the form.

Edhy Rijo

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search