Writing and saving comments inside a Spotfire Analysis file


Many times, users would like to collaborate with each other in the same Analysis file but don't  have a specific collaboration tool, like TIBBR (http://www.tibbr.com) to use. By leveraging the power of Property Controls and Script Controls, you can create a page on your Analysis file, which allows users to view and share comments ( which works in both the Web Player and Professional client).

First we need to setup an input box to capture the user’s comments. We do this with an ‘Input Field (multiple lines)’ Property Control:


We can also add a descriptive heading above the Input field as shown below:



After that, we need to create a place to store the comments.  For this, we create a Document Property and attach it to  a ‘Label’ Property Control. To maximize real estate , rather than putting the Label Property Control underneath the Input Field Property Control, we leveraged the concepts discussed in an early tip, to place them in a HTML table side by side.
In addition, we were able to style the Label by putting a border around it so its easily visible to the user:


The final step is to create a Script which will take the comments entered by the user in the Input Field Property Control  and save them to the Document Property we just created (which will update the display in the Label Property Control).
Below is the Script.  It assumes the Document Property for the saved comments (attached to the Label) is called savedComments and it assumes the Document Proeprty for the comments the user currently entered (the input field Property Control) is called inputComment
from System import DateTime, Threading
strComments = Document.Properties["savedComments"]
strUserInput = Document.Properties["inputComment"]

# Get the current time ie 09/15/2012 08:17:31
timestamp = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss")

# Get the currently logged in user’s username
username=Threading.Thread.CurrentPrincipal.Identity.Name

# Create the comment lines by appending the timestamp and login username following by the comment on a separateline
commentToAppend = timestamp + " - " + username + "\n" + strUserInput
if strComments == "":
   newLine = ""
else:
   newLine = "\n\n"
strAppendedComments= strComments + newLine + commentToAppend

#Append the comment lines to the savedComments Document Property
Document.Properties["savedComments"] = strAppendedComments

#Clear the Input Field Property Control of the previous input
Document.Properties["inputComment"] = ""

When executed, this script will capture the user's login name, the timestamp, and then the comments and append to the the savedComments Property. If you wish to prepend comments (so the newest show up on top) change the following line in the script:
strAppendedComments= strComments + newLine + commentToAppend
to

strAppendedComments= commentToAppend + strComments + newLine
Since Document Properties are automatically persisted within the Spotfire Analysis file, the comments are saved and stored.


Interested in learning how to build your own solutions like this? Please consider taking our SP232 Automation APis with Iron Python course using our Mentored Online Training delivery model.