Developer Documentation Library > Data Model > Accessing the UNICOM Intelligence Data Model > Working with the Metadata Model > Working with the Metadata Model: Tutorial > Creating and reading custom properties
 
Creating and reading custom properties
The MDM allows you to create your own MDM custom properties and associate these properties with almost any MDM object. A custom property consists of a name and an associated value (the value of a property is of type variant). Custom properties persist, which means that a custom property is not lost when the MDM Document is read, updated, and written by other applications.
Custom properties make use of the same Contexts collection as the Label object. That is, you can set and retrieve different values for the same property by supplying an optional user context. If no user context is specified the current user context is assumed.
This mrScriptBasic example adds to the Document object a custom property named MyProperty with a value of MyValue:
MyDocument.Properties.Item["MyProperty"] = "MyValue"
Because a property's value is of type variant, you can replace MyValue with a number, say 10.
MyDocument.Properties.Item["MyProperty"] = 10
You can also specify the user context when setting or reading a custom property. To specify the user context as Question, write the code as:
MyDocument.Properties.Item["MyProperty"]["Question"] = 10
Similar examples in VB.NET are:
MyDocument.Properties("MyProperty") = "MyValue"
MyDocument.Properties("MyProperty") = 10
MyDocument.Properties("MyProperty", "Question") = 10
Reading a property is straightforward, as shown in this example:
Dim GetPropertyValue

' Specifying the Context is optional
GetPropertyValue = MyDocument.Properties.Item["MyProperty"]["Question"]
You remove a property by calling Remove. For example:
MyDocument.Properties.Remove("MyProperty", "Question")
You can add custom properties to most MDM objects. For example, to add a custom property of XPos, with a value of 450 to the Variable Age:
MyDocument.Variables["Age"].Properties.Item["XPos"] = 450
Similar examples in VB.NET are:
Dim GetPropertyValue As String

' Specifying the Context is optional
GetPropertyValue = CStr(MyDocument.Properties("MyProperty", "Question"))
MyDocument.Properties.Remove("MyProperty", "Question")
MyDocument.Variables("Age").Properties("XPos") = 450
Requirements
See Requirements.
More on custom properties
MDM custom properties
Next topic
Introduction to versions
See also
Working with the Metadata Model: Tutorial
Creating and saving a variable