C# 在SAP Business One 9中使用DI API附加文件时出错
我正在创建一个应用程序,以便在SAP documents中附加扫描的文档,但我在该过程中遇到了一些问题。我正在使用SAP BO 9 PL8,发现了以下问题: 当我尝试使用update方法在现有附件(使用attachments2对象)中添加新的附件行时,DI会尝试检查旧的行,并且文件可能不存在于原始源路径中。所以,update方法报告了一个错误。我使用以下代码:C# 在SAP Business One 9中使用DI API附加文件时出错,c#,attachment,sapb1,C#,Attachment,Sapb1,我正在创建一个应用程序,以便在SAP documents中附加扫描的文档,但我在该过程中遇到了一些问题。我正在使用SAP BO 9 PL8,发现了以下问题: 当我尝试使用update方法在现有附件(使用attachments2对象)中添加新的附件行时,DI会尝试检查旧的行,并且文件可能不存在于原始源路径中。所以,update方法报告了一个错误。我使用以下代码: Attachments2 oAtt = oCompany.GetBusinessObject(BoObjectTypes.oAttach
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());
}
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访问此功能。例如,物料主数据(oItems)或库存转移(OSTOCKTRANSER)。它们有一个与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
当我在LandCost对象中修改AttachmentEntry属性时,当我尝试更新该对象时,该对象将失败。如果对象已经有附件(手动添加),则在新行中添加新附件有效。第一种情况的错误是:没有找到匹配的记录(ODBC-2028)。当我强制执行catch块时,我会得到其他信息:“1320000126-不正确的更新头字段”。我使用以下代码:
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());
}
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问题。我希望你能帮助我。提前谢谢
问候,,
佩德罗我通常这样做,而且效果很好
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
{
oAtt.Lines.Add();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;
}
如果(oAtt.Update()!=0)
抛出新异常(oCompany.GetLastErrorDescription());
xxxx可以是您要添加的行数
或对象的行数(Att.lines.Count)
大宗报价