I have a custom code widget in my UBAQ custom action. The code should look at the grid, count the checked rows, and set the variable. It seems to be double counting. When I check on row, it says 2, when i check 3 rows it says 6. Rather than just divide by 2, can you help me figure out what is causing this code to return double the number I expect?
var ttResults_xRow = (from ttResults_Row in queryResultDataset.Results where ttResults_Row.Calculated_NewRelease == true select ttResults_Row);
totalrows = ttResults_xRow.Count();
Other than the fact that I always get totalrows * 2, this works well. It also works in classic without any issues.
In a similar custom code widget I am adding up the number of CloseCount. This also duplicates. If my view has 2 rows checked, then the publishinfo message counts up 1, 2, 3 then 4, and ends with close count at 4 instead of 2. I think this is related to the original issue, and one solution may solve both.
CloseCount=0;
DelCount=0;
UpdateCount=0;
RelCount=0;
ManualUp=0;
CloseOrder=false;
// step through each row of results
foreach (var xRow in (from ttResults_Row in queryResultDataset.Results where ttResults_Row.Calculated_CloseRelease == true || ttResults_Row.Calculated_UseGEDate == true || ttResults_Row.Calculated_Manual == true select ttResults_Row))
{
//parse out order, line, rel from calculated field.
MyOrder = System.Convert.ToInt32(xRow.OrderRel_OrderNum);
MyLine = System.Convert.ToInt32(xRow.OrderRel_OrderLine);
MyRel = System.Convert.ToInt32(xRow.Calculated_MinRel);
//if Calculated_CloseRelease then close the open release
// We really want to delete these releases as long as they have not been shipped on, and they do not have any jobs created on them, and they are not the only release on a line.
if (xRow.Calculated_CloseRelease == true)
{
using (Erp.Contracts.SalesOrderSvcContract soSvc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.SalesOrderSvcContract>(Db))
{
Erp.Tables.OrderRel OrderRel;
var ORel = (from OrderRel_Row in Db.OrderRel
where OrderRel_Row.Company == Session.CompanyID &&
OrderRel_Row.OrderNum == MyOrder &&
OrderRel_Row.OrderLine == MyLine
select OrderRel_Row); //Get the OrderRel record to update...
if (ORel != null)
{
RelCount = ORel.Count();
}
if ((xRow.Calculated_Shipped >= 1) || (xRow.Calculated_MinJob != string.Empty || RelCount == 1)) //cant delete release, so close it
{
using (var txscope1 = IceDataContext.CreateDefaultTransactionScope())
{
foreach (var rels in (from rRow in Db.OrderRel where rRow.OrderNum == MyOrder && rRow.OrderLine == MyLine && rRow.OrderRelNum == MyRel select rRow))
{
if (rels != null)
{
rels.Character01 = BpmFunc.Now() + " System closed release " + MyRel + " in order " + MyOrder + " on line " + MyLine + ". " + " Shipped: " + xRow.Calculated_Shipped + " FirstJob: " + xRow.Calculated_MinJob;
Db.Validate(rels);
txscope1.Complete();
}
}
}
soSvc.CloseRelease(MyOrder, MyLine, MyRel);
soSvc.Update(ref MyVar1);
CloseCount = CloseCount + 1;
String message = ("Close Count: " + CloseCount);
//this.PublishInfoMessage(message, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
}
else // not closing release, so delete it
{
{
SalesOrderTableset SOTS = soSvc.GetByID(MyOrder);
var desiredReleases = SOTS.OrderRel.Where(r => r.OrderLine == MyLine && r.OrderRelNum == MyRel);
foreach(var rel in desiredReleases)
{
rel.RowMod = "D";
DelCount = DelCount + 1;
}
soSvc.Update(ref SOTS);
var openRels = SOTS.OrderRel.Where(r => r.OpenRelease == true);
if (openRels.Count() == 0)
{
soSvc.CloseOrderLine(MyOrder, MyLine);
soSvc.Update(ref SOTS);
}
var openLines = SOTS.OrderDtl.Where(r => r.OpenLine == true);
if (openLines.Count() == 0)
{
soSvc.CloseOrder(MyOrder);
soSvc.Update(ref SOTS);
CloseOrder=true; // this flag allows the memo to be created in the next widgets.
}
}
}
xRow.Calculated_CloseRelease = false;
}
}
//if Calcualted_UseGEDate then change our date to ge date
if (xRow.Calculated_UseGEDate == true)
{
// check to see if there is a valid date to update to - if not warn the user and uncheck usegedate
if (xRow.Calculated_MinDate == null)
{
PublishInfoMessage("There is no date for order " + MyOrder + " on line " + MyLine + " release " + MyRel + ". Check your selection.", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual,"","");
xRow.Calculated_UseGEDate = false;
}
else
{
MyOrder = xRow.OrderRel_OrderNum;
MyLine = xRow.OrderRel_OrderLine;
MyRel = xRow.Calculated_MinRel;
MyDate = xRow.Calculated_MinDate;
Erp.Tables.OrderRel OrderRel;
using (var txscope1 = IceDataContext.CreateDefaultTransactionScope())
{
foreach (var rel in (from rRow in Db.OrderRel where rRow.OrderNum == MyOrder && rRow.OrderLine == MyLine && rRow.OrderRelNum == MyRel select rRow))
{
if (rel != null)
{
string DateNew = String.Format("{0:M/d/yyyy}", MyDate);
string DateOld = String.Format("{0:M/d/yyyy}", rel.ReqDate);
rel.Character01 = BpmFunc.Now() + "--- System updated release " + MyRel + " in order " + MyOrder + " on line " + MyLine + "." + " Old Date: " + DateOld + " New Date: " + DateNew;
rel.ReqDate = MyDate;
rel.NeedByDate = MyDate;
Db.Validate(rel);
UpdateCount = UpdateCount + 1;
}
txscope1.Complete();
}
}
xRow.Calculated_UseDate = false;
}
}
// all that is left are the manual edits
// For each manual edit, just apply the updated values
if (xRow.Calculated_Manual == true)
{
using (Erp.Contracts.SalesOrderSvcContract soSvc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.SalesOrderSvcContract>(Db))
{
SalesOrderTableset SOTS = soSvc.GetByID(MyOrder);
var desiredReleases = SOTS.OrderRel.Where(r => r.OrderLine == MyLine && r.OrderRelNum == MyRel);
MyDate = xRow.OrderRel_ReqDate;
foreach(var rel in desiredReleases)
{
string DateNew = String.Format("{0:M/d/yyyy}", MyDate);
string DateOld = String.Format("{0:M/d/yyyy}", rel.ReqDate);
rel["Character01"] = BpmFunc.Now() + "--- System manually updated release " + MyRel + " in order " + MyOrder + " on line " + MyLine + " Old Date: " + DateOld + " New Date: " + DateNew + " Old Qty: " + Convert.ToInt32(rel.OurReqQty) + " New Qty: " + xRow.OrderRel_OurReqQty;
rel.ReqDate = MyDate;
rel.NeedByDate = MyDate;
rel.OurReqQty = xRow.OrderRel_OurReqQty;
rel.Make = true;
rel.RowMod = "U";
ManualUp=ManualUp+1;
}
soSvc.Update(ref SOTS);
}
}
}
CloseCount = CloseCount / 2;
