.set_object, .set_value, and .unset Macros

These macros are used to define a local variable of object (local object) or value type or to unset them.

Use the following syntax to create a local object:
.set_object ( [scope.] name [,object-ref [,mode]])
Use the following syntax to create a local variable:
.set_value ( [scope.] name, value [,mode])
Use the following syntax to remove a local object or variable:
.unset ( [scope.] name)

The following parameters are available:

Parameter

Description

scope

[optional] Specifies the qualifying scope. If no scope is set, then the scope is the object with the current scope. Use the this keyword to explicitly give a scope of the current object, or Parent to give a scope of the parent object.

Type: Simple-template returning an object or a collection scope

name

Specifies the name of the object or variable, which you can reference elsewhere in the template in the form of %name%.

Type: Simple-template

object-ref

[.set_object only - optional] Specifies an object reference. If no reference is specified or an empty string is given, the variable is a reference to the active object in the current translation scope.

Type: [scope.]object-scope]

value

[.set_value only] Specifies the value to give to the variable.

Type: Simple template (escape sequences ignored)

mode

[optional] Specifies the mode of creation. You can choose between:
  • new - Forces the (re)-definition of the variable in the current scope. Recommended when a variable with the same name may already be defined in a previous scope.

  • update – [default] If a variable with the same name already exists, update the existing variable. Otherwise define a new one.

  • newifundef - Define the variable in the current scope if it has not been defined in an outer scope. Otherwise do nothing.

Examples:
Examples
.set_object(Attribute1, Attributes.First)
.set_value(FirstAttributeCode, %Attributes.First.Code%)
%FirstAttributeCode% (OID: %Attribute1%)
Result:
a1 (OID: 63442F85-48DF-42C8-92C1-0591F5D34525)
.set_value(this.key, %Code%-%ObjectID%)
Result:
C1-40D8F396-EE29-4B7B-8C78-E5A0C5A23325
.set_value(i, 1, new)
%i?%
.unset(i)
%i?%
Result:
true
false
The first call to %i?% outputs true as the variable i is defined, and the second outputs false, because it has been unset.
Note: You can use the dereferencing operator, * (see GTL Operators), to convert the value of a variable set with the .set_value macro to a template name. For example, the following code is equivalent to %Code%.:
.set_value(i, Code)
%*i%