Extension of LD.AddAttachment function

Table of Contents

I Introduction

II How-to

    1. Understanding the sample script for Layoutdefinitions (Sharpshooter)
    2. Steps for setting up "Print attachments with Coresuite Designer using the sample script for Layoutdefinition (Sharpshooter)"
    3. Steps for setting up "Print attachments with Coresuite Service using the sample script for Layoutdefinition (Sharpshooter)"
    4. Steps for setting up "Printing attachments using Coresuite Customize using the DOC:0020: Add Or Print Additional Attachments sample Optimizer rule"

III Use case

IV Good to know

 

 

I Introduction (Back to Table of Contents)

With the 7.40 Release, we extended the LD.AddAttachment function to also facilitate (physical) printing. This means you no longer have to write your own complicated scripts to achieve this (see old Forum entries etc.).

The LD.AddAttachment function had been made available at the time, to facilitate the adding of additional files when emailing SAP Business One marketing documents (see e.g. Coresuite Country Package manual - LD.AddAttachment).

The naming "AddAttachment" derives from adding an (additional) attachment to an email generated for sending primarily SAP Business One marketing documents. 

Those attachments are often, but not exclusively, files that are saved in the "Attachment" tab/folder in SAP Business One marketing documents or Masterdata.

As of version 7.40, it is possible to use the LD.AddAttachment function for both, emailing and printing. The function allows for either adding static (files you saved in a specific, fixed location such as a catalogue, Terms of Conditions etc.) or dynamic (files with specifically associations that are meant to printed conditionally e.g. Product-sheets that you have saved in Item Masterdata, that you want to printout together with a Sales Order where they are included) files.

LD.AddAttachment can be used directly in GenerateScripts in your Coresuite Designer Sharpshooter Layout, but also in Coresuite Customize rules. The function works for native Coresuite Designer but also in combination with Coresuite Service.

 

 

II How-to (Back to Table of Contents)

When using the LD.AddAttachment function to print attachments vs adding attachments to an email, you need to specify this by setting the "Attachment printing" flag in the "Printer" tab in the respective Layoutdefinition. The "Attachment printing" flag was added with Coresuite Designer, version 7.40: 
Screenshot1.JPG This is required whether you use the LD.AddAttachment function directly in a Sharpshooter layout or in a Customize rule.

 

 

A. Understanding the sample script for Layoutdefinitions (Sharpshooter) (Back to Table of Contents)

The following is a sample script to be used in GenerateScripts in Sharpshooter and can be downloaded from here:

Screenshot2.JPG

  • This is the condition for when the script should be executed:
    GetData("LD.Par.PrintMode") = "N" And GetData("LD.Par.Preview") = "N" And Not Engine.IsDoublePass
  • SAP Business One links the Attachment tab/folder in SAP Business One marketing documents or Masterdata via the Attachments table (OATC), hence you need this key:
    Dim attachmentId As String = Document("AtcEntry")
    from the Coresuite Designer Document Datasource.
  • You use this to establish the "number" of files saved to the attachment tab/folder:
    Dim attachmentCount As Integer = LD.QueryData("Select Count(*) FROM [ATC1] T0 WHERE T0.[AbsEntry] = '"+ attachmentId +"'",True)
    By using the ",True" in the LD.QueryData function, the approach that is required for HANA environments, makes the query universal and hence can be used in SQL and HANA environments.
  • You need this to prepare the list of all files saved to the attachment tab/folder:
    For attachmentLine As Integer = 1 To attachmentCount
    • This query (to be used in SQL environments) generates the list to all full file paths of all files saved to the attachment tab/folder:
      'SQL
            Dim filePath As String = LD.QueryData("SELECT CAST([trgtPath] As nvarchar(max)) + '\' + CAST([FileName] AS nvarchar(max)) + '.' + [FileExt] FROM [ATC1] WHERE [Line] = '" + attachmentLine.ToString() + "' AND [AbsEntry] = '" + attachmentId + "'")
      Note: comment or uncomment this part of the script as required
    • This query (to be used in HANA environments hence using the ",True" in the LD.QueryData function) generates the full list of file paths of all files saved to the attachment tab/folder:
      'HANA
          Dim filePath As String = LD.QueryData("SELECT CAST([trgtPath] As nvarchar(250)) || '\' || [FileName]  || '.' || [FileExt] FROM [ATC1] WHERE [Line] = '" + attachmentLine.ToString() + "' AND [AbsEntry] = '" + attachmentId + "'",True)
      Note: comment or uncomment this part of the script as required
  • This takes care of the final printing:
    LD.AddAttachment(filePath)
  • You can use this to display the list of all attachments to be printed in the debug log:
    SwissAddonFramework.Messaging.Debug.Info("Added attachment '"+ filePath +"'")

 

