Akash Sharma Akash Sharma - 1 month ago 44
Python Question

Python Scripting in TIBCO Spotfire to show custom Messages

I am loading a data table on demand and have linked it to markings in a previous tab. The Data table look like:

ID Values
1 365
2 65
3 32
3 125
4 74
5 98
6 107


I want to limit the data that is brought into this new visualization based on distinct count of ID.

I am currently doing it using
"Limit Data by Expression" section in the properties.
Where my expression is

UniqueCount(ID) <= 1000


This works perfectly, however, I'd also like it to display a message like
"Too many IDs selected. Max Limit is 1000"

I was thinking of doing this using a property control where the property control triggers an iron python script. Any suggestions on how to write that script ?

Answer

One work-around would be use of a small Text Area on the page (perhaps as a header). You can Insert Dynamic Item -> Calculated Value or Icon and have it perform a count or unique count based on marking (selection). For example, once the Count(ID) is > 1000, the text can change to red, or the icon can change color. This is a processing-light alternative which won't necessarily create a pop-up, but can still provide instant notification to a user that too many rows have been selected.

Edit below:

<!-- Invisible span to contain a copy of your value -->
<span style="display:none;" id="stores-my-count"><span id="seek-ender"></span></span>


\\Javascript below to grab dynamic item element's value and put it into a span
\\To be executed every time the dynamic value changes
$("#DynamicItemSpotfireID").onchange = function() {
  var myCount = $("#DynamicItemSpotfireID").text();
  $("#stores-my-count").append(myCount);
}

#IronPython script to locate the value placed into the span by the JS above
#and put only that portion of the page's HTML (only the value) into a document property
parentSpan = '<span id="stores-my-count">'
endingSpan = '<span id="seek-ender">'
startingHTML = myTextArea.As[VisualContent]().HtmlContent
startVal = startingHTML.find(parentSpan, startingIndex, endingIndex) + len(parentSpan)
endVal = startingHTML.find(endingSpan, startingIndex, endingIndex)
Document.Properties["myMarkingCount"] = startingHTML[startVal:endVal]

I haven't tested most of this code and I provide it as a place to start thinking about the problem, rather than a turnkey solution. Hopefully it works with only minor tweaking necessary.