Creating New RcvDtl via Custom Code Function

Just wondering if anyone has any insight on this… I’m trying to create a new rcvDtl row in a custom epicor function, I call an api that feeds json data to the function that looks like this:

{
  "jsonData": "{“RcvHead”: [
    {
    “Company”: “PERL01”,
    “Plant”: “P01”,
    “VendorNum”: null,
    “PackSlip”: “33019-2500”,
    “PONum”: 259414,
    “POType”: “SMI”,
    “VendorNumVendorID”: “ENDR001”,
    “PurPoint”: “1”,
    “ReceivePerson”: “DMT”,
    “ReceiptDate”: “2023-08-20T16:06:17.140Z”
      }
    ],
    “RcvDtl”: [
    {
    “ReceiptType”: “P”,
    “POLine”: 11,
    “PORelNum”: 1,
    “PackLine”: 0,
    “PartNum”: “54974-1”,
    “InputOurQty”: 4000,
    “IUM”: “EA”,
    “ReceivedTo”: “PUR-STK”,
    “Received”: true
    }
    ]
  }",
"typeOfDmt": "PO Receipt Combined"
}

I can add a new rcvHead line just fine by itself, but when I try to add a new rcvDtl line that is tied to it, I get an error that states this: Packing Slip referenced is not for this site.
Here is my code:

{
  switch(this.typeOfDmt)
  {
      case "PO Receipt Combined":
        
        var context = Ice.Services.ContextFactory.CreateContext<ErpContext>();
        JObject jobj = JsonConvert.DeserializeObject<JObject>(this.jsonData);
        string vendorId = jobj["RcvHead"][0]["VendorNumVendorID"].ToString();
        //Erp.BO.UpdExtReceiptDataSet dsRecUpdExt = new Erp.BO.UpdExtReceiptDataSet();

        using( var receiptSvc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.ReceiptSvcContract>(context)){ 

          // Search Vendors to find the correct VendorNum
          int vendorNums = (from h in Db.Vendor where h.VendorID == vendorId select h.VendorNum).FirstOrDefault();
          bool errorsOccurred = false;
          
          var rcvHdRow = new Erp.Tablesets.RcvHeadRow(){
              Company = (string)jobj["RcvHead"][0]["Company"],
              Plant = (string)jobj["RcvHead"][0]["Plant"],
              VendorNum = vendorNums,
              PackSlip = (string)jobj["RcvHead"][0]["PackSlip"],
              PONum = (int)jobj["RcvHead"][0]["PONum"],
              POType = (string)jobj["RcvHead"][0]["POType"],
              VendorNumVendorID = (string)jobj["RcvHead"][0]["VendorNumVendorID"],
              PurPoint = (string)jobj["RcvHead"][0]["PurPoint"],
              ReceivePerson = (string)jobj["RcvHead"][0]["ReceivePerson"],
              ReceiptDate = DateTime.Parse(jobj["RcvHead"][0]["ReceiptDate"].ToString())
          };
          var rcvDtlRow = new Erp.Tablesets.RcvDtlRow(){
              Company = (string)jobj["RcvHead"][0]["Company"],
              Plant = (string)jobj["RcvHead"][0]["Plant"],
              VendorNum = vendorNums,
              PackSlip = (string)jobj["RcvHead"][0]["PackSlip"],
              ReceiptType = (string)jobj["RcvDtl"][0]["ReceiptType"],
              PONum = (int)jobj["RcvHead"][0]["PONum"],
              POLine = (int)jobj["RcvDtl"][0]["POLine"],
              PORelNum = (int)jobj["RcvDtl"][0]["PORelNum"],
              PackLine = (int)jobj["RcvDtl"][0]["PackLine"],
              PartNum = (string)jobj["RcvDtl"][0]["PartNum"],
              InputOurQty = (int)jobj["RcvDtl"][0]["InputOurQty"],
              IUM = (string)jobj["RcvDtl"][0]["IUM"],
              ReceivedTo = (string)jobj["RcvDtl"][0]["ReceivedTo"],
              Received = (bool)jobj["RcvDtl"][0]["Received"],
              PurPoint = (string)jobj["RcvHead"][0]["PurPoint"],
              ReceiptDate = DateTime.Parse(jobj["RcvHead"][0]["ReceiptDate"].ToString())
          };

          //var getRecord = receiptSvc.GetByID(vendorNums, jobj["RcvHead"][0]["PurPoint"].ToString(), jobj["RcvHead"][0]["PackSlip"].ToString());
          this.data.RcvHead.Add(rcvHdRow);          
          this.data.RcvHead.RcvHeadToRcvDtlRelation.ChildTable.Add(rcvDtlRow);
          this.errors = receiptSvc.UpdateExt(ref this.data, false, true, out errorsOccurred);
           
        }              
      break;
  }
}

