Skip to main content
Answer

Having trouble with CombineReports - only getting first and last orders to print

  • May 13, 2025
  • 2 replies
  • 82 views

Joe Schmucker
Captain II
Forum|alt.badge.img+3

I have a customer who wants to mass print Pick Tickets for sales orders with any status.

I created a custom processing screen to do this.  The screen works perfectly with the exception that I am only getting the first order in the list and the last order in the list.  I selected 8 records to print and verified that all 8 were in the list being processed in debug mode.  I found an article on stackoverflow where someone had a similar issue.  His issue was fixed by adding the MergeLast as false on the last record being added to the report.  I used a counter to find if the item being added was the last one, and put false in for the MergeLast parameter.  Did not help.

Here is my graph:

	public class ICSPrintPickTicketsProcess : PXGraph<ICSPrintPickTicketsProcess>
{

public PXFilter<Filter> FilterView;
public PXCancel<Filter> Cancel;

public PXFilteredProcessing<SOOrder, Filter,
Where<SOOrder.orderType, Equal<SOOrderTypeConstants.salesOrder>>,
OrderBy<Desc<SOOrder.orderNbr>>> DetailsView;

protected virtual IEnumerable detailsView()
{
Filter filter = FilterView.Select();

DetailsView.Cache.Clear();

PXSelectBase<SOOrder> query = new PXSelect<SOOrder,
Where<SOOrder.orderType, Equal<SOOrderTypeConstants.salesOrder>>,
OrderBy<Desc<SOOrder.orderNbr>>>(this);

if (filter.OrderStatus == "O")
{
query.WhereAnd<Where<SOOrder.status, Equal<SOOrderStatus.open>>>();
}
else
{
query.WhereAnd<Where<SOOrder.status, Equal<SOOrderStatus.completed>>>();
}

if (filter.ShowPreviouslyPrinted == null || filter.ShowPreviouslyPrinted == false)
{
query.WhereAnd<Where<AFSOOrderExt.usrPickTicketsPrinted, Equal<False>, Or<AFSOOrderExt.usrPickTicketsPrinted, IsNull>>>();
}
else
{
query.WhereAnd<Where<AFSOOrderExt.usrPickTicketsPrinted, Equal<True>>>();
}

foreach (SOOrder item in query.Select())
{
yield return item;
}
}

public ICSPrintPickTicketsProcess()
{
DetailsView.SetProcessCaption("Print Selected");

//DetailsView.SetProcessAllCaption("Print All");
DetailsView.SetProcessAllVisible(false);

DetailsView.SetSelected<SOOrder.selected>();

DetailsView.SetProcessDelegate(
delegate (List<SOOrder> list)
{
DoIt(list);
});
}

public static void DoIt(List<SOOrder> list)
{
int counter = 0;
int countTotal = list.Count;

var myGraph = PXGraph.CreateInstance<ICSPrintPickTicketsProcess>();

PXReportRequiredException ex = null;

foreach (SOOrder salesOrder in list)
{

PXProcessing<SOOrder>.SetCurrentItem(salesOrder);

counter++;

Dictionary<string, string> dictionary = new Dictionary<string, string>();
dictionary["OrderType"] = "SO";
dictionary["OrderNbr"] = salesOrder.OrderNbr;

if (counter != countTotal)
{
ex = PXReportRequiredException.CombineReport(ex, "IC641090", dictionary, true);
}
else
{
//last one so put false
ex = PXReportRequiredException.CombineReport(ex, "IC641090", dictionary, false);
}

PXProcessing.SetInfo(list.IndexOf(salesOrder), ICSMessages.PTSuccess);

//This updates the custom field to indicate it was printed
SOOrder currentOrder = SelectFrom<SOOrder>.Where<SOOrder.orderNbr.IsEqual<@P.AsString>
.And<SOOrder.orderType.IsEqual<SOOrderTypeConstants.salesOrder>>>.View.Select(myGraph, salesOrder.OrderNbr);
if (currentOrder != null)
{
AFSOOrderExt ext = currentOrder.GetExtension<AFSOOrderExt>();
if (ext != null)
{
ext.UsrPickTicketsPrinted = true;
myGraph.DetailsView.Update(currentOrder);
}
}

if (counter == countTotal)
{
myGraph.DetailsView.Cache.Persist(PXDBOperation.Update);

ex.Mode = PXBaseRedirectException.WindowMode.New;
//ex.SeparateWindows = false;
throw ex;
}
}
}


[Serializable]
[PXHidden]
public class Filter : PXBqlTable, IBqlTable
{
#region OrderStatus
[PXString(1, IsFixed = true)]
[PXDefault(ICSMessages.Open)]
[PXUIField(DisplayName = "Order Status", Enabled = true)]
[PXStringList(
new string[]
{
ICSConstants.Open,
ICSConstants.Completed
},
new string[]
{
ICSMessages.Open,
ICSMessages.Completed
})]
public virtual string OrderStatus { get; set; }
public abstract class orderStatus : PX.Data.BQL.BqlString.Field<orderStatus> { }
#endregion

#region ShowPreviouslyPrinted
[PXBool]
[PXDefault(false, PersistingCheck = PXPersistingCheck.Nothing)]
[PXUIField(DisplayName = "Show Previously Printed")]
public virtual bool? ShowPreviouslyPrinted { get; set; }
public abstract class showPreviouslyPrinted : PX.Data.BQL.BqlBool.Field<showPreviouslyPrinted> { }
#endregion





}

}

 

