Limiting the number of sales orders returned in the SalesOrderFactory

SOLVED

Is there a way to limit the number of sales orders that are returned when using the SalesOrderFactory by specifying some type of parameter? I'd like to just return a set of orders for a date range instead of every Sales Order on the system. I'm having to loop through thousands of orders returned in the list to get the ones I want and the performance is terrible.

  • 0
    verified answer

    You can limit the number of sales orders by adding filters.  Here's an example where I set up a date range filter for Receipts:

             Receipts = Company.Factories.ReceiptFactory.List();

    // Note, I have a using statement for "using API_COLLECTIONS = Sage.Peachtree.API.Collections.Generic";
    API_COLLECTIONS.FilterExpression filterExpression = 
    API_COLLECTIONS.FilterExpression.GreaterThanOrEqual( API_COLLECTIONS.FilterExpression.Property("Receipt.Date"),
                                                                                                     API_COLLECTIONS.FilterExpression.Constant(new DateTime(2015, 3, 1)) );

    API_COLLECTIONS.FilterExpression filterExpression2 =
    API_COLLECTIONS.FilterExpression.LessThan( API_COLLECTIONS.FilterExpression.Property("Receipt.Date"),
                                                                                   API_COLLECTIONS.FilterExpression.Constant(new DateTime(2015, 4, 1)) );

    API_COLLECTIONS.LoadModifiers modifier = API_COLLECTIONS.LoadModifiers.Create();
    modifier.Filters = API_COLLECTIONS.FilterExpression.AndAlso(filterExpression, filterExpression2);
    modifier.Filters = filterExpression;

    Receipts.Load(modifier);

    Hope it helps!

  • 0 in reply to Latoria

    Thanks so much. That makes my application run SO much faster.