CustShip.UpdateMaster is not returning a new system generated pack num in a temp dataset

Hello,

I’m writing a method directive to create Customer Shipments based on selected allocations in fulfillment workbench. If I select more than 1 order number (which indicates a new pack should be created), the 1st iteration of the loop creates the pack just fine, but the 2nd iteration creates an orderhed record with the SAME pack num as the last iteration, thus causing issues. I debugged this directive in Visual Studio and walked through it myself. On the 2nd iteration of a loop where there is a new order number up (a new pack id should be made), UpdateMaster will reuse the same packnum it created the first time. Does anyone have any solutions to this? Will I have to manually manipulate the pack ID (I’d prefer the method to take care of it for me). Here is my code:

//Start Diagnostics
var watch = System.Diagnostics.Stopwatch.StartNew();
watch.Start();
//Filter the Allocation List to only selected, and no allocation errors
var filteredAllocationList = ttOrderAlloc.OrderBy(o => o.OrderNum).Where(w => w.SelectedForAction == true && w.PickError == string.Empty).Select(s => new {s.OrderNum, s.OrderLine, s.OrderRelNum}).ToList();

//Variable to determine if we need to create a new shipment (1 order per shipment)
int previousOrderNum = 0;

//Required method variables
string creditMessage = "";
bool opPromptForNum;
string opReleaseMessage = "";
string opCompleteMessage = "";
string opShippingMessage = "";
string opLotMessage = "";
string opInventoryMessage = "";
string opLockQtyMessage = "";
string opAllocationMessage = "";
string opPartListNeedsAttr = "";
string opLotListNeedsAttr = "";
string shipCreditMsg = "";
bool cError;
bool compError;
string msg = "";
string opPostUpdMessage = "";
bool updateComplete;
bool checkComplianceError;
bool changeStatusError;
bool checkShipDtlAgain;
int billtoCustNumCreditHoldValidation = 0;
int headerPackNumCreated = 0;
string prePartInfo = "";
string prePartvMsgText = "";
bool prePartVSubAvail;
string prePartvMsgType = "";
string prePartOrigPartNum = "";
string prePartPartNum = "";
string checkOrderInfoOutMsg = "";
string getPartInfo = "";
bool getPartInfoB;

//Create an empty Customer Shipment Tableset
Erp.Tablesets.CustShipTableset myCustShipDataSet = new Erp.Tablesets.CustShipTableset();

