I have created a method directive bpm that copies a field value in a quote line to the corresponding order line. The bpm is initiated in the quote.createorder method…
After the variables are stored in the call context bpm data I call a proxy bpm to update the order… callContextBpmData.char01 is a comma delimited string of QuoteLine:Value…
Here is the code in the GetNewUD39 method…
int OrderNum=(int)callContextBpmData.Number02;
string[] bpmline = callContextBpmData.Character01.Split(',');
var Sales = ServiceRenderer.GetService<Erp.Contracts.SalesOrderSvcContract>(Db);
var OrderDataSet = Sales.GetByID(OrderNum);
foreach (string oline in bpmline)
{
if (oline.Length > 1) {
string[] qline=oline.Split(':');
int OLineNum=int.Parse(qline[0]);
this.PublishInfoMessage("!"+qline[0]+"!", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
var Order_xRow = (from OrderTable_Row in OrderDataSet.OrderDtl
where OrderTable_Row.OrderNum==OrderNum && OrderTable_Row.OrderLine==OLineNum
select OrderTable_Row).FirstOrDefault();
this.PublishInfoMessage("Processing " + Order_xRow, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
if (Order_xRow != null)
{
Order_xRow.CounterSaleLotNum = qline[1];
Order_xRow.RowMod = "U";
Sales.Update(ref OrderDataSet);
}
}
}
Working on a quote with 2 lines.
The debug messages show the callContextBpmData.char01 contains both lines(formatted correctly) and there corresponding values. The second debug message shows the query does not find the line 2 in the OrderDtl object.
After the order is created, both lines are there but only the 1st line has the updated value.
Hope I have given enough detail but not too much to confuse.
I am not sure, but I think that you need to add .ToString() to the Order_xRow in your messagebox. You may also need to reference a fieldname, something like Order_xRow.OrderNum.ToString(). I am not sure if you can use ToString, you may need to use the convert function instead.
Good luck!
int OrderNum=(int)callContextBpmData.Number02;
string[] bpmline = callContextBpmData.Character01.Split(',');
var Sales = ServiceRenderer.GetService<Erp.Contracts.SalesOrderSvcContract>(Db);
var OrderDataSet = Sales.GetByID(OrderNum);
foreach (string oline in bpmline)
{
if (oline.Length > 1) {
string[] qline=oline.Split(':');
int OLineNum=int.Parse(qline[0]);
var Order_xRows = (from OrderTable_Row in OrderDataSet.OrderDtl
where OrderTable_Row.OrderNum==OrderNum && OrderTable_Row.OrderLine==OLineNum
select OrderTable_Row).ToList();
InfoMessage.Publish($"Row count is: {Order_xRows.Count().ToString()}.");
}
}
The `InfoMessage.Publish($“Row count is: {Order_xRows.Count().ToString()}.”); appeared twice(as expected). Both times the message read Row count is:1```
I would also spit out the values for your line numbers and order numbers to make sure you have the right values as expected. Maybe the OLineNum is not incrementing as you expect?
Some more debugging… Selected all order detail from the order, looped through them and displayed the orderline number…
var Order_tRow = (from OrderTable_tRow in OrderDataSet.OrderDtl
where OrderTable_tRow.OrderNum==OrderNum
select OrderTable_tRow);
foreach (var otr in Order_tRow)
{
this.PublishInfoMessage("From OrderDtl " + otr.OrderLine, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, “”, “”);
}
Both Lines were displayed as orderline 1 & 2
Second:
Changed FirstOrDefault on initial query of OrderDtl… to Single
Threw
Description: BPM runtime caught an unexpected exception of ‘InvalidOperationException’ type.
See more info in the Inner Exception section of Exception Details.
Program: System.Linq.dll
Method: ThrowNoElementsException
I also hard coded OrderLine=2 in the query and it return the row…
Could I not be initializing/reusing variable Order_xRow correctly?
var Order_xRow = (from OrderTable_Row in OrderDataSet.OrderDtl
where OrderTable_Row.OrderNum==OrderNum && OrderTable_Row.OrderLine==OLineNum
select OrderTable_Row).FirstOrDefault();
Solution was to take the Sales.Update(ref OrderDataSet); out of the loop. Suspect the Update made the query no longer valid, so second record was no longer there. Thanks to all for the help.