cancel
Showing results for 
Search instead for 
Did you mean: 

Add Attachment to Delivery Note By DI API

Former Member
0 Kudos

Hello Experts

can i add attachment to delivery note or sale order by DI api

i did code for that but it giving error for Delivery not object but it working fine for activity object

This is My code

///////////////////////

  try

            {

                SAPbobsCOM.Attachments2 oATT = LoginForm.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oAttachments2) as SAPbobsCOM.Attachments2;

                string FileName = "C:\\Test\\MyTest.txt";

                oATT.Lines.Add();

                oATT.Lines.FileName = System.IO.Path.GetFileNameWithoutExtension(FileName);

                oATT.Lines.FileExtension = System.IO.Path.GetExtension(FileName).Substring(1);

                oATT.Lines.SourcePath = System.IO.Path.GetDirectoryName(FileName);

                oATT.Lines.Override = SAPbobsCOM.BoYesNoEnum.tYES;

                SAPbobsCOM.Contacts ACT;

                SAPbobsCOM.Documents oSO;

                SAPbobsCOM.Documents odelivery;

                 //// SAPbobsCOM.SalesOpportunities oactivity;

                oSO = (SAPbobsCOM.Documents)LoginForm.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders);

                odelivery = (SAPbobsCOM.Documents)LoginForm.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDeliveryNotes);

                                ACT = (SAPbobsCOM.Contacts)LoginForm.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oContacts);

                int iAttEntry = -1;

                if (oATT.Add() == 0)

                {

                    iAttEntry = int.Parse(LoginForm.oCompany.GetNewObjectKey());

                    //Assign the attachment to the GR object (GR is my SAPbobsCOM.Documents object) 

                    odelivery.AttachmentEntry = iAttEntry;

                } 

                 }

            catch (Exception ex)

            {

                // c = false;

                MessageBox.Show(ex.Message);

            }

Accepted Solutions (1)

Accepted Solutions (1)

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Vilas,

Follow this:

How do I create or copy an attatchment to Sales... | SCN

Hope that helps.

Thanks & Regards

ANKIT CHAUHAN

SAP Business One Global Support

Former Member
0 Kudos

Hello Ankit

I am getting error (Object does not support this method or method not implemented)

on  ( oDLN.AttachmentEntry = AttEntry;) code

ODLN is Delivery Not object

Please help me for

I am Uing 9.0 PL 12 version of SAP b1

former_member185682
Active Contributor
0 Kudos

Hi Vilas,

Can you provide more details to help us to understand your situation?

I followed Ankit's suggestion and worked fine.

I tested your code too, and worked fine too.

In two ways worked fine: using SAP version 9.1 PL 8 and version 9.0 PL 11.

Regards,

Diego

Former Member
0 Kudos

Hello Diego

I am using SAP 9.0 PL 12 and am also doing same as Ankit but it giving error on

Object.Attachmententry (Object does not support this method or method not implemented)on  ( oDLN.AttachmentEntry = AttEntry;)

Is This problem Of version?

I Think It should Work On Each PL Of SAP (9.0)

THis Is My Code