using (var customerShipSvc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.CustShipSvcContract>(Db)) //Create the Customer Shipment BO Object
{
//********************Begin Shipment Header Creation*************************
foreach (var row in filteredAllocationList)
{
  if (previousOrderNum != row.OrderNum)
  {
    
    myCustShipDataSet.ShipHead.Clear();
    myCustShipDataSet.ShipCOO.Clear();
    myCustShipDataSet.ShipDtl.Clear();
    updateComplete = false;
    customerShipSvc.GetNewShipHead(ref myCustShipDataSet); // Create a new customer shipment header row with defaults
    customerShipSvc.GetHeadOrderInfo(row.OrderNum, out creditMessage, ref myCustShipDataSet); //Obtain order defaults
    //customerShipSvc.GetOrderInfo(row.OrderNum, out creditMessage, ref myCustShipDataSet);
    foreach (var shipHeadRow in myCustShipDataSet.ShipHead) //Grab the BTCustNum for use in MasterUpdate
    {
      billtoCustNumCreditHoldValidation = (int)shipHeadRow["BTCustNum"];
    }
  
    customerShipSvc.GetLegalNumGenOpts(0, ref myCustShipDataSet, out opPromptForNum); //Required call
    customerShipSvc.UpdateMaster(ref myCustShipDataSet,false,false,false,false,false,false,false,0,billtoCustNumCreditHoldValidation,out opReleaseMessage,out opCompleteMessage,out opShippingMessage,out opLotMessage,out opInventoryMessage,out opLockQtyMessage,out opAllocationMessage,out opPartListNeedsAttr,out opLotListNeedsAttr,out shipCreditMsg,out cError,out compError,out msg,out opPostUpdMessage,out updateComplete,out checkComplianceError,out changeStatusError,out checkShipDtlAgain);
    
    foreach (var shipHeadRow in myCustShipDataSet.ShipHead) //Grab the newly created packnum for use in adding the detail lines
    {
      headerPackNumCreated = (int)shipHeadRow["PackNum"];
    }
  }
  
//****************************End Shipment Header Creation***********************************************
//****************************Begin Shipment Detail Creation*********************************************
  
  
    myCustShipDataSet.ShipDtl.Clear();
    customerShipSvc.GetNewOrdrShipDtl(ref myCustShipDataSet, headerPackNumCreated, row.OrderNum);
    var currPackLine = myCustShipDataSet.ShipDtl.Where(w => w.PackLine == 0).FirstOrDefault();
    currPackLine.OrderNum = row.OrderNum;
    
  
    currPackLine.OrderLine = row.OrderLine;
    customerShipSvc.CheckPrePartInfo(ref prePartPartNum, currPackLine.OrderNum, currPackLine.OrderLine, out prePartvMsgText, out prePartVSubAvail, out prePartvMsgType, out prePartOrigPartNum);
    customerShipSvc.GetOrderLineInfo(ref myCustShipDataSet, currPackLine.PackLine, currPackLine.OrderLine, prePartOrigPartNum);
    currPackLine.OrderRelNum = row.OrderRelNum;
    customerShipSvc.GetOrderRelInfo(ref myCustShipDataSet, currPackLine.PackLine, currPackLine.OrderRelNum, true);
    currPackLine.PartNum = prePartOrigPartNum;
    customerShipSvc.GetPartInfo(ref myCustShipDataSet, currPackLine.PackLine, ref prePartOrigPartNum, Guid.Empty, string.Empty, out getPartInfo, out getPartInfo, out getPartInfoB, out getPartInfo); 
   
    customerShipSvc.UpdateMaster(ref myCustShipDataSet, false, false, false, false, false, false, false, headerPackNumCreated, 0, out opReleaseMessage, out opCompleteMessage, out opShippingMessage, out opLotMessage, out opInventoryMessage, out opLockQtyMessage, out opAllocationMessage, out opPartListNeedsAttr, out opLotListNeedsAttr, out shipCreditMsg, out cError, out compError, out msg, out opPostUpdMessage, out updateComplete, out checkComplianceError, out changeStatusError, out checkShipDtlAgain);
      
  
  previousOrderNum = row.OrderNum;
 }
};


watch.Stop();
var elapsed = watch.ElapsedMilliseconds;
this.PublishInfoMessage(elapsed.ToString(),
        Ice.Common.BusinessObjectMessageType.Information,
        Ice.Bpm.InfoMessageDisplayMode.Individual,
        "Developer Message",
        "Information From the Developer");



Was the first Packer actually created (written to the DB) prior the new one being “assembled”?
Have you set the Pack Number to 0 for each new pack you’re about to create?

  • Yes, both pack ids are created in the DB (EVEN the new second pack , but the UpdateMaster is not returning it in my dataset)
  • Yes I am setting the pack ID to 0 on the header updatemaster call

The primary key for ShipHead is Company, Packnum. So is the 2nd packer (for the new Order) just overwritting the 1st one? Or ar you actually seeing two records with the same PackNum?

Im correctly seeing 2 new unique pack ID’s in the DB, but in the code my tableset is still being set with the previous pack id, thus causing adding all the lines to fail.

Iteration 1 —> pack id 1448684 created just fine , both in temporary bpm dataset and DB

Iteration 2 (new order) -----> pack ID 1448685 created in DB after master update, but temp dataset in bpm updatemaster returns 1448684 so I cannot add the lines:

foreach (var shipHeadRow in myCustShipDataSet.ShipHead) //Grab the newly created packnum for use in adding the detail lines
    {
      headerPackNumCreated = (int)shipHeadRow["PackNum"];
    }

I’m no expert at this, but maybe some of my questions will jog something loose…

Is myCustShipDataSet capable of holding multiple shipments, or just one?

What if you destroy that and create a new one on each new order?

Thanks for your assistance!

So on each new iteration I’m clearing out all shipHead, ShipDtl, and ShipCOO tables, hmmm

update master is broke. Switching to just update on order header creation resolved the issue. UGH!

1 Like