Saving Comments from within the Web Player


In earlier posts, we discussed how you can share annotations with other users of an analysis file.  Most of these solutions required building a mashup using the Spotfire Web Player APIs, and quite a few people asked if there was a way to implement similar functionality without using the Web Player APIs. While there is not a solution that provides all the same functionality as the previous tips, there is a way you can accomplish the saving of comments without using the Web Player APIs. 

First, you need to create something that will store the comments.  The best scenario is to use something that will automatically persist the information for you so you do not have to worry about implementing this. You can do this by using a Document Property. You can expose this property via a multi-line input field Property Control.

Next, using a Script Control, you can create a button which will use the Spotfire Automation APIs to save the file back to its original location in the Spotfire Library. By doing this, it will include the latest value of the property, including any updates made by the user in the Web Player.

The script is actually only one line of code:

Application.Save()

With this solution, it will also save the current state of the analysis file, including the active page, as well as active marking and filtering. This could be the desired effect, or you may want to update your script to reset the file to load the first analysis page the next time the file is opened. If you wish to save the file with the first page in the analysis loading, then add the following line of code in your script before the Application.Save() command:

Document.ActivePageReference = Document.Pages[0]

You can also extend this script to add some more complex functionality like setting the analysis so that no markings or filtering are used. 

When you are done with the Script Control,  users can enter comments in the input field and then they can click the ‘Save File’ button to trigger the script. The next time the file is opened, it will contain the latest contents, including the comments in the property control.

 


 
A variation of this solution would be to have the script take the contents of the property control and append them to a text area in the analysis file, as shown below.


 

One issue with these approaches is that you will not be able to use it if you have anonymous access setup for the Web Player. Using the APIs to save the file will cause an authentication error.  If this is the case, you will need to alter your solution a bit.  Rather than storing the comments in a property, you will need to store the comments in another location, like a text file accessible via URL.  Then, you need to update your script to read the text from the file and then display them in a text area. This way, the analysis file is never altered or re-saved, but the script is just reading in text from an outside source which is saved somewhere. 

Its also important to note that this solution works when saving the original file as itself, but its not possible to use any of the Save As capabilities to store different versions of this analysis file. Trying to use those Automation APIs will cause an error when executed from within the Web Player.