Difference between revisions of "Java API:Document Management"
imported>Aeric |
imported>Aeric |
||
Line 5: | Line 5: | ||
== getDocument == | == getDocument == | ||
{{:getDocument}} | {{:getDocument}} | ||
== Example: Generate an Attachment == | |||
{{Code:Generate an Attachment}} | |||
<noinclude> | <noinclude> | ||
__FORCETOC__ | __FORCETOC__ |
Revision as of 20:28, 16 January 2014
The Document Management Java APIs are used to generate and manage documents.
generateDocument
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:
- 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
- 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 result.getID() to retrieve the document ID
- Pass it to the getDocument method to get a PlatformFileBean that contains the document
- 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>
getDocument
Retrieves a document specified by its ID.
- Syntax
- <syntaxhighlight lang="java" enclose="div">
Result result = Functions.getDocument(String documentID); </syntaxhighlight>
- Parameters
- documentID - The ID of a document stored in the platform.
- Returns
- Result object that contains the document in the form of a PlatformFileBean.
- Usage
-
- Use result.getParameters() to get the params from the Result object.
- Call getPlatformFileBean() on the params, passing the document ID as a string.
- If needed, call getBytes() on the PlatformFileBean to get document content in a byte array.
- Example
- This example logs the size and name associated with a document.
- <syntaxhighlight lang="java" enclose="div">
Result result = Functions.getDocument(documentId); Parameters params = result.getParameters(); PlatformFileBean file = params.getPlatformFileBean(documentId); byte[] bytes = file.getBytes(); String msg = "Name:"+file.getName()+", size:"+file.getEncodedFileContent().length(); Logger.info(msg, "Document"); </syntaxhighlight>