Jump to content

python script to create a document property IF that property doesn't already exist

michael kalada

Recommended Posts

Hi All,

We have the belowscript that creates and populates doc properties and it works great. But Ineed it to check if the document property already exists before it runs. Tried to get it to work with an if statement but no luck. Any help would be greatly appreciated


from Spotfire.Dxp.Data import DataProperty

from Spotfire.Dxp.Data import DataType

from Spotfire.Dxp.Data import DataPropertyClass

propName = "myDocumentProperty2"

attr = DataProperty.DefaultAttributes

prop = DataProperty.CreateCustomPrototype(propName, DataType.String, attr)

Document.Data.Properties.AddProperty(DataPropertyClass.Document, prop) prop.Value = "myDocumentPropertyValue"


script isfromhttps://easyspotfire.blogspot.com/2014/04/create-document-property-and-s...

Link to comment
Share on other sites

You said that you had tried an "if" statement. Did you try the "ContainsPropery" method on the Document.Data.Properties collection which is a DataRegistry object

You can find the documentation for this method here:


You would use it something like this:

if ( Document.Data.Properties.ContainsProperty (DataPropertyClass.Document, propName ):

# Do something


# Do something else

However, one word of caution. IronPython code blocks run inside a transaction, so if you are planning on using this across multiple threads of execution, say for multiple users within web player, then the document property will not be visible to other threads until the thread that creates it completes.

In other words, if you run it in parrallel for multuple users they will all believe that the property does not exist and will try to create it.

Spotfire 7.5 provides an option to run an IronPython script without a transaction. This was added to address these kind of situations. If you are running Spotfire 7.0 or earlier, you will not have this option.

Link to comment
Share on other sites

  • 4 months later...
  • 3 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...