Difference between revisions of "Document Template Classes"

From AgileApps Support Wiki
imported>Aeric
imported>Aeric
Line 2: Line 2:


===About Print Template Classes===
===About Print Template Classes===
As far as a [[Print Template]] is concerned, a data object is simply a HashMap in the [{{DOCHOST}}/javadocs/com/platform/api/TenantContext.html TenantContext]. By manipulating the HashMap(s) it contains, you change the data that the Print Template has available for processing.
As far as a [[Print Template]] is concerned, a data object is simply a HashMap in the [{{DOCHOST}}/javadocs/com/platform/api/TemplateContext.html TemplateContext]. By manipulating the HashMap(s) it contains, you change the data that the Print Template has available for processing.


:* Template reference: $''objectName''.''fieldname''
:* Template reference: $''objectName''.''fieldname''
:* Retrieve a data object: TenantContext.get(''objectName'')
:* Retrieve a data object: TemplateContext.get(''objectName'')
:* Add or update a data object: TenantContext.put(''objectName'')
:* Add or update a data object: TemplateContext.put(''objectName'')
:* Get a field from data object:
:* Get a field from data object:
:* Add or update a field in a data object:  
:* Add or update a field in a data object:  


===Configuring a Print Template to use a Specified Class and Method===
===Configuring a Print Template to use a Specified Class and Method===
Line 15: Line 14:


Methods that take following arguments are listed:
Methods that take following arguments are listed:
:* [{{DOCHOST}}/javadocs/com/platform/api/TenantContext.html com.platform.api.TenantContext] - The container that the print template gets its data from.
:* [{{DOCHOST}}/javadocs/com/platform/api/TemplateContext.html 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 (objectName) - The name of the object the print template was invoked on.  
:* String (recordID) - The ID of the record on which it was invoked.
:* String (recordID) - The ID of the record on which it was invoked.


{{TBD|objectName is passed in, yes? Does return value have to be void}}
{{TBD|TemplateContext is in new javadocs, yes? objectName is passed in, yes? Does return value have to be void?}}


===Accessing Lookup Target Records===
===Accessing Lookup Target Records===
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 = TenantContext.get("Order")</tt> gets the Order HashMap from the TenantContext.  
# <tt>HashMap orderMap = TemplateContext.get("Order")</tt> gets the Order HashMap from the context.  
# <tt>HashMap customerMap = orderMap.get("customer")</tt> gets the lookup-target record for the customer field.
# <tt>HashMap customerMap = orderMap.get("customer")</tt> gets the lookup-target record for the customer field.
# <tt>String name = customerMap.get("name")</tt> gets the customer's name.
# <tt>String name = customerMap.get("name")</tt> gets the customer's name.


===Examples===
===Examples===
====Changing Field Data====
====Changing Field Data====
:<syntaxhighlight lang="java" enclose="div">
</syntaxhighlight>


====Example: Adding a New Field====
====Example: Adding a New Field====
:<syntaxhighlight lang="java" enclose="div">
</syntaxhighlight>


====Example: Adding a New Object====
====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>

Revision as of 21:19, 5 April 2012

This page is currently in progress...

About Print Template Classes

As far as a Print Template is concerned, a data object is simply a HashMap in the TemplateContext. 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)
  • Get a field from data object:
  • Add or update a field in a data object:

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

Data from lookup-target records is stored as a nested map. So to get data for the template variable $Order.customer.name:

  1. HashMap orderMap = TemplateContext.get("Order") gets the Order HashMap from the context.
  2. HashMap customerMap = orderMap.get("customer") gets the lookup-target record for the customer field.
  3. String name = customerMap.get("name") gets the customer's name.

Examples

Changing Field Data

Example: Adding a New Field

Example: Adding a New Object

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);