Examples: Variable substitution
Examples of variable substitution for resource monitor definitions using XML and MQ Explorer.
Examples showing how variable substitution works
Variable specification | After variable substitution |
---|---|
${FilePath} | c:\MONITOR\REPORTS\Paris\Report2009.doc |
${FilePath{token=1}{separator=.}} | c:\MONITOR\REPORTS\Paris\Report2009 |
${FilePath{token=2}{separator=.}} | doc |
${FilePath{token=3}} | REPORTS |
Variable specification | After variable substitution |
---|---|
${FilePath} | c:\MONITOR\REPORTS\Paris\Report2009.doc |
${FilePath{token=-2}{separator=.}} | c:\MONITOR\REPORTS\Paris\Report2009 |
${FilePath{token=-2}{separator=\}} | Paris |
${FilePath{token=-4}} | MONITOR |
The variables that are used for substitution are only available for positive trigger conditions. Only match and fileSize trigger conditions cause variables to be substituted. If a noMatch condition is used, and there are substitution variable names in the task definition, the task is not called, and the monitor raises a return code of 103 and error message BFGDM0060E.
Example using XML
Paris
), uses the penultimate directory name in the file path as the
destination agent name for the transfer (Report2009), and renames the
transferred file to be the root of the trigger file name with an extension of
.rpt.
<?xml version="1.0" encoding="UTF-8" ?>
<request version="4.00" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="FileTransfer.xsd">
<managedTransfer>
<originator>
<hostName>reportserver.com</hostName>
<userID>USER1</userID>
</originator>
<sourceAgent agent="${AgentName}" QMgr="QM1"/>
<destinationAgent agent="${FilePath{token=-2}}" QMgr="QMD"/>
<transferSet>
<item mode="binary" checksumMethod="MD5">
<source recursive="false" disposition="leave">
<file>c:/incoming/reports/summary/report.doc</file>
</source>
<destination type="file" exist="overwrite">
<file>/reports/${FileName{token=1}{separator=.}}.rpt</file>
</destination>
</item>
</transferSet>
</managedTransfer>
</request>
<?xml version="1.0" encoding="UTF-8" ?>
<request version="4.00" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="FileTransfer.xsd">
<managedTransfer>
<originator>
<hostName>reportserver.com</hostName>
<userID>USER1</userID>
</originator>
<sourceAgent agent="AGENT1" QMgr="QM1"/>
<destinationAgent agent="Paris" QMgr="QMD"/>
<transferSet>
<item mode="binary" checksumMethod="MD5">
<source recursive="false" disposition="leave">
<file>c:/incoming/reports/summary/report.doc</file>
</source>
<destination type="file" exist="overwrite">
<file>/reports/Report2009.rpt</file>
</destination>
</item>
</transferSet>
</managedTransfer>
</request>
The variable ${FilePath{token=-2}}
in the <destinationAgent>
element's agent
attribute is replaced with the value Paris
. This
value is treated in a not case-sensitive way and interpreted as a reference to the agent
PARIS
.
Examples using MQ Explorer
When creating a resource monitor through the MQ Explorer, and once the monitor properties and trigger conditions have been specified, the option is given
to add transfer items to the monitor. The following examples demonstrate how the ${FilePath} and
${FileName} variables can be used in the Add a transfer item panel
to
customize transfers resulting from a resource monitor match.
Example 1
- Set the source File name to be ${FilePath}.
- From the dropdown menu of Type for the destination, select Directory.
- Set the destination File name to be the location to which you wish the source file to be transferred, for example, this could be C:\MFT\out\.
Example 2
In order to transfer the source file to another location and change the extension of the file,
the ${FileName}
variable can be used in conjunction with the
${FilePath}
variable:
- Set the source File name to be ${FilePath}.
- Set the destination File name to be the location to which you wish the source file to be transferred, followed by ${FileName{token=1}{separator=.}}, followed by the new extension of the file. For example, this could be C:\MFT\out\${FileName{token=1}{separator=.}}.rpt, which would equate to C:\MFT\out\Report2009.rpt with the source file name.
Example 3
In order to use part of the file path of the source file to determine the destination of the
transfer, the ${FilePath}
variable can be used in conjunction with token and
separator specifications.
In the following example it is assumed that the file path of the source file is equal to C:\MONITOR\REPORTS\Paris\Report2009.doc.
- Set the source File name to be ${FilePath}.
- Set the destination File name to be the destination to where the folders for each location are situated, and then append the destination part of the file path and the file name. For example, this could be C:\MFT\out\${FilePath{token=-2}{separator=\}}\${FileName}, which would equate to C:\MFT\out\Paris\Report2009.doc with the source file name.