Difference between revisions of "Document Template Classes"
imported>Aeric |
imported>Aeric |
||
Line 13: | Line 13: | ||
:* Add or update a field in a data object: <tt>HashMap.put("''fieldName''",''value'');</tt><br>where <tt>''value''</tt> is typically a string or a nested HashMap. | :* Add or update a field in a data object: <tt>HashMap.put("''fieldName''",''value'');</tt><br>where <tt>''value''</tt> is typically a string or a nested HashMap. | ||
The keys for the standard HashMaps that a TemplateContext contains are: | |||
:* <tt>createdUsr</tt> - The [[User]] object for the person who created the record. | |||
:* <tt>modifiedUsr</tt> - The [[User]] object for the person who most recently modified the record. | |||
{{TBD|What are the other standard objects?}} | {{TBD|What are the other standard objects?}} | ||
Line 27: | Line 30: | ||
===Accessing Lookup Target Records=== | ===Accessing Lookup Target Records=== | ||
{{TBD|Is nested data stored like this?}} | |||
Data from lookup-target records is stored as a nested map. So to get data for the template variable <tt>$Order.customer.name</tt>: | Data from lookup-target records is stored as a nested map. So to get data for the template variable <tt>$Order.customer.name</tt>: | ||
# <tt>HashMap orderMap = TemplateContext.get("Order")</tt> gets the Order HashMap from the context. | # <tt>HashMap orderMap = TemplateContext.get("Order")</tt> gets the Order HashMap from the context. |
Revision as of 21:30, 5 April 2012
This page is currently in progress...
About Print Template Classes
You can use a method in a Print Template Class to manipulate the data that a Print Template has available for processing. Here's how it works:
- When a Print Template is processed, it gets its data from the TemplateContext
- That object contains a HashMap for each kind of record that , a data object is simply a HashMap in the . The TemplateContext object is passed to a method in your data-handler so, by manipulating the HashMap(s) it contains, you change the data that the Print Template has available for processing.
- Template reference: $objectName.fieldname
- Retrieve a data object: TemplateContext.get("objectName");
- Add or update a data object: TemplateContext.put("objectName", HashMap);
- Get a field from data object: HashMap.get("fieldName");
- Add or update a field in a data object: HashMap.put("fieldName",value);
where value is typically a string or a nested HashMap.
The keys for the standard HashMaps that a TemplateContext contains are:
__TBD: What are the other standard objects?__
Configuring a Print Template to use a Specified Class and Method
- --select the class, and the method to use
Methods that take following arguments are listed:
- com.platform.api.TemplateContext - The container that the print template gets its data from.
- String (objectName) - The name of the object the print template was invoked on.
- String (recordID) - The ID of the record on which it was invoked.
__TBD: TemplateContext is in new javadocs, yes? objectName is passed in, yes? Does return value have to be void?__
Accessing Lookup Target Records
__TBD: Is nested data stored like this?__ Data from lookup-target records is stored as a nested map. So to get data for the template variable $Order.customer.name:
- HashMap orderMap = TemplateContext.get("Order") gets the Order HashMap from the context.
- HashMap customerMap = orderMap.get("customer") gets the lookup-target record for the customer field.
- String name = customerMap.get("name") gets the customer's name.
Examples
Changing Field Data
- <syntaxhighlight lang="java" enclose="div">
</syntaxhighlight>
Example: Adding a New Field
- <syntaxhighlight lang="java" enclose="div">
</syntaxhighlight>
Example: Adding a New Object
- <syntaxhighlight lang="java" enclose="div">
public void processTemplate(TemplateContext context, String objectName,String recordId)
HashMap<String, Object> map = new HashMap<String, Object>(); map.put("CompanyName", "Tulip"); map.put("Phone", "408-230-0987"); context.put("Company",map); </syntaxhighlight>