Share variable across templates


There might be a scenario where you want to share a variable value across templates within a document specification. This is not supported directly using RPE template variable. However this could be achieved using Java system variable.

Note: Once the Java system variable is set, the variable value is available during future document generation until RPE Launcher / Studio is restarted. Hence, make sure to reset such variable value at the beginning of the template to avoid unnecessary results.

During concurrent document generation, if same variable name is used, it could result in inconsistent value. Hence, create a very unique variable name for using across document specifications. You could log (using _sessionLogger) the variable value before using them for printing.Set the variable “myVar” to a value in template 1.

java.lang.System.setProperty(“myVar”, “Setting the variable value in Template 1”);

setVariableTemplate_1

Read variable value in template 2

java.lang.System.getProperty(“myVar”);

readVariableTemplate_2

Create a document specification that includes template 1 first and then template 2. Generating the document will print the following.

Some text

Read value set in template 1: Setting the variable value in Template 1

Advertisements

Author: Kumaraswamy M

Kumar is an architect for Rational Publishing Engine. He has been with the product for more than 4 years and has been involved in many releases of RPE. His expertise are in Web application development and API design. He loves going on a long ride on bike and conquering peaks during weekend treks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s