SETPROPERTY
SETPROPERTY
Saves multiple properties and values in an XML variable. Each property can have a value. To populate a variable, you must use the function as a parameter of an action. For example, in the Create Action dialog, define a Set parameters action. In the Parameters section, select the variable to be populated as the Name, and the define a SETPROPERTY function as the Value. In View Mode, the parameter is populated when the action is triggered.
See XML variables.
The function stores the definition of the variable as XML.
You can use the function to set a single property and value or multiple properties, each with a value. Use it, for example, to populate an XML variable with the values of the slice dimensions in a report. You can also use the function to delete properties and values from a variable.
SETPROPERTY can be used to reference specific elements or can be used to reference hyperblock cells.
To return values from the properties of a variable use GETPROPERTY .
See GETPROPERTY.
These examples are based on the Best Practices Templates database and use properties named Unique and Caption to store the unique name and caption of an element:
Set a single property and value
SETPROPERTY("String xml definition", "[key]", "Property name","Property value")
The first argument of the formula can be an object or string.
The * wildcard character can be used with the key and property arguments to overwrite or delete multiple values simultaneously.
Examples
-
=SETPROPERTY(globalvariables._gv_property,"[Product]","Unique", "[Product].[All Tires].[Car Tires all Season]")
-
=SETPROPERTY(globalvariables._gv_property,reportobjects.Hyperblock4.Text, "Unique","[Product].[All Tires].[Car Tires all Season]")
-
=SETPROPERTY(globalvariables._gv_property,"reportvariables.rv_dimension.text","Unique", "reportvariables.rv_element.text")
In all three examples, the Product dimension is the key and the property name is 'Unique'.
In the first example, the Product dimension and the unique name of a product are specified. In the second example, the name of a hyperblock containing the Product dimension is specified. The third example references report variables which contain a dimension name and an element unique name.
In the XML definition the key forms the row name.
Set multiple properties and values
SETPROPERTY("String xml definition", "[key]", "Property name","Property value","Property name","Property value")
Example
=SETPROPERTY(globalvariables._gv_property,"[Product]","Unique","[Product].[All Tires].[Car Tires all Season]","Caption","Car Tires all Season")
Multiple keys
=SETPROPERTY(SETPROPERTY("String xml definition","Key1","Property1","Value1"), "Key2","Property2","Value2")
Each key forms a row in the XML definition of the variable.
Or, use multiple SETPROPERTY formulas in multiple actions to populate a single XML variable - for example to store the filter dimensions in a dynamic report.
Delete a single property
SETPROPERTY("String xml definition", "[Key]", "Property name","")
Example
This deletes the "Caption" property from a variable that stores the unique name and caption of an element of the Product dimension.
=SETPROPERTY(globalvariables._gv_property,"[Product]","Caption","")
Delete multiple properties
SETPROPERTY("String xml definition","[Key]","Property name","","Property name,"")
Delete all properties of a row
SETPROPERTY("String xml definition","[Key]")
SETPROPERTY in hyperblocks
The SETPROPERTY function can reference hyperblock cells. When used with hyperblocks, it is possible to define these combinations of keys, properties and values in an XML variable:
- One key with multiple property/value pairs
- Multiple keys with one property/value pair
- Multiple keys with multiple property/value pairs
- Multiple keys with multiple properties and one value
Examples
These examples use a vertical hyperblock in cells B2, B3 and B4 and a global variable called gv_SetProperty.
One key with multiple property/value pairs:
=SETPROPERTY(globalvariables.gv_setproperty,"[Product]",B3,B4)
Multiple keys with one property/value pair:
=SETPROPERTY(globalvariables.gv_setproperty,B2,"Property","Value")
Multiple keys with multiple property/value pairs:
=SETPROPERTY(globalvariables.gv_setproperty,B2,B3,B4)
Multiple keys with multiple properties and one value:
=SETPROPERTY(globalvariables.gv_setproperty,B2,B3,"Value")
Editing and deleting properties and values
When SETPROPERTY is used to reference hyperblock cells, these actions are possible:
- Delete a row from the XML definition
- Delete a single value
- Delete multiple properties
- Update or set a single value
- Update or set multiple values
Examples
Delete a row from the XML definition:
=SETPROPERTY(globalvariables.gv_setproperty,"Key")
Delete a single value:
=SETPROPERTY(globalvariables.gv_setproperty,"Key","")
=SETPROPERTY("String xml definition","Key","Property1","","Property3","")
Set a single value:
=SETPROPERTY("String xml
definition","Key","Property","Value")
Set multiple values:
=SETPROPERTY("String xml definition","Key","Property1","Value1","Property2", "Value2","Property3","Value3")
Change multiple values with wildcard on key:
<Table><Row name="Key1"><Property name="property" value ="Value1" /></Row> <Row name="Key2"><Property name="property" value ="Value2" /></Row></Table>To change both Value1 and Value2 to NewValue:
=SETPROPERTY("String xml definition"," Key*
","Property","NewValue")
The wildcard identifies both keys and the formula changes both their values.
Change multiple values with wildcard on property:
<Table><Row name="Key1"><Property name="property1" value ="Value1"/> <Property name="property2" value ="Value11"/></Row> <Row name="Key2"><Property name="property1" value ="Value2" /> <Property name="property2" value ="Value21"/></Row></Table>
To change the value of Property1 and Property2 of Key1 use:
=SETPROPERTY("String xml
definition","Key1","Property*","NewValue")
The wildcard identifies both Property1 and Property2 of Key1.
To change the properties of both keys, use a wildcard on both key and property:
=SETPROPERTY("String xml definition"
,"Key*","Property*","NewValue")