Specialized Administration > Tailoring Business Objects > Object Initialization Rules Administration > Working with Object Initialization Rules > Specifying Rules > VarDef Tag Syntax
  
VarDef Tag Syntax
An XML document used for a rule can contain one or more VarDef tags. Always nest the VarDef tag within an AttributeValues tag.
Each VarDef tag defines a variable name and its value that can then be referenced in rules using the VarRef tag. The variable definitions that are available when you are referencing a variable (using the VarRef tag) are determined by the object type and the context hierarchies that are in place. For the details about how rules use these hierarchies, see Merging Rules to Create a Composite Rule.
As an example, assume that you defined a variable in the site context that can be used in rules defined for the wt.doc.WTDocument object type. Then this definition is available in all contexts for the rules defined for the wt.doc.WTDocument object type and all of its subtypes. The definition of the same variable in a child context of the site or associated with a subtype of wt.doc.WTDocument would generally take precedence over the definition in the site context if the object to which the rules were being applied was either in the child context or was associated with a subtype.
The value for a variable is not calculated until a rule element is processed that references the variable. To reference a specific variable that is defined through the VarDef tag, use the value that is specified in the id attribute of VarDef tag in the id attribute of the VarRef tag. The first element processed a when rule is being applied that has a specific variable reference causes the value of the variable to be calculated and cached. Then the cached value is used for every reference to the variable that is processed during the rule application.
The VarDef tag syntax is as follows:
<VarDef id="variable_name"
algorithm="default_value_algorithm">
algorithm_arguments
</VarDef>
where variable_name is the name of the variable that is used when referencing the variable in the VarRef tag. The name can consist of any valid XML name that is meaningful to you.
The following example defines the GeneratedNumber variable that can be used to generate a number for documents so that you can set the name of the document to the generated number. You can define this variable for use when creating documents by nesting the XML in the AttributeValues tag for the wt.doc.WTDocument object type:
<VarDef id="GeneratedNumber"
algorithm=”com.ptc.windchill.enterprise.revisionControlled.server.impl.NumberGenerator">
<Arg>{GEN:wt.enterprise.SequenceGenerator:WTDOCUMENTID_seq:10:0}</Arg>
</VarDef>
* 
The value of the variable defined in the VarDef tag cannot be derived from the calculation for another value in the same rule. For example, you cannot define a GeneratedNumber variable for WTPart from the number attribute value which is set by the AttrValue tag in the same rule. For more information, see Variables.
Additionally, you can include optional XML attributes in the VarDef tag to do the following:
Set the variable definition specified as the absolute definition to use in the composite rule.
Ignore the specified definition when the definition is inherited from the parent context.