Creating Property Control Groups that do not automatically update Expressions and Calculations


In certain scenarios, there is a requirement to have multiple Property Controls that drive a given analysis file. The values behind these Property Controls will all be used in a series of expressions and calculations.  However, the way these expressions and calculations works means that they will be recalculated each time the property values change.  This is OK in some situations, but in many scenarios you want to trigger the update after all Property Control values have been updated (or at least allow the user to define when to update).

This can be accomplished by making two sets of properties: the first set will be attached to the Property Controls in the User Interface and the second will be attached to the expressions and calculations. We then use a Script Control to allow the user to click on a button, and pass the values from the UI properties to the properties which are driving the expression. This would create a flow similar to a user filling out and submitting a form on a Web page. Once the Script is executed, the expressions and calculations are updated. 

To highlight this use case, we will use the Spotfire Educational Services online Training Needs Assessment calculator.  This calculator can be found at  http://spottrain.tibco.com/SpotfireWeb/ViewAnalysis.aspx?file=kevin/TNA

The calculator uses a series of Property Controls to query the user about the number of users they have for each role. 

    

We then use a calculation which takes into account all the values from the first page to calculate the total number of passports a customer should purchase to cover their training needs. 

The expression used for the calculation is shown below:

case [Role]
when "Administrator" then ([Pathway Days]*${
intNbrAdminsUI})
when "DBA" then ([Pathway Days]*${i
ntNbrDbasUI})
when "Developer Basic" then ([Pathway Days]*${intNbrBasicDevsUI})
when "Developer Advanced" then ([Pathway Days]*${intNbrAdvDevsUI})
when "Analyst" then if ("${nbrNeedExpressions}"="Yes",(([Pathway Days]+1)*${intNbrAnalystsUI}), (([Pathway Days])*${intNbrAnalystsUI}))
when "Author" then ([Pathway Days]*${intNbrAuthorsUI})
when "Business User" then ([Pathway Days]*${intNbrConsumersUI})
else 0
end

All of the variables in the expression above, like ${intNbrAdminsUI}, are attached to the Property Controls on the first page.  The output is then displayed on the second page:

.
    

In this scenario, the expression will re-calculate everytime a user changes a value in one of the Property Controls on the first page. If this was an analysis with a lot of data, this could become inefficient.   A similar issue would happen if the values from the Property Control were not being used in an expression, rather they were being passed to a Data Function to perform calculations outside Spotfire.

 

One solution to have the expression or function only update once is to have the expression use a separate set of properties than what are exposed via the Property Controls.  We then add a Script Control, and have the script go through the properties used in the expression and update them with the values from the properties used in the Property Controls.  The script we used to do this for the Needs Assessment example is shown below:


Document.Properties["intNbrAdminsExpr"] = Document.Properties["intNbrAdminsUI"]

Document.Properties["intNbrDbasExpr"] = Document.Properties["intNbrDbasUI"]

Document.Properties["intNbrConsumersExpr"] = Document.Properties["intNbrConsumersUI"]

Document.Properties["intNbrAnalystsExpr"] = Document.Properties["intNbrAnalystsUI"]

Document.Properties["intNbrAuthorsExpr"] = Document.Properties["intNbrAuthorsUI"]

Document.Properties["intNbrBasicDevsExpr"] = Document.Properties["intNbrBasicDevsUI"]

Document.Properties["intNbrAdvDevsExpr"] = Document.Properties["intNbrAdvDevsUI"]