Skip to Content
0

How to add attachment to ARINVOICE using SAPBuisnessOneSDK

Feb 22, 2017 at 12:30 PM

62

avatar image

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.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
DIEGO LOTHER Feb 22, 2017 at 06:43 PM
1

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

Show 3 Share
10 |10000 characters needed characters left characters exceeded

Hi Diego,

It works, thank you very much.

But I have another related question.

The image I'd like to attach is located in the folder "C:\images\".

When I use code below everything works fine but image is being copied to Desktop folder and attachment's path is "C:\Users\TestSAP\Desktop" as you can see from screenshot. Is it possible to specify the folder where the attachment will be copied?

I really appreciate your help.

Waiting for the answer.

Sincerely, Alex.

Attachments2 oAtt = (Attachments2)company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oAttachments2);
string filename = @"C:\images\untitled.png";
if (File.Exists(filename))
{
    oAtt.Lines.SourcePath = Path.GetDirectoryName(filename);
    oAtt.Lines.FileName = Path.GetFileNameWithoutExtension(filename);
    oAtt.Lines.FileExtension = Path.GetExtension(filename).Substring(1);
    oAtt.Lines.Override = BoYesNoEnum.tYES;
    int attEntry = 0;
    if (oAtt.Add() == 0)
    {
         attEntry = int.Parse(company.GetNewObjectKey());
         document.AttachmentEntry = attEntry;
    }
    else
    throw new Exception("Could not add attachment : " + company.GetLastErrorDescription());
}
capture.png (11.5 kB)
0

Hi Alex,

Go to the Administration --> System Initialization --> General Settings on path tab and set what is your attachment folder. This is the path that should be showed in your path field on the attachment tab on your document form.

Hope it helps.

Kind Regards,

Diego Lother

0

Hi Diego.

Thank you once again!

Sincerely, Alex.

0