B. Steps for setting up "Print attachments with Coresuite Designer using the sample script for Layoutdefinition (Sharpshooter)" (Back to Table of Contents)

Use the following steps to print all attachments linked on your SAP Business One marketing document (e.g. Sales Order) together with your "main" document:

  1. Go to the "Printer" tab of the Layoutdefinition that you use to print your actual document (e.g. Sales Order) and either add a new row or use any of the existing rows to select the "Attachment printing" flag.

    Note:
    • if there are no other special printer settings required, you only need to set that flag in the new row and leave the rest as is
    • if you already have various printer settings applied, evaluate in which row your flag would be set most appropriately according to your requirements
  2. Open the Layout in Sharpshooter
    • as you are trying to print attachments linked to an SAP Business One marketing document, go to "Document" GenerateScript
    • append the script sample from here


This is it - any files saved in the "Attachment" tab/folder in your SAP Business One marketing documents will now be printed together with your "main" document.

 

C. Steps for setting up "Print attachments with Coresuite Service using the sample script for Layoutdefinition (Sharpshooter)" (Back to Table of Contents)

Use the following steps to print all attachments linked on your SAP Business One marketing document (e.g. Sales Order) together with your document when it is printed using Coresuite Service:

  1. Prepare your Layoutdefinition as described above
  2. Go to the Printdefinition where you want to use the prepared Layoutdefinition and check its "Name Id" in the "Extended Definition" tab
    • should there be no "Name Id" defined, add it
    • if there is already a "Name Id" defined, copy it
  3. Go to your Coresuite Service rule (details on how to set up and use Coresuite Service rules can be found in the document attached to our Coresuite Service FAQ) and add your "Name Id" to the appropriate location


This is it - any files saved in the "Attachment" tab/folder in your SAP Business One marketing documents will now be printed together with your document when using Coresuite Service for printing.

 

D. Steps for setting up "Printing attachments using Coresuite Customize using the DOC:0020: Add Or Print Additional Attachments sample Optimizer rule" (Back to Table of Contents)

Use the following steps to print all attachments linked on your SAP Business One marketing document (e.g. Sales Order) together with your document. When using an Optimizer rule, you will not need to modify any scripts in your Layoutdefintion.

  1. Go to the "Printer" tab of the Layoutdefinition that you use to print your actual document (e.g. Sales Order) and either add a new row or use any of the existing rows to select the "Attachment printing" flag.

    Note:
    • if there are no other special printer settings required, you only need to set that flag in the new row and leave the rest as is
    • if you already have various printer settings applied, evaluate in which row your flag would be set most appropriately according to your requirements
  2. As we have updated the DOC:0020: Add Or Print Additional Attachments sample Optimizer rule with version 7.40, please re-import it as described in Coresuite Country Package manual - Import Example Rules (Examples).
  3. Once imported, go to coresuite customize->Optimizer activate this rule.
  4. Go to the Printdefinition which contains the Layoutdefinition with the Layout which you want to use for printing check its "Name Id" in the "Extended Definition" tab.
  5. Go back to the rule and check if the "Form Type" column of your rule contains the "Name Id" of your Printdefinition, if not add it.


This is it - any files saved in the "Attachment" tab/folder in your SAP Business One marketing documents will now be printed together with your document.

 

 

III Use case (Back to Table of Contents)

The LD.AddAttachment function can be used in a number of different scenarios. Think of:

  • Printing/emailing catalogues files that you have not attached anywhere but saved in a specific location together with Sales Quotations.
  • Further amending the query in the sample script to filter by "FreeText" which of the SAP Business One attachments should be printed.
  • Printing/emailing product sheets that you have saved in Item Masterdata, that you want to print out together with a Sales Order where they are included.
  • Printing/emailing effort/activity reports together with an AR Invoice - first create the effort/activity reports as attachments to access it via the LD.AddAttachment function.
  • Printing/emailing AR Invoices together with Dunning Letters - create a PDF for each AR Invoice and save it in its own "Attachment" tab/folder to access it via the LD.AddAttachment function.

 

 

IV Good to know (Back to Table of Contents)

  • The LD.AddAttachment function currently supports (attachment) files of type PDF, DOCX and TXT.
  • Add/Update the GenerateScript in Sharpshooter on "Document" level when you need to add the "attachments" per document;
    Add/Update the GenerateScript in Sharpshooter on "Databand" level when you e.g. need to add the "attachments" per item.

 

 

(Back to Table of Contents)

Was this article helpful?
2 out of 2 found this helpful
Have more questions? Submit a request

Comments

0 comments

Article is closed for comments.