AgileApps Support Wiki Pre Release

Code:Generate an Attachment

From AgileApps Support Wiki
Revision as of 21:08, 16 January 2014 by 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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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. Use the generateDocument API to create a PDF (or HTML) document from an existing template.
  2. Use the getDocument API to retrieve it, in the form of a PlatformFileBean.
  3. Use the addRecord API to attach the PlaformFileBean to the case.
<syntaxhighlight lang="java" enclose="div">

import com.platform.api.*; import com.platform.beans.*;

class SampleCodeToGenerateAnAttachment { {

 // This signature allows the method to be invoked from a rule
 public ... {
    //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);
 }

} </syntaxhighlight>