cancel
Showing results for 
Search instead for 
Did you mean: 

Di Api Linking Goods receipt to Purchase Orders error -2028 - No matching records found (ODBC -2028)

Former Member
0 Kudos

Hello,

I'm working on an application to make goods receipt simpler for our company using SAP business one 9.2

I already got it working so far that I can add a new goods receipt via DI API. The following C# code does this for me:

Company company = _sapService.GetCompany();

var oPurchaseDeliveryNotes = (Documents) company.GetBusinessObject(BoObjectTypes.oPurchaseDeliveryNotes);

// required fields
oPurchaseDeliveryNotes.CardCode = GetCardCode(
                models.First()
                    .DocNum);
oPurchaseDeliveryNotes.PaymentGroupCode = -1;

// order lines
var i = 0;
foreach (OrderLineViewModel model in models.Where(model => model.RecQuantity != 0))
 {
      if (IsScanSerialNumber(model.ItemCode))
      {
          // Serial Numbers
          var j = 0;
          foreach (string serialNumber in model.SerialNumbers)
          {
              oPurchaseDeliveryNotes.Lines.SerialNumbers.ManufacturerSerialNumber = serialNumber;
              oPurchaseDeliveryNotes.Lines.SerialNumbers.InternalSerialNumber = serialNumber;
              oPurchaseDeliveryNotes.Lines.SerialNumbers.SetCurrentLine(j);

              // Go to next line and add
              oPurchaseDeliveryNotes.Lines.SerialNumbers.Add();
              j++;
         }
  }
 
   // Other line information
   oPurchaseDeliveryNotes.Lines.ItemCode = model.ItemCode;              
   oPurchaseDeliveryNotes.Lines.ItemDescription = model.Dscription;
   oPurchaseDeliveryNotes.Lines.Quantity = (double) model.RecQuantity;
   oPurchaseDeliveryNotes.Lines.ShipDate = DateTime.Now;
   oPurchaseDeliveryNotes.Lines.VendorNum = model.VendorNum;

   // Go to next line and add
   oPurchaseDeliveryNotes.Lines.SetCurrentLine(i);
   oPurchaseDeliveryNotes.Lines.Add();
   i++;
}

int result = oPurchaseDeliveryNotes.Add();
if (result == 0)
{
     // success
     return;
}

int errorCode;
string errorDesc;
company.GetLastError(out errorCode, out errorDesc);
throw new Exception($"{errorCode} - {errorDesc}");

The above code works, but does not link the Goods Receipt to the Purchase Order.

I read in other topics that I have to set BaseEntry, BaseType and BaseLine to make the link work like this:

// Link to PO info
oPurchaseDeliveryNotes.Lines.BaseEntry = GetPurchaseOrderEntry(model.DocNum);
oPurchaseDeliveryNotes.Lines.BaseType = 22;
oPurchaseDeliveryNotes.Lines.BaseLine = GetPruchchaseOrderLineCode(model.DocNum, model.ItemCode);

However now I get the following error: '-2028 - No matching records found (ODBC -2028)'

Can anyone help me figure out what I'm doing wrong?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I already found the answer.

I set the values for fields that DI Api fills automatically. (Line.ItemCode, Line.VendorNum, Line.ItemDescription, Line.ShipDate and PaymentGroupCode).

Now I only set the quantity, and now it works.

I hope this helps others that have the same problem.

Answers (0)