Difference between revisions of "GenerateDocument"

From AgileApps Support Wiki
imported>Aeric
 
imported>Aeric
 
(31 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{DISPLAYTITLE:generateDocument}}
{{DISPLAYTITLE:generateDocument}}
:<tt>Functions.generateDocument(String objectId, String recordId, String templateId, String format)</tt>
Generates a document based on an HTML [[Create an HTML Document Template|Document Template]].
 
:Generates document of <tt>templateId</tt> evaluated with <tt>params</tt> in the format.
 
:If the format is PDF, it generates the document in PDF format, otherwise HTML format. It relates this generated document to the object of type <tt>objectId</tt> and record identifier <tt>recordId</tt>.
 
Generates a document based on a [[Print Templates|Print Template]].


'''Syntax'''
'''Syntax'''
 
:<syntaxhighlight lang="java" enclose="div">
<pre>Result result = Functions.generateDocument(String objectID, String recordID, String printTemplateID, String format)</pre>
Result result;
result = Functions.generateDocument(String object, String recordID,  
                                    String templateID, String format);
</syntaxhighlight>


'''Parameters'''
'''Parameters'''
:;objectID:The identifier of the related object
:;object:The name or identifier of the object that contains the record of interest.
:;recordID:The identifier of the related record
:;recordID:The identifier of the record to pass to the template.
:;printTemplateID:The name of the [[Print Templates|print template]]
:;printTemplate:The identifier of the [[Document Template]].
:;format:You can specify <tt>CONSTANT.DOCUMENT.FORMAT.HTML</tt> or <tt>CONSTANT.DOCUMENT.FORMAT.PDF</tt>
::To get the template ID:
:::* Go to '''[[File:GearIcon.png]] > Objects > {object} > Document Templates'''
:::* Click the Wrench icon to edit the view or create a new one
:::* Add the recordID field to the view
:::* In the listing, find the ID of the Document Template you'll be using
:;format:<tt>CONSTANTS.DOCUMENT.HTML</tt> -or- <tt>CONSTANTS.DOCUMENT.PDF</tt>
::This option applies to HTML and PDF templates. Word templates always produce Word files. PowerPoint templates produce PowerPoint files.


'''Return'''
'''Return'''
:[[Result Class|<tt>Result</tt> object]]


[[Result Class|<tt>Result</tt> object]]
;Usage:
::* Get the object name from the [[Object Properties]]
::* Get the template name from the [[Document Template]]
::* Get the record ID from the [[incoming parameters]]
::* Use <tt>result.getID()</tt> to retrieve the document ID
::* Pass it to the [[getDocument]] 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.


:{| border="0" cellpadding="5" cellspacing="0"
:<syntaxhighlight lang="java" enclose="div">
|
String printTemplate = "";     // Code this value
<syntaxhighlight lang="java" enclose="div">
String recordID = "";         // Get this value from incoming parameters
String printTemplateID = "";
  ...
String leadID = "";
Result result = Functions.generateDocument("cases", recordID, printTemplate, CONSTANTS.DOCUMENT.HTML);
// Some code to populate printTemplateID.
// Some code to populate leadID.
Result result = Functions.generateDocument("LEAD", leadID, printTemplateID, CONSTANT.FILE.FORMAT.HTML);
int resultCode = result.getCode();
int resultCode = result.getCode();
if(resultCode < 0)
if(resultCode < 0)
{
{
     String msg = "Some Message";
     String msg = "Some Message";
     Functions.debug(msg + ":\n" + result.getMessage()); // Log details
     Logger.info(msg + ":\n" + result.getMessage(), "Doc"); // Log details
     Functions.throwError(msg + ".");                     // Error dialog
     Functions.throwError(msg + ".");                       // Error message
}
}
else
else
{
{
     // Some business logic.
    String doc_id = result.getID();
    PlatformFileBean file = Functions.getDocument(doc_id);
 
     // Additional business logic...
}
}
</syntaxhighlight>
</syntaxhighlight>
|}
<noinclude>


<noinclude>[[Category:Email and Document Management]]</noinclude>
[[Category:Java API]]
</noinclude>

Latest revision as of 22:46, 26 June 2014

Generates a document based on an HTML Document Template.

Syntax

<syntaxhighlight lang="java" enclose="div">

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

                                   String templateID, String format);

</syntaxhighlight>

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 identifier of the Document Template.
To get the template ID:
  • Go to GearIcon.png > Objects > {object} > Document Templates
  • Click the Wrench icon to edit the view or create a new one
  • Add the recordID field to the view
  • In the listing, find the ID of the Document Template you'll be using
format
CONSTANTS.DOCUMENT.HTML -or- CONSTANTS.DOCUMENT.PDF
This option applies to HTML and PDF templates. Word templates always produce Word files. PowerPoint templates produce PowerPoint files.

Return

Result object
Usage
Example
This example calls generateDocument on a case to create an HTML document.
<syntaxhighlight lang="java" enclose="div">

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...

} </syntaxhighlight>