Skip to Content

Off late, I have received few questions on how retrieve the print preview form (PDF content) of standard business object via coding . In this blog, I would like to share the code snippet to simulate the preview action in ABSL (code). The logic for standard object and custom objects are different as explained below.

Standard Objects:

I will take Quote object as an example. Before we start to write the code, we will require following information related to form template.

  1. Form Template Group Code: Group code identifies the collection of form templates with same semantics grouped under it..
  2. Object Type Code It is the type code of the business object.
  3. Object Node Type CodeIt is the type code of the node (usually root node).

We get the above information from the repository explorer in cloud application studio. (menu options: view->repository explorer) as shown below.

Form Template Group Code: We From repository explorer, under data types, search for OutputRequestFromTemplateGroupCode:

Object Type Code: Again from repository explorer, under business object, select the business object. Under description section you will find the Object Type Code.  . Ex – CustomerQuote = 30

Object Node Type Code: Again from repository explorer, select the root node of the business object. Under description section you will find the Object Node Type Code. Ex- 3807

 

Now we are ready to write the code.

Code snippet:

import ABSL;
import BASIS.Global;
import AP.Common.GDT;
import DocumentServices.Global;

//To simulate Preview
var docOutReq :  elementsof  DocumentOutputRequest;

docOutReq.ReferenceObjectNodeID.content =  this.UUID.content.ToString(); // UUID of root node.
docOutReq.ReferenceObjectNodeTypeCode.content = "3807"; //Object Node Type code of Quote root node
docOutReq.ReferenceObjectTypeCode.content = "30"; //Object type code of Quote BO

var docInst = DocumentOutputRequest.Create(docOutReq);

var FTG : OutputRequestFormTemplateGroupCode;
FTG.content = "C02"; //Form Template Group Code for Quote

docInst.RefreshDefaultOutputRequest(FTG); 

var DocItem = docInst.Item;
var docItem = docInst.Item.GetFirst(); // Or get based on lang, template code.

docItem.Preview(); // Execute preview action
var binCont = docItem.ItemPreview.PreviewBinaryObject; // Get the binary object of PDF.

docInst.Delete();

 

Custom Objects:

It is simple compared to standard objects, we use the standard reuse library 🙂

OutputManagementUtilities.GetPDF(BusinessObjectNode, FormTemplateCode,    FormTemplateLanguage);

  1.  BusinessObjectNode = Node instance of the business object , ex “this”.
  2. FormTemplateCode = Code in the Form Template Header
  3. FormTemplateLanguage = Language of form template, ex ‘E’

Code snippet:

import ABSL;
import AP.Common.GDT;
import DocumentServices.Global;
import BASIS.Global;

//variables
var FormTemplateLanguage = "E";
var PDF : BinaryObject;
var FormTemplateCode : OutputRequestFormTemplateCode;

//Code is Form Template Header Code
//Could be different for Orgianal vs Patch solution.
if(Context.IsPatchSolution()){
	FormTemplateCode.content = "YXXXXXXW_P00RY"; //patch solution
}else{
	FormTemplateCode.content = "YXXXXXXW_P00RY"; //Orignal Solution
}
// Reuse Service Call 
PDF = OutputManagementUtilities.GetPDF(this,FormTemplateCode,FormTemplateLanguage);
To report this post you need to login first.

11 Comments

You must be Logged on to comment or reply to a post.

  1. Said M.

    Dear Pramodh,

    thank you for the great tutorial.
    In order to creat pdf content for custom visits programatically, i’ve following your instruction.
    But it seems, that DocumentOutputRequest not working for Custom Visits.
    my Setup :

    docOutReq.ReferenceObjectNodeTypeCode.content = "38268"; // 3631 try also with apppointmentActivity wich is deprecated
    docOutReq.ReferenceObjectTypeCode.content = "12"; // ​
    .
    .
    .
    FTG.content = "C02";
    .
    .
    .
    Do you have an idea what I did wrong?
    Best Regards
    Said
    (0) 
    1. Pramodh Patil Post author

      Hi Said,

      You mentioned that it is a custom visit. For custom objects please check the second section, there is a standard API.

      thanks & regards

      Pramodh

       

       

       

      (0) 
  2. Benny Huang

    Hi Pramodh,

    In my production system, CustomerInvoice, I use the DocumentOutputRequest.Item, and PreviewBinaryObject, then send it to customer using email. The script is:

    foreach(var attach in ci.DocumentOutputRequest.Item)
    {
    if(attach.Status.OutputStatusCode != “3”)
    {
    var attachment : pe:Attachment;
    attachment.FileName=attach.DocumentName+”.pdf”;
    attachment.Binary=attach.ItemPreview.PreviewBinaryObject.content;
    attachments.Add(attachment);
    }
    }

    The issue: the PDF attached to the customer email is blank, but also has the “Test Copy”  watermark on the bottom-right of the page.

    In test system hasn’t the issue, do you know where the problem is?

    Best Regards,

    Benny Huang

    (0) 
    1. Pramodh Patil Post author

      Hi Benny,

      Can you please check what is the active template for the group code in form maintenance UI?

      If there are multiple templates available for the same group code, then you might have to loop through the DocumentOutputRequest.Item and pick the right template based the template code language.

      Hope this helps.

      Thanks & regards

      Pramodh

      (0) 
      1. Benny Huang

        Hi Pramodh,

        Thanks a lot.

        Now I using the script as you, the template is ok, now still has the “Test Copy” issue in my production. Could I do something in the script?

        Best Regards,

        Benny Huang

        (0) 
        1. Pramodh Patil Post author

           

          Hi Benny,

          The Test Copy should removed from the template, and cannot be handled in the script.

          Please check from UI Workcenter  Application User Management-> Business Flexibility – Master Template Maintenance for any logs or header/footers.

          Business Flexibility – Form Template Maintenance : For the form and check if it has test copy and replace with correct template.

          thanks & regards

          Pramodh

          (0) 
  3. Rufat Gadirov

    Hi Pramodh,

    thank you for the tutorial!

    I implemented the exact code for Customer Quote Standard BO and I bound it to a custom action

    on Quote TI (Root Level, single) via the extensibility explorer. But unfortunately, it loads shortly but

    nothing shows up. I also debugged the Code and I can see that only one doc item instance is found

    for “C02” (Form Template Group Code).

    Therefore, I didn´t loop via the doc items via language and country code.

    Do you have any idea what the issue could be?

    Best regards,

    Rufat

    (0) 
    1. Pramodh Patil Post author

       

      Hi Rufat,

       

      To be clear, this action will not preview the PDF on UI, it will only fetch you the PDF binary content, which you can for ex add it to attachments or e-mail.

      In your case, did you get the binary content?

      var binCont = docItem.ItemPreview.PreviewBinaryObject

      was PreviewBinaryObject filled?

      Thanks & regards

      Pramodh

      (0) 
  4. Rufat Gadirov

    Dear Pramodh,

     

    thank you for the clarification! Yes, I did get the binary content. But my initial goal was to build a custom print preview as we wanted to check if we can use our own print preview or use the sap standard action in our own custom action for quotes. We implemented several custom actions and didn´t want to have several buttons on the UI but use only one. So, as I understood, there is no quick possibility to implement a custom print preview for standard sap objects like CustomerQuote?

    Best regards

    Rufat

    (0) 

Leave a Reply