- Are you using on-demand queries that take a long time to load?
- Are you worried users will tie up their machines if queries run automatically anytime the trigger is pulled?
- Would you like to be able to trigger those queries with a button instead?
In previous posts, I’ve hinted I’m working on a large project merging several data sets. Well, I’m still working on that project, and as I was reviewing it today, I realized Data Shop Talk readers might be interested in using IronPython to trigger on-demand queries with a button. Let’s look at my use case to understand this a little better.
A header data table populates a map with well locations. Users mark the map to choose which wells they want to query production data for. The marking triggers on-demand queries of three different production data sets.
These on-demand queries take a few minutes to execute. If the queries actually trigger every time the user pokes at the map, it ties up their machine while the query executes, and they might not be ready for the query to execute. I would much rather have the user click a button to trigger the query when they are ready.
This is easy to do with a simple IronPython script. Note, in the code snippet below, I am actually triggering the update of three different tables. Here’s how you do it.
- Add a text area to the page
- Toggle the text area into edit mode
- Add an action control button
- Name the button something like “Update On Demand tables”
- Click the Script button
- Click New
- Name the script
- Copy and paste the script from below. Use the screenshot as a guide in case the copy/paste operation corrupts the spacing
- Add the parameters
- Connect the parameters to the table(s)
- Run the script to make sure there are no errors
- Click ok until you are out.
if Table.IsRefreshable and Table.NeedsRefresh:
if Table1.IsRefreshable and Table1.NeedsRefresh:
if Table2.IsRefreshable and Table2.NeedsRefresh:
Lastly, make sure the on-demand query is set up NOT to refresh automatically, which would look something like this.
Content developed with Spotfire version 7.9.1.