0

我正在尝试创建 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);

4

2 回答 2

0

尝试在行级别设置基本类型:

 targetLines.BaseType = 18;
于 2022-02-15T12:42:33.443 回答
0

原来这才docRef.Add()是罪魁祸首。回想起来这很有意义,但是该Documents_DocumentReferences对象没有Count属性,并且几乎没有文档,所以我觉得它在 DI Api 中是相当新的。

由于它缺乏集合对象的通常特征, like Documents_Lines,我说服自己我需要调用Add()来做任何事情。

无论如何,问题解决了:)

于 2022-02-16T08:42:27.987 回答