Difference between revisions of "GenerateDocument"

From AgileApps Support Wiki
imported>Aeric
imported>Aeric
Line 22: Line 22:
::* Pass it to the {{^Fcn}} <tt>getDocument()</tt> method to get a {{^PlatformFileBean}} that contains the document
::* Pass it to the {{^Fcn}} <tt>getDocument()</tt> method to get a {{^PlatformFileBean}} that contains the document


;Example:This example calls <tt>generateDocument</tt> for a lead, creating a HTML document.
;Example:This example calls <tt>generateDocument</tt> on a case to create an HTML document.


:<syntaxhighlight lang="java" enclose="div">
:<syntaxhighlight lang="java" enclose="div">
String printTemplateID = "";
String printTemplate = "";     // Code this value
String leadID = "";
String recordID = "";         // Get this value from incoming parameters
// Some code to populate printTemplateID.
  ...
// Some code to populate leadID.
Result result = Functions.generateDocument("Cases", recordID, printTemplate, CONSTANTS.DOCUMENT.HTML);
Result result = Functions.generateDocument("LEAD", leadID, printTemplateID, CONSTANTS.DOCUMENT.HTML);
int resultCode = result.getCode();
int resultCode = result.getCode();
if(resultCode < 0)
if(resultCode < 0)
Line 39: Line 38:
else
else
{
{
     // Some business logic.
    String doc_id = result.getID();
    PlatformFileBean file = Functions.getDocument(doc_id);
 
     // Additional business logic...
}
}
</syntaxhighlight>
</syntaxhighlight>

Revision as of 02:46, 16 January 2014

Generates a document based on an HTML Document Template.

Syntax

Result result;
result = Functions.generateDocument(String object, String recordID, 
                                    String printTemplate, String format);

Parameters

object
The name or identifier of the object that contains the record of interest.
recordID
The identifier of the record to pass to the template.
printTemplate
The name or identifier of the Document Template
format
CONSTANTS.DOCUMENT.HTML -or- CONSTANTS.DOCUMENT.PDF

Return

Result object
Usage
  • Use result.getID() to retrieve the document ID
  • Pass it to the Functions class getDocument() method to get a PlatformFileBean that contains the document
Example
This example calls generateDocument on a case to create an HTML document.
String printTemplate = "";     // Code this value
String recordID = "";          // Get this value from incoming parameters
  ...
Result result = Functions.generateDocument("Cases", recordID, printTemplate, CONSTANTS.DOCUMENT.HTML);
int resultCode = result.getCode();
if(resultCode < 0)
{
    String msg = "Some Message";
    Logger.info(msg + ":\n" + result.getMessage(), "Doc"); // Log details
    Functions.throwError(msg + ".");                       // Error message
}
else
{
    String doc_id = result.getID();
    PlatformFileBean file = Functions.getDocument(doc_id);

    // Additional business logic...
}