I pretty much followed the code here. However, what I am trying to do is to create multiple lines.
I managed to create the first Shipment detail line, but when it comes to the 2nd loop, the call to GetNewShipDtl will throw an error. Anyone seen this before?
System.NullReferenceException: Object reference not set to an instance of an object.
at Erp.Services.BO.CustShipSvc.ShipDtlAfterGetNew() in C:_Releases\ERP\UD10.2.200.4\Source\Server\Services\BO\CustShip\CustShip.cs:line 30241
indent preformatted text by 4 spaces // Set the pack num
var pn = 167; // newShipment.PackNum;
int lineNo = 1;
foreach(var load in loadsToAdd)
{
try
{
csts = hCustShip.GetByID(pn);
this.PublishInfoMessage("Load", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "FirstVar","SecondVar");
hCustShip.GetNewShipDtl(ref csts, pn);
hCustShip.GetOrderInfo(load.OrderNum, out creditMsg, ref csts);
hCustShip.GetOrderLineInfo(ref csts, lineNo, load.OrderLine,"");
hCustShip.GetOrderRelInfo(ref csts, lineNo, 1, false);
hCustShip.GetQtyInfo(ref csts, lineNo, 0, 1);
lineNo++;
var newShipmentDtl = csts.ShipDtl.Where(p => p.RowMod.Equals("A", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
newShipmentDtl.JobLotNum = load.JobNo_c;
csts.ShipHead[0].RowMod = "U";
hCustShip.Update(ref csts);
}
catch (Exception ex)
{
this.PublishInfoMessage(ex.ToString(), Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "FirstVar","SecondVar");
}
}
I came across this same issue and have been messing with it for almost a week. It seems there is a lot going on in the background that makes it very unpredictable to work with. I was able to get it to work for now, but I have to test extensively because I don’t exactly trust it just yet since I’ve had to decipher which data was missing and it has taken a lot time to figure out.
So to point to Jose’s comment, you do need to change the RowMod of the header to U because the BO through standard procedure of using this BO updates the header and line at the same time, which is different than other BO’s. You can see this in the trace. I had to set the RowMod after the GetOrderRelInfo method call just before the update.
I was able to get the line to add after already adding a line by setting the RowMod of the first line to U. But, before you call update, I had to clear that RowMod property and it saved. Not sure why you have to toggle the RowMod of the saved line before you can add and save another.
UpdateMaster did not work very well, especially when trying to add Misc Charges. I was getting errors that it could not find the pack, or the line within the dataset even though I could clearly see it in the debugger. I only used UpdateMaster when creating the header at the beginning. Update is more reliable.
If anyone else has worked with this and come across similar issues, I would love to hear how you dealt with it.