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.