Manipulating Extended Properties by Script

You can dynamically get and set objects extended properties like attributes and collections using scripts.

The syntax for identifying any object property is:

"<TargetCode>.<PropertyName>"

For example, to get the extended attribute MyAttribute from the importXXX object, use:

GetExtendedAttribute("importXXX.MyAttribute")

Note that if the script is inside a profile (for example, in a custom check script), you can use the %CurrentTargetCode% variable instead of a hard-coded TargetCode, in order to improve the portability of your script.

For example:

GetExtendedAttribute("%CurrentTargetCode%.MyAttribute")

In the following example we:

Example

If (not ExistingModel Is Nothing) and (not FoundClass Is Nothing) Then
 ' Modify extended attribute on the class
 Dim ExaName 
 ExaName = "importXXX.MyAttribute"  ' attribute name prefixed by extension code
 If FoundClass.HasExtendedAttribute(ExaName) Then
  output "Extended attribute can be accessed" 
  FoundClass.SetExtendedAttributeText ExaName, "1024"
  FoundClass.SetExtendedAttribute ExaName, 2048
  Dim valAsText, valAsInt
  valAsText = FoundClass.GetExtendedAttributeText(ExaName)
  valAsInt = FoundClass.GetExtendedAttribute(ExaName)
 End If
 ' Modify extended collection on the class
 Dim ExColName, ExCol
 ExColName = "importXXX.MyCollection"  ' collection name prefixed by extension code
 Set ExCol = FoundClass.GetExtendedCollection(ExColName)
 If not ExCol is Nothing Then
  output "Extended collection can be accessed" 
  ' The extended collection can be used as a standard collection
  ' for example, we add the class in its own extended collection
  ExCol.Add FoundClass
  Set ExCol = Nothing
 End If
End If