title: Error attaching a file using the DI API in SAP Business One 9
body: <p>I'm creating an application to attach scanned documents at SAP documents, but I have some problems with that process. I'm using SAP BO 9 PL8 and found the next problems:</p>
  
  <p>When I try to add a new attachment line in a existing attachment (using the attachments2 object) with the update method, the DI try to check older lines, and it's possible that the file not exists in the original source path. So, update method reports an error. I use the code below:</p>
  
  <pre><code>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());  
  }  
  </code></pre>
  
  <p>There are some documents in SAP who have a attachment tab, but via DI is not possible access to this functionality. For example the item master data (oItems) or the stock transfer (oStockTransfer). They have a AttachmentEntry field like the Documents object, but the objects haven't a property to add a attachment, so I have to create an activity for this documents.</p>
  
  <pre><code>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  
  </code></pre>
  
  <p>When I modify the AttachmentEntry property in LandedCost object, the object fail when I try to update it. If the object have already an attachment (added manually), add a new attachment in a new line works. The error of the first case is: No matching records found (ODBC -2028). When I force a catch block I get this other information: "1320000126 - Incorrect update header field". I use the code below:</p>
  
  <pre><code>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());  
      }  
  }  
  </code></pre>
  
  <p>I need to know what I'm doing wrong or if I need to contact with SAP to inform about these DI issues. I hope you can help me. Thanks in advance.</p>
  
  <p>Regards,
  Pedro</p>