我正在尝试创建 A/P 贷项凭证作为 A/P 发票的副本。我是手动进行的,但复制值,而不是将贷项凭单指向基础文档。
相关位都在这个方法中:
private int CreateTarget(IDocuments sourceDoc, IDocuments targetDoc, int docEntry)
{
targetDoc.DocDueDate = DateTime.Today;
targetDoc.DocDate = DateTime.Today;
targetDoc.DocType = sourceDoc.DocType;
targetDoc.CardCode = sourceDoc.CardCode;
targetDoc.ContactPersonCode = sourceDoc.ContactPersonCode;
targetDoc.NumAtCard = sourceDoc.NumAtCard;
targetDoc.SalesPersonCode = sourceDoc.SalesPersonCode;
targetDoc.Comments = sourceDoc.Comments;
targetDoc.ShipToCode = sourceDoc.ShipToCode;
targetDoc.PayToCode = sourceDoc.PayToCode;
targetDoc.Address = sourceDoc.Address;
targetDoc.Address2 = sourceDoc.Address2;
using (var sLines = sourceDoc.Lines.WithComCleanup())
{
using (var tLines = targetDoc.Lines.WithComCleanup())
{
var sourceLines = sLines.Resource;
var targetLines = tLines.Resource;
for (var idx = 0; idx < sourceLines.Count; idx++)
{
if (idx != 0)
{
targetLines.Add();
}
targetLines.ItemCode = sourceLines.ItemCode;
targetLines.Quantity = sourceLines.Quantity;
targetLines.UnitPrice = sourceLines.UnitPrice;
targetLines.DiscountPercent = sourceLines.DiscountPercent;
}
}
}
using (var docRefCom = targetDoc.DocumentReferences.WithComCleanup())
{
var docRef = docRefCom.Resource;
docRef.Add();
docRef.ReferencedObjectType = GetReferencedObjectType(false);
docRef.ReferencedDocEntry = docEntry;
}
if (targetDoc.Add() != 0)
{
var (code, message) = _sboWrapper.GetLastError();
throw new SapB1Exception(code, message);
}
return _sboWrapper.GetNewObjectKey();
}
当我targetDoc.Add()
接到电话时,我从 DI API 收到以下错误:代码:-10 消息:540020003 - 缺少文档类型
我想不通,这意味着什么。我尝试添加各种属性,但运气不佳。
我的源文档是这样声明的: (SAPbobsCOM.Documents)Company.GetBusinessObject(BoObjectTypes.oPurchaseInvoices).GetByKey(docEntry);
我的目标文件是这样的: (SAPbobsCOM.Documents)Company.GetBusinessObject(BoObjectTypes.oPurchaseCreditNotes);