Skip to Content
avatar image
Former Member

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

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?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    Jan 23 at 01:16 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded