2014-01-16 108 views
3

我正在創建一個應用程序以將掃描文檔附加到SAP文檔,但是我在該過程中遇到了一些問題。我正在使用SAP BO 9 PL8,並發現下面的問題:使用SAP Business One中的DI API附加文件時出錯9

當我嘗試在更新方法中使用現有附件(使用attachments2對象)添加新附件行時,DI嘗試檢查舊行,並且該文件可能不存在於原始源路徑中。所以,更新方法報告錯誤。我使用以下代碼:

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()); 
} 

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 

當我修改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()); 
    } 
} 

我需要知道我在做什麼錯,或者如果我需要聯繫SAP來通知這些DI問題。我希望你能幫助我。提前致謝。

問候, 佩德羅

回答

0

我通常做這個和它的作品!

Private Sub test_NonContinue_LandedCost() 

    'Sample code for the non-continuous inventory system 
    Dim svrLandedCost As SAPbobsCOM.LandedCostsService = oCompany.GetCompanyService().GetBusinessService(SAPbobsCOM.ServiceTypes.LandedCostsService) 

    Dim oLandedCost As SAPbobsCOM.LandedCost = svrLandedCost.GetDataInterface(SAPbobsCOM.LandedCostsServiceDataInterfaces.lcsLandedCost) 

    Dim oLandedCostEntry As Long = 0 

    Dim GRPOEntry As Integer = 15 

    'Landed cost document - item tab line 1 
    Dim oLandedCost_ItemLine As SAPbobsCOM.LandedCost_ItemLine 
    oLandedCost_ItemLine = oLandedCost.LandedCost_ItemLines.Add 
    oLandedCost_ItemLine.BaseDocumentType = SAPbobsCOM.LandedCostBaseDocumentTypeEnum.asGoodsReceiptPO 
    oLandedCost_ItemLine.BaseEntry = GRPOEntry 
    oLandedCost_ItemLine.BaseLine = 0 

    'Landed cost document - item tab line 2 
    oLandedCost_ItemLine = oLandedCost.LandedCost_ItemLines.Add() 
    oLandedCost_ItemLine.BaseDocumentType = SAPbobsCOM.LandedCostBaseDocumentTypeEnum.asGoodsReceiptPO 
    oLandedCost_ItemLine.BaseEntry = GRPOEntry 
    oLandedCost_ItemLine.BaseLine = 1 

    'Landed cost document - item tab line 3 
    'This is a split line –split from second line (BaseEntry = 13, BaseLine = 1) 
    oLandedCost_ItemLine = oLandedCost.LandedCost_ItemLines.Add() 
    oLandedCost_ItemLine.BaseDocumentType = SAPbobsCOM.LandedCostBaseDocumentTypeEnum.asGoodsReceiptPO 
    oLandedCost_ItemLine.BaseEntry = GRPOEntry 
    oLandedCost_ItemLine.BaseLine = 1 
    oLandedCost_ItemLine.Quantity = 2 
    oLandedCost_ItemLine.Warehouse = "02" 

    'Landed cost document - cost tab line 1 
    Dim oLandedCost_CostLine As SAPbobsCOM.LandedCost_CostLine 
    oLandedCost_CostLine = oLandedCost.LandedCost_CostLines.Add 
    oLandedCost_CostLine.LandedCostCode = "CB" 
    'Suppose the vendor currency is Foreign Currency, if in local currency should set 'oLandedCost_CostLine.amount 
    oLandedCost_CostLine.amount = 100 
    'oLandedCost_CostLine.AllocationBy = SAPbobsCOM.LandedCostAllocationByEnum.asCashValueAfterCustoms 

    'Landed cost document - cost tab line 2 
    oLandedCost_CostLine = oLandedCost.LandedCost_CostLines.Add 
    oLandedCost_CostLine.LandedCostCode = "EQ" 
    oLandedCost_CostLine.amount = 100 
    'oLandedCost_CostLine.AllocationBy = SAPbobsCOM.LandedCostAllocationByEnum.asCashValueAfterCustoms 

    'Landed cost document - cost tab line 3 
    oLandedCost_CostLine = oLandedCost.LandedCost_CostLines.Add 
    oLandedCost_CostLine.LandedCostCode = "EQ" 
    oLandedCost_CostLine.amount = 100 
    'oLandedCost_CostLine.AllocationBy = SAPbobsCOM.LandedCostAllocationByEnum.asCashValueAfterCustoms 
    oLandedCost_CostLine.CostType = SAPbobsCOM.LCCostTypeEnum.asVariableCosts 


    Dim oLandedCostParams As SAPbobsCOM.LandedCostParams = svrLandedCost.GetDataInterface(SAPbobsCOM.LandedCostsServiceDataInterfaces.lcsLandedCostParams) 

    'Add a landed cost 
    Try 
     oLandedCostParams = svrLandedCost.AddLandedCost(oLandedCost) 
     oLandedCostEntry = oLandedCostParams.LandedCostNumber 
    Catch ex As Exception 
     'exception process 
     MsgBox(ex.Message) 
    End Try 

    'Update a landed cost 
    Dim oLandedCostUpdateParams As SAPbobsCOM.LandedCostParams = svrLandedCost.GetDataInterface(LandedCostsServiceDataInterfaces.lcsLandedCostParams) 
    Dim oLandedCostUpdate As SAPbobsCOM.LandedCost = svrLandedCost.GetDataInterface(LandedCostsServiceDataInterfaces.lcsLandedCost) 

    'Operate on the landed cost 
    oLandedCostUpdateParams.LandedCostNumber = oLandedCostEntry 
    'Get the landed cost 
    Try 
     oLandedCostUpdate = svrLandedCost.GetLandedCost(oLandedCostUpdateParams) 
    Catch ex As Exception 
     'exception process 
     MsgBox(ex.Message) 
    End Try 


    'Split functionality, split line 1 
    Dim oLandedCostUpdate_ItemLine As SAPbobsCOM.LandedCost_ItemLine 
    oLandedCostUpdate_ItemLine = oLandedCostUpdate.LandedCost_ItemLines.Add() 
    oLandedCostUpdate_ItemLine.OriginLine = 1 
    oLandedCostUpdate_ItemLine.Quantity = 1 
    oLandedCostUpdate_ItemLine.Warehouse = "02" 


    Dim oLandedCostUpdate_CostLine As SAPbobsCOM.LandedCost_CostLine 
    oLandedCostUpdate_CostLine = oLandedCostUpdate.LandedCost_CostLines.Add() 

    oLandedCostUpdate_CostLine.LandedCostCode = "QA" 
    oLandedCostUpdate_CostLine.amount = 50 
    oLandedCostUpdate_CostLine.CostType = SAPbobsCOM.LCCostTypeEnum.asVariableCosts 
    oLandedCostUpdate_CostLine.AllocationBy = LandedCostAllocationByEnum.asQuantity 


    Try 
     svrLandedCost.UpdateLandedCost(oLandedCostUpdate) 
    Catch ex As Exception 
     'exception process 
     MsgBox(ex.Message) 
    End Try 

End Sub 
0
{ 
oAtt.Lines.Add(); <------ here i think you have a error 

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()); 
} 

通常SAP在對象的第一行是默認的,所以不需要添加一行,除非你要添加多個行。

也許它應該是這樣的:

for(int i = 0 ;i< xxxx; i++) 
{ 
oAtt.Lines.setCurrentLine(i); 

if(i>0) 
{ 
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()); 

XXXX可能是你想添加 行數或對象具有(Att.lines.Count)

行數

Blockquote

相關問題