在 SAP Business One 9 中使用 DI API 附加文件时出错

Ped*_*dez 5 c# attachment sapb1

我正在创建一个应用程序来在 SAP 文档中附加扫描的文档,但我在该过程中遇到了一些问题。我正在使用 SAP BO 9 PL8 并发现了下一个问题:

当我尝试使用 update 方法在现有附件(使用attachments2 对象)中添加新附件行时,DI 尝试检查旧行,并且原始源路径中可能不存在该文件。所以,update方法报错。我使用下面的代码:

Attachments2 oAtt = oCompany.GetBusinessObject(BoObjectTypes.oAttachments2);  
if (oAtt.GetByKey(doc.AttachmentEntry))  
{  
    oAtt.Lines.Add();  
    oAtt.Lines.FileName = oAttNew.Lines.FileName;  
    oAtt.Lines.FileExtension = oAttNew.Lines.FileExtension;  
    oAtt.Lines.SourcePath = oAttNew.Lines.SourcePath;  
    oAtt.Lines.Override = BoYesNoEnum.tYES;  
    if (oAtt.Update() != 0)  
        throw new Exception(oCompany.GetLastErrorDescription());  
}  
Run Code Online (Sandbox Code Playgroud)

SAP 中有一些文档具有附件选项卡,但无法通过 DI 访问此功能。例如,物料主数据 (oItems) 或库存转移 (oStockTransfer)。他们有一个像 Documents 对象一样的 AttachmentEntry 字段,但是这些对象没有添加附件的属性,所以我必须为此文档创建一个活动。

Documents doc = oCompany.GetBusinessObject(oType);  
doc.GetByKey(int.Parse(docEntry));  
doc.AttachmentEntry = oAtt.AbsoluteEntry;  
StockTransfer oStock = .oCompany.GetBusinessObject(BoObjectTypes.oStockTransfer);  
// oStock.AttachmentEntry = oAtt.AbsoluteEntry FAIL  
Run Code Online (Sandbox Code Playgroud)

当我修改 LandedCost 对象中的 AttachmentEntry 属性时,当我尝试更新它时该对象失败。如果对象已有附件(手动添加),则在新行作品中添加新附件。第一种情况的错误是:没有找到匹配的记录(ODBC -2028)。当我强制使用 catch 块时,我会得到其他信息:“1320000126 - 不正确的更新头字段”。我使用下面的代码:

LandedCostsService service = oCompany.GetCompanyService().GetBusinessService(ServiceTypes.LandedCostsService);  
LandedCostParams oParam = service.GetDataInterface(LandedCostsServiceDataInterfaces.lcsLandedCostParams);  
LandedCost oLandedCost = service.GetDataInterface(LandedCostsServiceDataInterfaces.lcsLandedCost);  
oParam.LandedCostNumber = int.Parse(docEntry);  
oLandedCost = service.GetLandedCost(oParam);  
if (oAtt.GetByKey(oLandedCost.AttachmentEntry)) {  
   // Code similar to first code block I posted  
}  
else  
{  
    if (oAttNew.Add() != 0)  
        throw new Exception(oCompany.GetLastErrorDescription());  
    oAtt.GetByKey(int.Parse(oCompany.GetNewObjectKey()));  
    oLandedCost.AttachmentEntry = oAtt.AbsoluteEntry;  
    try  
    {  
        service.UpdateLandedCost(oLandedCost);  
    }  
    catch (Exception ex)  
    {  
        throw new Exception(ex.Message + oCompany.GetLastErrorDescription());  
    }  
}  
Run Code Online (Sandbox Code Playgroud)

我需要知道我做错了什么,或者我是否需要联系 SAP 以告知这些 DI 问题。我希望你能帮助我。提前致谢。

问候,佩德罗

小智 0

我通常这样做并且有效!

