Build/Split/Merge in a Function -- No error, just doesn't add stock to PCID

Hey all,

In a function, I’m trying to move stock in a lot to a PCID container. It looks like it should work and gets no errors. The data I’m building in the source looks like what I see in a trace log.

But I get no stock moved to a PCID.

Code below. Note I’m setting a checkbox true on the UD detail row after the AddPartToPCID method at the bottom. It sets there, so I know it hit the method. It just doesn’t make the transfer.

I saw a reference to running the method inside/outside of a transaction scope. Taking out the transaction scope code doesn’t seem to make any difference.

Any ideas?

Thanks,

Joe

Code:

// process job receipt to inventory

var context = (Erp.ErpContext)Ice.Services.ContextFactory.CreateContext();
var erpContext = new Erp.Internal.Lib.CCredChk(context); // used this library/assembly only for erpContext

string jobHeatLotNum = String.Empty;

using(var txscope = IceDataContext.CreateDefaultTransactionScope())        //Start Transaction
{
  var ud102_xRow = (from row in erpContext.Db.UD102 
    where row.Company == Session.CompanyID &&
    row.Key1 == jobNum &&
    row.Key2 == jobSeq
  select row).FirstOrDefault();
  
  if (ud102_xRow != null)
  {
    jobHeatLotNum = ud102_xRow.HeatLotNum_c;
  }
  
  bool updated = false;
  
  // transfer on-hand coil qty for each part/lot/whse/bin
  foreach(var ud102A_xRow in (from row in erpContext.Db.UD102A
    where row.Company == Session.CompanyID &&
    row.Key1 == jobNum &&
    row.Key2 == jobSeq &&
    row.Completed_c == true &&
    row.Received_c == true &&
    row.PCID_c != String.Empty &&
    row.PCIDReceived_c != true
    orderby row.Key1 ascending
    orderby row.Key2 ascending
    orderby row.ChildKey1 ascending
  select row))
  {    
    decimal weight = ud102A_xRow.Weight_c;
    
    Erp.Contracts.PkgControlIDBuildSplitMergeSvcContract buildSplitMerge = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.PkgControlIDBuildSplitMergeSvcContract>(erpContext.Db, true);
    
    var dsBuildSplitMerge = new Erp.Tablesets.PCIDBuildSplitMergeSourcePartTableset();
    
    buildSplitMerge.GetNewPCIDPart(ref dsBuildSplitMerge);
    
    var dsBuildSplitMergeDest = new Erp.Tablesets.PCIDBuildSplitMergeDestTableset();

    // get the destination PCID dataset 
    buildSplitMerge.GetDestPCID(ud102A_xRow.PCID_c, true, ref dsBuildSplitMergeDest );
    
    // read destination record if the PCID is empty
    foreach(var ttBuildSplitMergeDest_xRow in (from row in dsBuildSplitMergeDest.PCIDBuildSplitMergeDest
      where row.Company == Session.CompanyID &&
      row.PkgControlStatus.ToUpper() == "EMPTY"
    select row))
    {
      // set the values in the source side dataset
      foreach(var ttBuildSplitMerge_xRow in (from row in dsBuildSplitMerge.PCIDBuildSplitMergeSourcePart
        where row.Company == Session.CompanyID && 
        string.Equals(row.RowMod, IceRow.ROWSTATE_ADDED, StringComparison.OrdinalIgnoreCase)
      select row))
      {
        ttBuildSplitMerge_xRow.PartNum = ud102A_xRow.PartNum_c;
        ttBuildSplitMerge_xRow.WarehouseCode = ud102A_xRow.CoilWarehouseCode_c;
        ttBuildSplitMerge_xRow.BinNum = ud102A_xRow.CoilBinNum_c;
        ttBuildSplitMerge_xRow.LotNum = ud102_xRow.HeatLotNum_c;
        ttBuildSplitMerge_xRow.SourceQuantity = weight;
        
        buildSplitMerge.OnChangeSourcePartNum(ud102A_xRow.PartNum_c, ud102A_xRow.CoilWarehouseCode_c, ref dsBuildSplitMerge);
        buildSplitMerge.OnChangeSourcePartBinNum(ud102A_xRow.CoilBinNum_c, ref dsBuildSplitMerge);
        buildSplitMerge.OnChangeSourcePartLotNum(ud102_xRow.HeatLotNum_c, ref dsBuildSplitMerge);
        
        if (ttBuildSplitMerge_xRow.AvailableQuantity < weight) 
        {
          ttBuildSplitMerge_xRow.SourceQuantity = ttBuildSplitMerge_xRow.AvailableQuantity;
          weight = ttBuildSplitMerge_xRow.AvailableQuantity;
        }
        
        buildSplitMerge.OnChangeSourceQty(weight, ref dsBuildSplitMerge);
        
        updated = true;

        buildSplitMerge.AddPartToPCID(ref dsBuildSplitMerge, ref dsBuildSplitMergeDest); // this doesn't seem to do anything

        ud102A_xRow.PCIDReceived_c = true; // this part is working okay
      }
    }
  }
  
  erpContext.Db.Validate();
  txscope.Complete(); 
}