Any help would be greatly appreacited!

I think you need to use the BOs like you would see in a trace. This thread has working code for what you want to do.

1 Like

Thanks for sharing this!.. I was able to again add the rcvHead line to Epicor but when trying to add the rcvDtl line, I got a new error message.

{
  "error": "Ice.BLException: This Purchase Order line has no releases for this site.\r\n   at Erp.Services.BO.ReceiptSvc.GetDtlPOLineInfo(ReceiptTableset& ds, Int32 vendorNum, String purPoint, String packSlip, Int32 packLine, Int32 poLine, String& serialWarning) in C:\\_releases\\ERP\\ERP11.2.200.9\\Source\\Server\\Services\\BO\\Receipt\\Receipt.cs:line 15576\r\n   at Erp.Services.BO.ReceiptSvcFacade.GetDtlPOLineInfo(ReceiptTableset& ds, Int32 vendorNum, String purPoint, String packSlip, Int32 packLine, Int32 poLine, String& serialWarning) in C:\\_releases\\ERP\\ERP11.2.200.9\\Source\\Server\\Services\\BO\\Receipt\\ReceiptSvcFacade.cs:line 3853\r\n   at EFx.PerElbDMTAutomation.Implementation.PerEfnConvertToTablesetImpl.Run()"
}

I double checked to make sure there was a release for that order line and verified that there is, so was wondering if you had any insight on this or if anyone else did?

Here is my code:

