Declaring and Using Variables

In the previous workflow example the variable “PRICE” was declared and used within the same “flow-control” step. However, it is important to note that variables are available outside the scope of the “flow-control” step where they are declared.

Variables can only be declared in “flow-control” steps and must be declared first in the step. When a variable is declared, the value must be defined or a “from” reference must be specified that identifies where in the job ticket the variable value is to be found. The following “flow-control” step shows the ways in which a variable can be declared.

<flow-control>
<variable name="PRICE" from="stockquote/request[@tag='request1']/price"/>
<variable name="FAIL" from="retrieve/request[@tag='request1]" attr="fail"/>
<variable name="VAR1" type="string">Some value goes here.</variable>
<variable name="VAR2" type="bool">1</variable>
<variable name="VAR3" type="integer">1001</variable>
<variable name="VAR4" from-item="file-path"/>
</flow-control>

The above gives examples of the four ways in which variables can be declared:

  1. The “PRICE” variable will get its value using the “from” option which specifies an Xpath reference to an existing node in the job ticket. The text value of the node will be assigned to the variable.
  2. The “FAIL” variable is similar to “PRICE” but it also uses the “attr” option. An existing node is located using the “from” XPath query but instead of using the node text value the node “fail” attribute value will be used.
  3. Both “VAR2” and “VAR3” are examples of assigning a “hardcoded” value to the variable. In this case the variable should have the “type” attribute. Possible types are “string”, “bool”, “integer” or “double”. If no type is specified then “string” is assumed.
  4. The “VAR4” variable uses the “from-item” option that has not been discussed yet. See the “from-each-item” option described in the Repeating Workflow Tickets section.

As mentioned before, variables do not have to be used within the “flow-control” step that declares them. The following example below shows how variables can be used to assign parameter values using the “from-variable” option (similar to the “from” option), or they can be used in another “flow-control” workflow step.

<workflow>
<retrieve>
<request tag="request1" name="retrieve-rendition">
<URL type="string">file://c:/Dev/Vista/MyDoc1.doc</URL>
<rendition-format>pdf</rendition-format>
</request>
</retrieve>
<flow-control>
<variable name="RENDITIONFOUND"
from="retrieve/request[@tag='request1']/rendition-found"/>
<variable name="RENDITION"
from="retrieve/request[@tag='request1']/local-rendition-path"/>
<if expression="RENDITIONFOUND = 1">
<goto>assemble[@tag='assemble']</goto>
</if
</flow-control>
<retrieve>
<request tag="request2" name="retrieve-document">
<URL type="string" from="retrieve/request[@tag='request1']/URL"/>
</request>
</retrieve>
<render tag="render-pdf">
<request tag="request1" name="render-pdf">
<document-name type="string" from="retrieve/request[@tag='request2']/localpath"/>
<force-rendition type="bool">1</force-rendition>
<local-path type="string" from="retrieve/request[@tag='request2']/localpath"/>
<content-type type="string" from="retrieve/request[@tag='request2']/localpath"
/>
</request>
</render>
<distribute>
<request tag="request1" name="distribute-rendition">
<URL from="retrieve/request[@tag='request1']/URL" />
<local-path type="string" from="render/request[@tag='request1']/localrendition-
path" />
<format type="string">pdf</format>
</request>
</distribute>
<flow-control>
<variable name="RENDITION" from="render/request[@tag='request1']/localrendition-
path" />
</flow-control>
<assemble tag="assemble">
<request tag="request1" name="assemble-pdf">
<output path type="string">c:\vista-test\assembledoutput.pdf</output-path>
<source-documents type="xml" resolve-from="1">
<documents>
<source-document from-variable="RENDITION"/>
</documents>
</source-documents>
</request>
</assemble>
</workflow>