Let me see if I can find my code. I do this somewhere here, I just don’t remember where :rofl:

Cool. Thanks!

image

Ok this code is 2 years old before I knew what I was doing at all, but it works.
It is part of a larger program, but you can pick through it.

  //Add Lot from PCID
  Action<string, string, string, string, string, string, decimal, string, Erp.Contracts.PkgControlIDBuildSplitMergeSvcContract, Erp.Contracts.PkgControlIDSvcContract> AddToPCID = (pcid, partNum, partDesc, partClass, jobNum, lotNum, qty, uom, pcidBSM, pcidItem) =>
  {
    bool retVal = false;
    
    Erp.Tablesets.PCIDBuildSplitMergeDestTableset destTS = new Erp.Tablesets.PCIDBuildSplitMergeDestTableset();
    Erp.Tablesets.PCIDBuildSplitMergeSourcePartTableset sourceTS = new Erp.Tablesets.PCIDBuildSplitMergeSourcePartTableset();

    pcidBSM.GetDestPCID(pcid, false, ref destTS);
        
    Erp.Tablesets.PCIDBuildSplitMergeSourcePartRow partRow = (Erp.Tablesets.PCIDBuildSplitMergeSourcePartRow)sourceTS.PCIDBuildSplitMergeSourcePart.NewRow();
    
    partRow.Company = Session.CompanyID;
    partRow.Plant = "";
    partRow.PartNum = partNum;
    partRow.PartDescription = partDesc;
    partRow.BinNum = "WARE";
    partRow.BinDescription = "Warehouse";
    partRow.LotNum = lotNum;
    partRow.LotTrackedPart = true;
    partRow.SerialTrackedPart = false;
    partRow.OnHandQuantity = qty;
    partRow.SourceQuantity = qty;
    partRow.AvailableQuantity = qty;
    partRow.WarehouseCode = (partClass == "SCRA" ? "SCRAP" : "FIN");
    partRow.SourceUOM = uom;
    partRow.AvailableUOM = uom;
    partRow.OnHandUOM = uom;
    partRow.AttributeSetID = 0;
    partRow.EnableAttributeSetSearch = false;
    partRow.PartTrackInventoryAttributes = false;
    //partRow.DispNumberOfPieces = 0;//0
    partRow.SysRowID = Guid.NewGuid();
    partRow.RowMod = "A";
    
    

    sourceTS.PCIDBuildSplitMergeSourcePart.Add(partRow);
        
    pcidBSM.AddPartToPCID(ref sourceTS, ref destTS);
    


    Erp.Tablesets.PkgControlIDTableset pcidTS = new Erp.Tablesets.PkgControlIDTableset(); 
    
    pcidTS = pcidItem.GetByID(pcid);
    pcidTS.PkgControlItem.FirstOrDefault().SupplyJobNum = jobNum;
    pcidTS.PkgControlItem.FirstOrDefault().RowMod = "U";
    
    pcidItem.Update(ref pcidTS);    
    

  };

Thanks Kevin! I’ll give it a try.

Joe

I finally made this work to some degree outside of a transaction scope, but finally went with a looping scheme and widgets to do the split/build/merge.

That seems to work okay.

Thanks for your help.

Joe

1 Like

9 posts were split to a new topic: PCID Build / Split / Merge From Stock - Help