Difference between revisions of "Code:Generate an Attachment"

From AgileApps Support Wiki
imported>Aeric
(Created page with "This example uses a Document Template to generate a PDF, and then attaches the PDF to the current case. In outline, the process is: # Use the generateDocument API to cr...")
 
imported>Aeric
Line 2: Line 2:


In outline, the process is:
In outline, the process is:
# Get the record ID from the [[incoming method parameters]].
# Use the [[generateDocument]] API to create a PDF (or HTML) document from an existing template.
# Use the [[generateDocument]] API to create a PDF (or HTML) document from an existing template.
# Use the [[getDocument]] API to retrieve it, in the form of a {{^PlatformFileBean}}.
# Use the [[getDocument]] API to retrieve it, in the form of a {{^PlatformFileBean}}.
Line 15: Line 16:
   public ... {
   public ... {


     //Generate the document
    // Get the record ID from the incoming parameters
 
     // Generate the document
     Result result = Functions.generateDocument(_______, "CONSTANTS.DOCUMENT.PDF");
     Result result = Functions.generateDocument(_______, "CONSTANTS.DOCUMENT.PDF");
         // or CONSTANTS.DOCUMENT.HTML  
         // or CONSTANTS.DOCUMENT.HTML  

Revision as of 21:10, 16 January 2014

This example uses a Document Template to generate a PDF, and then attaches the PDF to the current case.

In outline, the process is:

  1. Get the record ID from the incoming method parameters.
  2. Use the generateDocument API to create a PDF (or HTML) document from an existing template.
  3. Use the getDocument API to retrieve it, in the form of a PlatformFileBean.
  4. Use the addRecord API to attach the PlaformFileBean to the case.
import com.platform.api.*;
import com.platform.beans.*;

class SampleCodeToGenerateAnAttachment {
{
  // This signature allows the method to be invoked from a rule
  public ... {

     // Get the record ID from the incoming parameters

     // Generate the document
     Result result = Functions.generateDocument(_______, "CONSTANTS.DOCUMENT.PDF");
        // or CONSTANTS.DOCUMENT.HTML 

     // Retrieve the file
     r.
     PlatformFileBean fileBean = Functions.getDocument(

     // Add the document as an attachment
     Parameters params = Functions.getParametersInstance();
     params.add("title", "…name of generated file…");
     params.add("file_field", fileBean );
     params.add("related_to", "cases:"+recordID);
     result = Functions.addRecord("attachments", params);
  }
}