Customer Banners (Ads) - SpiceUp. AX and SpotfireX Disclaimer



If you find this site useful and you want to support, buy me a coffee   to keep this site alive and without ads.

Create, Read and Delete Document Properties

from Spotfire.Dxp.Data import DataPropertyRegistry, DataPropertyClass, DataProperty, DataType, DataPropertyAttributes 

# Create a property blueprint
propertyPrototype = DataProperty.CreateCustomPrototype("NewProperty", DataType.Integer, DataPropertyAttributes.IsVisible | DataPropertyAttributes.IsEditable | DataPropertyAttributes.IsPersistent | DataPropertyAttributes.IsPropagated)

# Instantiate the prototype
Document.Data.Properties.AddProperty(DataPropertyClass.Document, propertyPrototype)

# Set property
Document.Properties["NewProperty"] = 10

# Read property
print "NewPrperty value is: " + Document.Properties["NewProperty"]  

# Read a string list property (string array or List box (multiple select))  
selection = Document.Data.Properties.GetProperty(DataPropertyClass.Document, "myStringList").Value
for element in selection: print element

# Check the property's attributes
documentProperty = DataPropertyRegistry.GetProperty(Document.Data.Properties, DataPropertyClass.Document, "NewProperty")

print documentProperty.Attributes

# Delete property
DataPropertyRegistry.RemoveProperty(Document.Data.Properties, DataPropertyClass.Document, "NewProperty")
try:
print Document.Properties["NewProperty"] 
except:
print "NewProperty not found!"


# Delete all properties (cleanup)
# I use this script when using a dxp as a template that has many doc properties that I do not need anymore.
# WARNING: IT WILL REMOVE ALL PROPERTIES
from Spotfire.Dxp.Data import DataPropertyRegistry, DataPropertyClass
for p in Document.Properties:
try:
DataPropertyRegistry.RemoveProperty(Document.Data.Properties, DataPropertyClass.Document, p.Name)
except Exception as e :
print str(e)

No comments: