Jump to content


Willkommen im Coresystems Community Forum

Dieses Forum wird nicht mehr weiter betrieben.
Sollten Sie eine Lösung für eine spezifische Aufgabenstellung suchen wenden Sie sich bitte an unseren Support: helpdesk.coresystems.ch.
Für allgemeine Produktinformationen kontaktieren Sie unser Sales-Team: sales@coresystems.ch

Welcome at the coresystems community forum

This forum is no longer being maintained.
If you need a specific solution please contact our support: helpdesk.coresystems.ch.
For general product information do not hesitate to contact our sales team: sales@coresystems.ch

Photo
- - - - -

Add an attachment to a Document (e.g. a Delivery)


  • Please log in to reply
4 replies to this topic

#1 Paolo Manfrin

Paolo Manfrin

    Advanced Member

  • Moderators
  • 418 posts
  • LocationSwitzerland

Posted 20 May 2014 - 15:11

In this sample I would like to show a piece of code how to add an attachment to a Delivery via DI

// attach the PDF to the Delivery document
string exportPathForSAP = Path.GetTempPath().Substring(0, Path.GetTempPath().Length - 1);
SAPbobsCOM.Documents oDelivery = (SAPbobsCOM.Documents)SwissAddonFramework.B1Connector.GetB1Connector().Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDeliveryNotes);
oDelivery.GetByKey(Convert.ToInt32(DocEntry));

SAPbobsCOM.Attachments2 oAttachment = (SAPbobsCOM.Attachments2)SwissAddonFramework.B1Connector.GetB1Connector().Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oAttachments2);
if (oAttachment.GetByKey(oDelivery.AttachmentEntry))
{
    // the document has already attachments 
    oAttachment.Lines.Add();
    oAttachment.Lines.SetCurrentLine(oAttachment.Lines.Count-1);
    oAttachment.Lines.FileName = "PDF_ " + this.MessageReference + ".pdf";
    oAttachment.Lines.SourcePath = exportPathForSAP;
    oAttachment.Lines.Override = SAPbobsCOM.BoYesNoEnum.tYES;
    if (oAttachment.Update()!=0)
    {
        string errMsg = SwissAddonFramework.B1Connector.GetB1Connector().Company.GetLastErrorDescription();
        SwissAddonFramework.Messaging.StatusBar.WriteError(errMsg);
    }
    System.Diagnostics.Process.Start(exportPath);
}
else
{   // the document has no attachments assigned so far
    oAttachment.Lines.FileName = "PDF_ " + this.MessageReference + ".pdf";
    oAttachment.Lines.SourcePath = exportPathForSAP;
    if (oAttachment.Add() != 0)
    {
        string errMsg = SwissAddonFramework.B1Connector.GetB1Connector().Company.GetLastErrorDescription();
        SwissAddonFramework.Messaging.StatusBar.WriteError(errMsg);
    }

    string objKey = SwissAddonFramework.B1Connector.GetB1Connector().Company.GetNewObjectKey();
    oAttachment.GetByKey(Convert.ToInt32(objKey));
    int absEntry = oAttachment.AbsoluteEntry;
    oDelivery.AttachmentEntry = oAttachment.AbsoluteEntry;

    if (oDelivery.Update() != 0)
    { 
        // error
        string errMsg = SwissAddonFramework.B1Connector.GetB1Connector().Company.GetLastErrorDescription();
        SwissAddonFramework.Messaging.StatusBar.WriteError(errMsg);
        return;
    }
    SwissAddonFramework.Messaging.StatusBar.WriteSucess("Attachment added succesful to Delivery " + DocNum);
    System.Diagnostics.Process.Start(exportPath);
}

Enjoy!



#2 Jan_de_Lange

Jan_de_Lange

    Member

  • Members
  • PipPip
  • 11 posts

Posted 20 June 2014 - 10:27

Hello Paolo,

 

Thats just what I was looking for. How/where do Iimplement this code in Designer?

 

 

 Kind regards

 

Jan de Lange



#3 Paolo Manfrin

Paolo Manfrin

    Advanced Member

  • Moderators
  • 418 posts
  • LocationSwitzerland

Posted 20 June 2014 - 11:05

Hi Jan, 

you do not implement this in designer but rather in customize.

You can link it to an optimizer rule or a function button rule for example.

cheers

paolo



#4 Jan_de_Lange

Jan_de_Lange

    Member

  • Members
  • PipPip
  • 11 posts

Posted 20 June 2014 - 15:56

Thanks, I have edited a customise rule but there is a compiler error as the result of that.

 

if (oAttachment.Update()! = 0) gives various errors:

 

What did i do wrong? or is there something missing?



#5 Paolo Manfrin

Paolo Manfrin

    Advanced Member

  • Moderators
  • 418 posts
  • LocationSwitzerland

Posted 1 July 2014 - 16:09

Hi Jan,

please post some screenshots and the errors you get. 

Thank You

paolo






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users