michael kalada Posted May 5, 2016 Share Posted May 5, 2016 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 More sharing options...
Dave Leigh Posted May 5, 2016 Share Posted May 5, 2016 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: https://docs.tibco.com/pub/doc_remote/spotfire/7.0.1/doc/api/html/M_Spot... You would use it something like this: if ( Document.Data.Properties.ContainsProperty (DataPropertyClass.Document, propName ): # Do something else: # 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 More sharing options...
michael kalada Posted May 5, 2016 Author Share Posted May 5, 2016 THANK YOU !!!!!!!!!!!!!!!!!!! If you ever find yourself in Jacksonville Florida let me buy you a drink. Thanks again, Michael T Kalada Mike.kalada@pontoonsolutions.com Link to comment Share on other sites More sharing options...
arthur Boender Posted September 21, 2016 Share Posted September 21, 2016 Thanks Dave, this was exactly what I was looking of, and thanks Mike for asking the question! Link to comment Share on other sites More sharing options...
Michael Kalada 2 Posted March 30, 2020 Share Posted March 30, 2020 an edit 4 years later, Davids snippet is missing an end parenthesisshould be if ( Document.Data.Properties.ContainsProperty ( DataPropertyClass.Document, propName )): # Do something else: # Do something else Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now