Okay, to start with my goal is to prevent users from reprinting the same Order Number in SO Pick List. So if they the So Picklist has printed the Order Number once, if they try to print again it won’t appear in the pick list again.
The simple workflow that I was going for is:
- Systask check for Report “SO Pick list” and Status is “COMPLETE”
- Code runs to insert + 1 in the counter and insert date into counterdate field
- The report printed will filter out the order number with count > 0
What I have done so far is:
-
Created 2 UD fields in OrderHed SOPickListPrintDate_c and SOPickPrintCount_c to be used to enter the date the order number was last printed and a counter which defaults starts at 0.
-
Then I have modify the SOPick report to filter out the order numbers that has SOPickPrintCount_c more than 0.
-
Then, I modified the code from the link below to fit do the same insertion
Committing updated record to database from a report form - #5 by LReynolds
However, I noticed after modifying and using the code above that there were a few issues with code insertion.
Scenario 1 - Users don’t filter any Order Number and the SO Pick List Report just takes all Order that meets the Date Range requirement.
Results: Report printed all within range but my code did not insert anything because it was checking by Orderlist which was empty. Upon studying I found that it was because my code was using the Orderlist and when no Order Number was taken, the Orderlist is “”.
Scenario 2 - Order filters out say 2 orders, but 1 of the order NeedByDate is not in report filter range.
Results: The report printed out only 1 order number but my code inserts into the 2 Order Number rows instead of only 1.
For both the scenarios I realise I need to pull out the Filter Range Date value in the SO Pick List for my code so it can insert to the correct counter fields BUT I need to have it done in SysTask because I only want the counter to be inserted AFTER Report has run “COMPLETE” and not insert if it ran on “ERROR”.
My code in SysTask is as per below:
string[] OrderArray = new string[] {};
int[] myInts = new int[] {};
char[] Separator = {'~'};
string Orders;
foreach (var ttSysTaskRow in (from ttSysTaskRow in ttSysTask where ttSysTaskRow.TaskDescription == "SO Pick list" select ttSysTaskRow))
{
foreach (var SysTaskParam_iterator in Db.SysTaskParam.Where(SysTaskParam_Row=> SysTaskParam_Row.SysTaskNum == ttSysTaskRow.SysTaskNum && SysTaskParam_Row.ParamName == "OrderList"))
{
Orders = SysTaskParam_iterator.ParamCharacter;
if(Orders == ""){
//SOPickListReportParam ds = new SOPickListReportParam();
//SOPickListReportParam[0]
//Add The Date Range in Filter to filter out the orderHed NeedByDate field?
foreach (var OrderHed_iterator in Db.OrderHed.Where(OrderHed_Row=> OrderHed_Row.VoidOrder == false && OrderHed_Row.OpenOrder == true && OrderHed_Row.OrderNum == 0 && OrderHed_Row.Company == callContextClient.CurrentCompany)){
OrderHed_iterator.SOPickListPrintDate_c = DateTime.Today;
OrderHed_iterator.SOPickPrintCount_c = OrderHed_iterator.SOPickPrintCount_c+1;
//OrderHed_iterator.SOPickPrintCount_c = 0;
}
}else{
OrderArray = Orders.Split(Separator);
myInts = Array.ConvertAll(OrderArray, int.Parse);
foreach (int order in myInts){
//Add The Date Range in Filter to filter out the orderHed NeedByDate field?
foreach (var OrderHed_iterator in Db.OrderHed.Where(OrderHed_Row=> OrderHed_Row.VoidOrder == false && OrderHed_Row.OpenOrder == true && OrderHed_Row.OrderNum == order && OrderHed_Row.Company == callContextClient.CurrentCompany)){
OrderHed_iterator.SOPickListPrintDate_c = DateTime.Today;
OrderHed_iterator.SOPickPrintCount_c = OrderHed_iterator.SOPickPrintCount_c+1;
}
}
}
}
}
Db.Validate();
====
The only way I can currently think of is to add a UD field into the Systask table and use that to pass parameter from the Erp.Rpt.SOPickListReport.SubmitToAgent method you mentioned but I’m wondering if there is another to pull it without having to do this.