/////////////////////////////////////////

   try

            {

                SAPbobsCOM.Attachments2 oAtt = (SAPbobsCOM.Attachments2)LoginForm.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oAttachments2);

                string FileName = "C:\\Test\\MyTest.txt";

                //oATT.Lines.Add();

                //oATT.Lines.FileName = System.IO.Path.GetFileNameWithoutExtension(FileName);

                //oATT.Lines.FileExtension = System.IO.Path.GetExtension(FileName).Substring(1);

                //oATT.Lines.SourcePath = System.IO.Path.GetDirectoryName(FileName);

                //oATT.Lines.Override = SAPbobsCOM.BoYesNoEnum.tYES;

                if (System.IO.File.Exists("C:\\Test\\MyTest.txt"))

                {

                    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 iErr = oAtt.Add();

                    int AttEntry = 0;

                    if (iErr == 0)

                    {

                        AttEntry = int.Parse(LoginForm.oCompany.GetNewObjectKey());

                        SAPbobsCOM.Documents oDLN = (SAPbobsCOM.Documents)LoginForm.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDeliveryNotes);

                        oDLN.CardCode = "C00000852";

                        oDLN.AttachmentEntry = AttEntry;

                        oDLN.Lines.BaseEntry = 362;

                        oDLN.Lines.BaseType = 17;

                        oDLN.Lines.BaseLine = 0;

                        iErr = oDLN.Add();

                        if (iErr != 0) MessageBox.Show(LoginForm.oCompany.GetLastErrorDescription());

                    }

                } 

            }

            catch (Exception ex)

            {

                // c = false;

                MessageBox.Show(ex.Message);

            }

former_member185682
Active Contributor
0 Kudos

Hi vilas,

Verify the version of SAPBobsCom that you are referencing in your project. I believe that you are using the version 8.90 or older. In this version, the property AttachmentEntry isn't available. For use this property, you need use a SAPBobsCom 9.0 or latest.

Regards

Diego

Former Member
0 Kudos

Hello DIEGO

Thanks It is working on SAP 9.1

My Text file copied in Attachment folder also entry pass in Attachment table

but i need help to update delivery Record with specific Attachment so that it will see in Specific Document

former_member185682
Active Contributor
0 Kudos

Hi vilas,

I think that I didn't understand the problem, if you saved your attachment, you just need associate the value of the key of Attachments2 object to the property AttachmentEntry in the Delivery object. But this property "AttachmentEntry " is only available in version 9.0 or latest from SAPBobsCom.

Your code that you past in the last answer works fine if you use a newly SAPBobsCom.

With your code, I get this result in my sap b1 client:

Regards,

Diego

Former Member
0 Kudos

Thanks Everyone

Its working

former_member188471
Active Contributor
0 Kudos

Diego, Could you share me your code. Thanks

former_member185682
Active Contributor
0 Kudos

Hi CAB,

I used the code provided in this thread How do I create or copy an attatchment to Sales... | SCN

and the code provided by Vilas Maskey in your first question.


Best regards,

Diego Lother


View Diego Lother's profile on LinkedIn

former_member188471
Active Contributor
0 Kudos

I'm trying to purchase invoice but I get error -5002 , the code is the same. You will have idea that it might be?


'Meter los archivos como adjunto al documento

                Dim Adjuntos As SAPbobsCOM.Attachments2

                Adjuntos = oCompany.GetBusinessObject(oAttachments2)

              

                Adjuntos.Lines.SourcePath = "c\repsotiorio"

                Adjuntos.Lines.FileName = "AVM950418QQ6_431309_FAA_8B2CE109-ECBC-45A7-BD93-89772A70CC84_"

                Adjuntos.Lines.FileExtension = "xml"

             

                Try

                    Dim iAttEntry As Integer = -1

                    Dim errorat As Integer = Adjuntos.Add()    '******HERE GENERATES ERROR

                    If (errorat = 0) Then

                        iAttEntry = Int32.Parse(oCompany.GetNewObjectKey())

                        oDocumentoSAP.AttachmentEntry = iAttEntry

                    End If

                Catch ex As Exception

                End Try

The purchase invoice already exists , I'm just attaching a file xml.

former_member185682
Active Contributor
0 Kudos

Hi CAB,

After this:

Dim errorat As Integer = Adjuntos.Add()


call:


Dim errorDesc As string = oCompany.GetLastErrorDescription()


-5002 can be this error : A folder attachments was not set or the attachment folder has been modified or deleted.


Hope it helps.


Best regards,

Diego Lother


View Diego Lother's profile on LinkedIn

former_member188471
Active Contributor
0 Kudos

You gave me a great north : the path was bad .



thanks,

Answers (0)