Python Scripting in TIBCO Spotfire to show custom Messages
<p>I am loading a data table on demand and have linked it to markings in a previous tab. The Data table look like:</p>

<pre><code>  ID        Values
  1         365
  2         65
  3         32
  3         125
  4         74
  5         98
  6         107
</code></pre>

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

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

<pre><code>UniqueCount(ID) &lt;= 1000
</code></pre>

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

<p>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 ?</p>

<p>One work-around would be use of a small Text Area on the page (perhaps as a header).  You can <code>Insert Dynamic Item</code> -> 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.</p>

<p>Edit below:</p>

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


\\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 = '&lt;span id="stores-my-count"&gt;'
endingSpan = '&lt;span id="seek-ender"&gt;'
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]
</code></pre>

<p>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.</p>

python visualization data-visualization ironpython spotfire