The pertinent code is in the DoIt method.  If you select one record, perfect.  If you select multiple records (Sales Orders), you get 2 pages on the report.  The first order and the last order in the list.

Please help.

Best answer by Joe Schmucker

Update.  The code I thought worked only worked for 1 or 2 selected records.  That was the only testing I did with it and I thought it was fixed.  This is the code I ended up with in case any else has this issue.  Putting False in the ex line seems wrong, but it is the only way it works.

            foreach (SOOrder salesOrder in list)
            {

                counter++;

                Dictionary<string, string> parameters = new Dictionary<string, string>();
                parameters["OrderType"] = filter.OrderType;
                parameters["OrderNbr"] = salesOrder.OrderNbr;

                ex = PXReportRequiredException.CombineReport(ex, "IC641090", parameters, false);

                //if (counter != countTotal)
                //{
                //    ex = PXReportRequiredException.CombineReport(ex, "IC641090", parameters, false);
                //}
                //else
                //{
                //    //last one so put false
                //    ex = PXReportRequiredException.CombineReport(ex, "IC641090", parameters, true);
                //}

            }

            if (ex != null)
            {

                ex.Mode = PXBaseRedirectException.WindowMode.New;
                //ex.SeparateWindows = false;
                throw ex;
            }
 

 

2 replies

Joe Schmucker
Captain II
Forum|alt.badge.img+3
  • Author
  • Captain II
  • May 14, 2025

I fixed the issue.  I flip flopped the true and false as shown below.  I am not sure why this is the fix because the true and false don’t seem logical to me based on what I’ve found online.

if (counter != countTotal)
{
ex = PXReportRequiredException.CombineReport(ex, "IC641090", parameters, false);
}
else
{
//last one so put TRUE, not FALSE
ex = PXReportRequiredException.CombineReport(ex, "IC641090", parameters, true);
}

 


Joe Schmucker
Captain II
Forum|alt.badge.img+3
  • Author
  • Captain II
  • Answer
  • May 15, 2025

Update.  The code I thought worked only worked for 1 or 2 selected records.  That was the only testing I did with it and I thought it was fixed.  This is the code I ended up with in case any else has this issue.  Putting False in the ex line seems wrong, but it is the only way it works.

            foreach (SOOrder salesOrder in list)
            {

                counter++;

                Dictionary<string, string> parameters = new Dictionary<string, string>();
                parameters["OrderType"] = filter.OrderType;
                parameters["OrderNbr"] = salesOrder.OrderNbr;

                ex = PXReportRequiredException.CombineReport(ex, "IC641090", parameters, false);

                //if (counter != countTotal)
                //{
                //    ex = PXReportRequiredException.CombineReport(ex, "IC641090", parameters, false);
                //}
                //else
                //{
                //    //last one so put false
                //    ex = PXReportRequiredException.CombineReport(ex, "IC641090", parameters, true);
                //}

            }

            if (ex != null)
            {

                ex.Mode = PXBaseRedirectException.WindowMode.New;
                //ex.SeparateWindows = false;
                throw ex;
            }