\n\n
Private Sub test_NonContinue_LandedCost()\n\n    \'Sample code for the non-continuous inventory system\n    Dim svrLandedCost As SAPbobsCOM.LandedCostsService = oCompany.GetCompanyService().GetBusinessService(SAPbobsCOM.ServiceTypes.LandedCostsService)\n\n    Dim oLandedCost As SAPbobsCOM.LandedCost = svrLandedCost.GetDataInterface(SAPbobsCOM.LandedCostsServiceDataInterfaces.lcsLandedCost)\n\n    Dim oLandedCostEntry As Long = 0\n\n    Dim GRPOEntry As Integer = 15\n\n    \'Landed cost document - item tab line 1\n    Dim oLandedCost_ItemLine As SAPbobsCOM.LandedCost_ItemLine\n    oLandedCost_ItemLine = oLandedCost.LandedCost_ItemLines.Add\n    oLandedCost_ItemLine.BaseDocumentType = SAPbobsCOM.LandedCostBaseDocumentTypeEnum.asGoodsReceiptPO\n    oLandedCost_ItemLine.BaseEntry = GRPOEntry\n    oLandedCost_ItemLine.BaseLine = 0\n\n    \'Landed cost document - item tab line 2\n    oLandedCost_ItemLine = oLandedCost.LandedCost_ItemLines.Add()\n    oLandedCost_ItemLine.BaseDocumentType = SAPbobsCOM.LandedCostBaseDocumentTypeEnum.asGoodsReceiptPO\n    oLandedCost_ItemLine.BaseEntry = GRPOEntry\n    oLandedCost_ItemLine.BaseLine = 1\n\n    \'Landed cost document - item tab line 3\n    \'This is a split line \xe2\x80\x93split from second line (BaseEntry = 13, BaseLine = 1)\n    oLandedCost_ItemLine = oLandedCost.LandedCost_ItemLines.Add()\n    oLandedCost_ItemLine.BaseDocumentType = SAPbobsCOM.LandedCostBaseDocumentTypeEnum.asGoodsReceiptPO\n    oLandedCost_ItemLine.BaseEntry = GRPOEntry\n    oLandedCost_ItemLine.BaseLine = 1\n    oLandedCost_ItemLine.Quantity = 2\n    oLandedCost_ItemLine.Warehouse = "02"\n\n    \'Landed cost document - cost tab line 1\n    Dim oLandedCost_CostLine As SAPbobsCOM.LandedCost_CostLine\n    oLandedCost_CostLine = oLandedCost.LandedCost_CostLines.Add\n    oLandedCost_CostLine.LandedCostCode = "CB"\n    \'Suppose the vendor currency is Foreign Currency, if in local currency should set \'oLandedCost_CostLine.amount\n    oLandedCost_CostLine.amount = 100\n    \'oLandedCost_CostLine.AllocationBy = SAPbobsCOM.LandedCostAllocationByEnum.asCashValueAfterCustoms\n\n    \'Landed cost document - cost tab line 2\n    oLandedCost_CostLine = oLandedCost.LandedCost_CostLines.Add\n    oLandedCost_CostLine.LandedCostCode = "EQ"\n    oLandedCost_CostLine.amount = 100\n    \'oLandedCost_CostLine.AllocationBy = SAPbobsCOM.LandedCostAllocationByEnum.asCashValueAfterCustoms\n\n    \'Landed cost document - cost tab line 3\n    oLandedCost_CostLine = oLandedCost.LandedCost_CostLines.Add\n    oLandedCost_CostLine.LandedCostCode = "EQ"\n    oLandedCost_CostLine.amount = 100\n    \'oLandedCost_CostLine.AllocationBy = SAPbobsCOM.LandedCostAllocationByEnum.asCashValueAfterCustoms\n    oLandedCost_CostLine.CostType = SAPbobsCOM.LCCostTypeEnum.asVariableCosts\n\n\n    Dim oLandedCostParams As SAPbobsCOM.LandedCostParams = svrLandedCost.GetDataInterface(SAPbobsCOM.LandedCostsServiceDataInterfaces.lcsLandedCostParams)\n\n    \'Add a landed cost\n    Try\n        oLandedCostParams = svrLandedCost.AddLandedCost(oLandedCost)\n        oLandedCostEntry = oLandedCostParams.LandedCostNumber\n    Catch ex As Exception\n        \'exception process\n        MsgBox(ex.Message)\n    End Try\n\n    \'Update a landed cost\n    Dim oLandedCostUpdateParams As SAPbobsCOM.LandedCostParams = svrLandedCost.GetDataInterface(LandedCostsServiceDataInterfaces.lcsLandedCostParams)\n    Dim oLandedCostUpdate As SAPbobsCOM.LandedCost = svrLandedCost.GetDataInterface(LandedCostsServiceDataInterfaces.lcsLandedCost)\n\n    \'Operate on the landed cost\n    oLandedCostUpdateParams.LandedCostNumber = oLandedCostEntry\n    \'Get the landed cost\n    Try\n        oLandedCostUpdate = svrLandedCost.GetLandedCost(oLandedCostUpdateParams)\n    Catch ex As Exception\n        \'exception process\n        MsgBox(ex.Message)\n    End Try\n\n\n    \'Split functionality, split line 1\n    Dim oLandedCostUpdate_ItemLine As SAPbobsCOM.LandedCost_ItemLine\n    oLandedCostUpdate_ItemLine = oLandedCostUpdate.LandedCost_ItemLines.Add()\n    oLandedCostUpdate_ItemLine.OriginLine = 1\n    oLandedCostUpdate_ItemLine.Quantity = 1\n    oLandedCostUpdate_ItemLine.Warehouse = "02"\n\n\n    Dim oLandedCostUpdate_CostLine As SAPbobsCOM.LandedCost_CostLine\n    oLandedCostUpdate_CostLine = oLandedCostUpdate.LandedCost_CostLines.Add()\n\n    oLandedCostUpdate_CostLine.LandedCostCode = "QA"\n    oLandedCostUpdate_CostLine.amount = 50\n    oLandedCostUpdate_CostLine.CostType = SAPbobsCOM.LCCostTypeEnum.asVariableCosts\n    oLandedCostUpdate_CostLine.AllocationBy = LandedCostAllocationByEnum.asQuantity\n\n\n    Try\n        svrLandedCost.UpdateLandedCost(oLandedCostUpdate)\n    Catch ex As Exception\n        \'exception process\n        MsgBox(ex.Message)\n    End Try\n\nEnd Sub\n
Run Code Online (Sandbox Code Playgroud)\n