Serial Matching Automation via uBAQ BPM

Hello,

I was going to respond to the below thread, but I got the warning that Necroposting is discouraged, hence the new post: Serial Matching - ERP 10 - Epicor User Help Forum (epiusers.help)

I have the following code. While it is incomplete, I am following the trace I performed, and sadly running OnChangeMtlSerialNo() I get “Serial Match Material record not found.”

I appreciate your time! Once I get this figured out I am going to share the code with the community so no one else is stuck on this process. I already posted my code that performs the steps for serial number assignment.

Here is my code thus far:

// Loop through our serials and perform matching
foreach (var serialNum in selectedSerialNumbersTS.SelectedSerialNumbers)
{
	var serialNumber = serialNum.SerialNumber;
	var partNum = serialNum.PartNum;
	string opRevMsg;
	string opnoBOMMsg;
	var serialNumberMatchingTS = serialMatchingSvc.ChangeSerialNum(serialNumber, partNum, String.Empty, jobNum, assemblySeq, out opRevMsg, out opnoBOMMsg);
	string opQuestion;
	serialMatchingSvc.ValidateAssembly(jobNum, assemblySeq, out opQuestion, ref serialNumberMatchingTS);
	serialMatchingSvc.OnChangeMtlSerialNo("J", serialNumber, mtlSeq, ref serialNumberMatchingTS);
	debugMsg("Serial Matching TS", serialNumberMatchingTS);
}

Here is what my Serial Number Matching tableset looks like befor ethe OnChangeMtlSerialNo call:

{
   "SerialMatchHdr":[
      {
         "ColumnNames":0,
         "Company":"401",
         "JobNum":"000012",
         "TopPartNum":"N00983203-1",
         "RevisionNum":"3",
         "PartDescription":"Precision Part, Machined, 83mm",
         "TopSerialNum":"203-180066",
         "SNStatus":"WIP",
         "Quantity":15.00000000,
         "CreateDate":"2022-11-22T00:00:00",
         "EnableNewChildPart":false,
         "AssemblySeq":0,
         "FullyMatched":false,
         "SourceIsJob":true,
         "SysRowID":"eb9a20aa-747a-4789-8a0d-0e3ddad13830",
         "RowMod":"",
         "SpecifiedProperties":"/z8=",
         "UserDefinedColumns":{
            
         }
      }
   ],
   "SerialMatchAsmbl":[
      {
         "ColumnNames":0,
         "Company":"401",
         "AsmblSeqNum":267,
         "BOMAssemblySeq":0,
         "IsSerialTracked":true,
         "TopPartNum":"N00983203-1",
         "TopSerialNum":"203-180066",
         "ReqByAsmblSeqNum":0,
         "ParentPartNum":"",
         "ParentSerialNo":"",
         "ParentAssemblySeq":0,
         "ParentPartDesc":"",
         "ParentAsmblSeqNum":0,
         "AsmblPartNum":"N00983203-1",
         "AsmblSerialNo":"203-180066",
         "AsmblPartDesc":"Precision Part, Machined, 83mm",
         "QtyPer":1.0,
         "PullQty":0.0,
         "OverRunQty":0.0,
         "RequiredQty":15.00000000,
         "AddedByMatching":false,
         "FullyMatched":false,
         "ReqByAssemblySeq":0,
         "RecNum":1,
         "BOMSeq":0,
         "BOMLevel":0,
         "ParRowIDent":"00000000-0000-0000-0000-000000000000",
         "FromReassignSNAsm":false,
         "SysRowID":"e95d52b0-341b-4139-944f-bac998e627da",
         "RowMod":"U",
         "SpecifiedProperties":"P/B/Hw==",
         "UserDefinedColumns":{
            
         }
      }
   ],
   "SerialMatchMtl":[
      {
         "ColumnNames":0,
         "Company":"401",
         "SeqNum":268,
         "TopPartNum":"N00983203-1",
         "TopSerialNum":"203-180066",
         "ParentPartNum":"N00983203-1",
         "ParentSerialNo":"203-180066",
         "ParentAssemblySeq":0,
         "ParentPartDesc":"Precision Part, Machined, 83mm",
         "ReqByAsmblSeqNum":267,
         "ParentAsmblSeqNum":267,
         "MtlPartNum":"N00910101-1",
         "MtlSerialNo":"",
         "MtlPartDesc":"Preform,Precision Part 83mm",
         "BOMMtlSeq":10,
         "BOMAssemblySeq":0,
         "QtyPer":1.0,
         "AddedByMatching":false,
         "ParRowIDent":"e95d52b0-341b-4139-944f-bac998e627da",
         "BOMMtlSeqNum":1,
         "FromReassignSNAsm":false,
         "SysRowID":"9a50ceca-24d0-4ea8-a5e9-ab837fcc66b5",
         "RowMod":"U",
         "SpecifiedProperties":"//8/",
         "UserDefinedColumns":{
            
         }
      }
   ],
   "AvailToMatch":[
      
   ],
   "ExtensionTables":[
      
   ]
}

