Skip to Content
avatar image
Former Member

How to add attachment to ARINVOICE using SAPBuisnessOneSDK

Hello.

I'm working on data exportation from our product to SAP Buisness One using SAPBuisnessOneSDK.dll.

I try to export ARInvoice, APInvoice, SalesOrder and PurchaseOrder.

How can I add attachment to these type of documents so they reveal at attachment table?

Hope you can provide me with advice or some piece of code.

Waiting for the answer.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Feb 22, 2017 at 06:43 PM

    Hi Alex,

    You need to use the Attachments2 object to insert attachments for SAP Business One and after this, reference the id of your attachment entry for your document.

    Below a sample:

    Attachments2 oAtt = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oAttachments2);
                    string filename = @"C:\Users\diego.lother\Desktop\txt.txt";
                    if (File.Exists(filename))
                    {
                        oAtt.Lines.SourcePath = System.IO.Path.GetDirectoryName(filename);
                        oAtt.Lines.FileName = System.IO.Path.GetFileNameWithoutExtension(filename);
                        oAtt.Lines.FileExtension = System.IO.Path.GetExtension(filename).Substring(1);
                        oAtt.Lines.Override = SAPbobsCOM.BoYesNoEnum.tYES;
                        int attEntry = 0;
                        if (oAtt.Add() == 0)
                        {
                            attEntry = int.Parse(oCompany.GetNewObjectKey());
                            Documents oDoc = oCompany.GetBusinessObject(BoObjectTypes.oInvoices);
                            oDoc.CardCode = "C00000001";
                            oDoc.DocDueDate = DateTime.Now;
                            oDoc.DocType = BoDocumentTypes.dDocument_Service;
                            oDoc.Lines.ItemDescription = "Test";
                            oDoc.Lines.AccountCode = "5.01.02.05.39";
                            oDoc.Lines.LineTotal = 100.00;
                            oDoc.AttachmentEntry = attEntry;
                            if (oDoc.Add() != 0)
                                MessageBox.Show(oCompany.GetLastErrorDescription());
                        }
                        else
                            MessageBox.Show(oCompany.GetLastErrorDescription());
                    }
    

    Hope it helps.

    Kind Regards,

    Diego Lother

    Add comment
    10|10000 characters needed characters exceeded