Need explanation how POPStandardItemLine works

SOLVED

Hi all,

I am looping the POPStandardItemLine or an Order using foreach loop. The item lines in the order consists of standard order line and a charge line. While looping, I encounter an error.

this is because 1 item in the POPStandardItemLine is a Charge line. 

How can I loop the lines no matter what item is inside (standard item / free text item / charge line / discount line) ?

Sage.Accounting.POP.POPStandardItemLines lines = new Sage.Accounting.POP.POPStandardItemLines();
lines.Query.Filters.Clear();
lines.Find();
lines.Query.Filters.Add(new Sage.ObjectStore.Filter(Sage.Accounting.POP.POPStandardItemLine.FIELD_POPORDERRETURNDBKEY, order.POPOrderReturn));
lines.Find();

foreach(Sage.Accounting.POP.POPStandardItemLine line in lines) // the error happen here
{ 
    //do something here
}

  • +1
    verified answer

    HI Murni,

    First you should not really be using a for each loop for a sage collection, they can cause memory leaks and performance issues, look at the enumerable operation in the developer guide

    second, loop the collection as POPOrderReturnLines and cast each line by its type

    for each line as poporderreturnline in lines
     Select Case line.LineType
                Case OrderProcessing.LineTypeEnum.EnumLineTypeStandard
    
                    Dim STDLine As Sage.Accounting.POP.POPStandardItemLine = DirectCast(line, Sage.Accounting.POP.POPStandardItemLine)
    
                    'do something
    
                Case OrderProcessing.LineTypeEnum.EnumLineTypeFreeText
                    Dim FreeText As Sage.Accounting.POP.POPFreeTextLine = DirectCast(line, Sage.Accounting.POP.POPFreeTextLine)
                    'do something
    
                Case OrderProcessing.LineTypeEnum.EnumLineTypeCharge
                    Dim ChargeLine As Sage.Accounting.POP.POPAdditionalChargeLine = DirectCast(line, Sage.Accounting.POP.POPAdditionalChargeLine)
                    'do something
    
                Case OrderProcessing.LineTypeEnum.EnumLineTypeComment
                    Dim CommentLine As Sage.Accounting.POP.POPCommentLine = DirectCast(line, Sage.Accounting.POP.POPCommentLine)
                    'do something
            End Select
    
    
    next

    But you should really look at the enumberable operation for large collections

  • 0 in reply to Toby

    thank you Toby, will try it out. But a lot of examples for Collection are using foreach. For example this: my.sage.co.uk/.../DOC0077_Overview.html

  • 0 in reply to murni

    Sorry my bad, i forgot all the details of that topic.  I was thinking of the ForwardOnly property.  Enumerable pattern is in regards to larger  collections and processess that require a lot of processing.