I got it figured out! Here’s how to do it in case anyone else is looking to do it.

First, big shout out to this thread:

This helped me see where I was going wrong, so big thanks to @knash !!

If you follow the code there, it’ll get you the matching. To code matching, you basically need these Serial Matching service calls:

  1. ChangeSerialNum
  2. GetAvailableToMatch
  3. UpdateSMMtl

Here is my code, my situation was different because within my uBAQ I am also performing serial assignments. So I already had a list of serials to loop through from that set. Also note the use of Erp.Tablesets:

  // Get the prefix for our part number
  var sPrefix = Db.PartPlant.Where(m => m.Company == currCompany && m.Plant == currPlant && m.PartNum == upperLevel.PartNum).Select(m => m.SNPrefix).FirstOrDefault();
  
  // Loop through our serials and perform matching
  foreach (var serialNum in selectedSerialNumbersTS.SelectedSerialNumbers)
  {
    var serialNumber = serialNum.SerialNumber;
    var partNum = serialNum.PartNum;
    string opRevMsg;
    string opnoBOMMsg;
    var serialMatchingTS = serialMatchingSvc.ChangeSerialNum(serialNumber, partNum, String.Empty, jobNum, assemblySeq, out opRevMsg, out opnoBOMMsg);
    if (serialMatchingTS != null)
    {
      serialMatchingTS.SerialMatchHdr[0].RowMod = "U";
      serialMatchingTS.SerialMatchAsmbl[0].RowMod = "U";
      serialMatchingSvc.GetAvailableToMatch("mtl", ref serialMatchingTS);
      
      Erp.Tablesets.AvailToMatchTable smAvailToMatchTS = serialMatchingTS.AvailToMatch;
      Erp.Tablesets.SerialMatchMtlTable smMtlTS = serialMatchingTS.SerialMatchMtl;
      
      // Get the serial for our lower level part
      var llSerial = serialNumber.Replace(sPrefix, "");
      
      // Loop through each available to match row in our tableset
      foreach (Erp.Tablesets.AvailToMatchRow arow in smAvailToMatchTS)
      {
        if (arow.SerialNumber.EndsWith(llSerial) && arow.PartNum == lowerLevel.PartNum)
        {
          // Set the matched and selected
          arow.Matched = true;  
          arow.Selected = true;
          
          // loop through the match material rows
          foreach (Erp.Tablesets.SerialMatchMtlRow rowMtl in smMtlTS)
          {
            rowMtl.MtlSerialNo = arow.SerialNumber;
            break;
          }
          break;
        }
      }
      
      // Now run the match update
      serialMatchingSvc.UpdateSMMtl("J", ref serialMatchingTS);
      debugMsg("Serial Matching Done", serialMatchingTS);
    }
  }