Code:Generate an Attachment
From AgileApps Support Wiki
Revision as of 21:10, 16 January 2014 by imported>Aeric
This example uses a Document Template to generate a PDF, and then attaches the PDF to the current case.
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 getDocument API to retrieve it, in the form of a PlatformFileBean.
- 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 ... {
// 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); }
} </syntaxhighlight>