on 01-19-2018 4:47 PM - last edited on 02-04-2024 2:51 AM by postmig_api_4
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?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
96 | |
10 | |
9 | |
6 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.