{
  switch(this.typeOfDmt)
  {
      case "PO Receipt Combined":
        try
        {
		  // Instantiate variables required to run services and further code
          var context = Ice.Services.ContextFactory.CreateContext<ErpContext>();
          JObject jobj = JsonConvert.DeserializeObject<JObject>(this.jsonData);
          string vendorId = jobj["RcvHead"][0]["VendorNumVendorID"].ToString();
          ReceiptTableset rcvTS = new ReceiptTableset();
            
          using( var receiptSvc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.ReceiptSvcContract>(context)){
            
            // Search Vendors to find the correct VendorNum
            int vendorNums = (from h in Db.Vendor where h.VendorID == vendorId select h.VendorNum).FirstOrDefault();
            int poNum = (int)jobj["RcvHead"][0]["PONum"];
            bool errorsOccurred = false;
            string purPoint = (string)jobj["RcvHead"][0]["PurPoint"];
            string packSlip = (string)jobj["RcvHead"][0]["PackSlip"];
            string warning = "";
            string warnMsg = "";
            
            receiptSvc.ExistsRcvHead(vendorNums,
                                purPoint,
                                packSlip,
                                poNum,
                                out warning);
         
            if( !warning.Equals(string.Format("The Packing Slip {0} already exists. Do you want to continue?",packSlip)) )
            {
              //GetNewRcvHead Method
              vendorNums = 0;
              purPoint = "";
              
              receiptSvc.GetNewRcvHead(ref rcvTS,
                                  vendorNums,
                                  purPoint);
                                  
              //GetPOInfo Method
              bool fromReceiptEntryNewRcpt = true;
              
              receiptSvc.GetPOInfo(ref rcvTS,
                              poNum,
                              fromReceiptEntryNewRcpt,
                              out vendorNums,
                              out purPoint,
                              out warning,
                              out warnMsg);
         
              //GetWarningPOClosed Method
              string cWarning = "";
              
              receiptSvc.GetWarningPOClosed(poNum,
                                       out cWarning);
              
              if( cWarning != "" )
                ;//Do Code
              
              //Update Method                                  
              rcvTS.RcvHead[0].Company = (string)jobj["RcvHead"][0]["Company"];
              rcvTS.RcvHead[0].Plant = (string)jobj["RcvHead"][0]["Plant"];
              rcvTS.RcvHead[0].VendorNum = vendorNums;
              rcvTS.RcvHead[0].PackSlip = packSlip;
              rcvTS.RcvHead[0].PONum = (int)jobj["RcvHead"][0]["PONum"];
              rcvTS.RcvHead[0].POType = (string)jobj["RcvHead"][0]["POType"];
              rcvTS.RcvHead[0].VendorNumVendorID = (string)jobj["RcvHead"][0]["VendorNumVendorID"];
              rcvTS.RcvHead[0].PurPoint = purPoint;
              rcvTS.RcvHead[0].ReceivePerson = (string)jobj["RcvHead"][0]["ReceivePerson"];
              rcvTS.RcvHead[0].ReceiptDate = DateTime.Parse(jobj["RcvHead"][0]["ReceiptDate"].ToString());
              rcvTS.RcvHead[0].RowMod = "A";
              receiptSvc.Update(ref rcvTS);
            }
            //GetNewRcvDtl Method
            receiptSvc.GetNewRcvDtl(ref rcvTS,
                               vendorNums,
                               purPoint,
                               packSlip);
           
            //GetDtlPOLineInfo Method
            int packLine = 0;
            int poLine = (int)jobj["RcvDtl"][0]["POLine"];
            string serialWarning = "";
            
            receiptSvc.GetDtlPOLineInfo(ref rcvTS,
                                   vendorNums,
                                   purPoint,
                                   packSlip,
                                   packLine,
                                   poLine,
                                   out serialWarning);
             
            //GetDtlQtyInfo Method
            decimal inputOurQty = (int)jobj["RcvDtl"][0]["InputOurQty"];
            string inputIUM = (string)jobj["RcvDtl"][0]["IUM"];
            string whichField = "QTY";
            
            receiptSvc.GetDtlQtyInfo(ref rcvTS,
                                vendorNums,
                                purPoint,
                                packSlip,
                                packLine,
                                inputOurQty,
                                inputIUM,
                                whichField,
                                out warnMsg);
              
            if( warnMsg != "" )
              ;//Do Code
            
            //CheckDtlBeforeUpdate Method
            string qMessageStr = "";
            string sMessageStr = "";
            string lcMessageStr = "";
            string pcMessageStr = "";
            
            receiptSvc.CheckDtlBeforeUpdate(rcvTS,
                                       vendorNums,
                                       purPoint,
                                       packLine,
                                       packSlip,
                                       out qMessageStr,
                                       out sMessageStr,
                                       out lcMessageStr,
                                       out pcMessageStr);
      
            //PreUpdate Method
            bool RequiresUserInput = false;
            
            receiptSvc.PreUpdate(ref rcvTS,
                            out RequiresUserInput);
         
            //Update Method
            rcvTS.RcvDtl[rcvTS.RcvDtl.Count - 1].Company = (string)jobj["RcvHead"][0]["Company"];
            rcvTS.RcvDtl[rcvTS.RcvDtl.Count - 1].Plant = (string)jobj["RcvHead"][0]["Plant"];
            rcvTS.RcvDtl[rcvTS.RcvDtl.Count - 1].VendorNum = vendorNums;
            rcvTS.RcvDtl[rcvTS.RcvDtl.Count - 1].PackSlip = packSlip;
            rcvTS.RcvDtl[rcvTS.RcvDtl.Count - 1].ReceiptType = (string)jobj["RcvDtl"][0]["ReceiptType"];
            rcvTS.RcvDtl[rcvTS.RcvDtl.Count - 1].PONum = (int)jobj["RcvHead"][0]["PONum"];
            rcvTS.RcvDtl[rcvTS.RcvDtl.Count - 1].POLine = poLine;
            rcvTS.RcvDtl[rcvTS.RcvDtl.Count - 1].PORelNum = (int)jobj["RcvDtl"][0]["PORelNum"];
            rcvTS.RcvDtl[rcvTS.RcvDtl.Count - 1].PackLine = packLine;
            rcvTS.RcvDtl[rcvTS.RcvDtl.Count - 1].PartNum = (string)jobj["RcvDtl"][0]["PartNum"];
            rcvTS.RcvDtl[rcvTS.RcvDtl.Count - 1].POType = (string)jobj["RcvHead"][0]["POType"];
            rcvTS.RcvDtl[rcvTS.RcvDtl.Count - 1].InputOurQty = inputOurQty;
            rcvTS.RcvDtl[rcvTS.RcvDtl.Count - 1].IUM = inputIUM;
            rcvTS.RcvDtl[rcvTS.RcvDtl.Count - 1].ReceivedTo = (string)jobj["RcvDtl"][0]["ReceivedTo"];
            rcvTS.RcvDtl[rcvTS.RcvDtl.Count - 1].Received = (bool)jobj["RcvDtl"][0]["Received"];
            rcvTS.RcvDtl[rcvTS.RcvDtl.Count - 1].PurPoint = purPoint;
            rcvTS.RcvDtl[rcvTS.RcvDtl.Count - 1].ReceiptDate = DateTime.Parse(jobj["RcvHead"][0]["ReceiptDate"].ToString());
            rcvTS.RcvDtl[rcvTS.RcvDtl.Count - 1].RowMod = "A";
            receiptSvc.Update(ref rcvTS);
          }
        }
        catch(Exception e){this.error = e.ToString();}
    
      break;
  }
}