Update Category Tray Filter of Matrix Based off the Mouse Click Selection In Another

4.53K viewsScripting
0

Hello,

I suppose this may be rather straight forward, but I’m having troubles as I am new to scripting in Quantrix.

I have the following 2 matricies. MarketingSpecificSpend…. and EventForecastMonthlyForecast. They share the linked category EventID. I want to make a selection with my mouse in MarketingSpecificSpend…Matrix and have it change the Filter Tray for Event ID in the EventForecastMonthlyForecastMatrix, make sense. So in the screen shot I would want EventForecastMonthlyForecast to show EventID “Event1” because that is what I have selected in MarketingSpecificSpend_InputAssumptions. I know there is a way to do it if EventID is also brought into the filter tray of the MarketingSpecificSpend…Matrix, but I really don’t want to do that.
[img:2wiu0fca]http://i1374.photobucket.com/albums/ag417/elderrichardlopez/ScriptQuestion1_zps3f40b639.png[/img:2wiu0fca]

I think I know the scripting code to change the filter tray value, I’m running into troubles on how to identify what EventID is selected in MarketingSpecificSpend_InputAssumptions. In VBA this would be much like the activecell functionality.

Any thoughts?

0

Ben,

Option 2 works for me. In the meantime I had created a work around using a filter column in the header data. This was then married to the details matrix and a filter applied to only show those records that are indicated as “YES” in the header filter column. See the attache model example.

This isn’t script based nor is it automatic as it still requires manual entry. One advantage of using this method in this particular instance over what you suggested is that if I want to view multiple items in the details I can do so.

Many thanks for the insight and solution.

0

Hi,

One thing to note is that Quantrix scripting doesn’t have an event model, which may impact the usefulness of a script like this. My guess is you would want the filter to update automatically in response to selection, which would require events. What you CAN do, though it’s not as glamorous, is assign a hotkey to the script and trigger it manually on selection. I don’t know whether this would satisfy your use case or not.

Regarding how to write the script itself:

The way you would intuitively approach this would be to query the [font=”Courier New”]model.selectedGroupsOrItems[/font] property, which retrieves the groups and/or items currently selected in the UI. Frustratingly, however, [font=”Courier New”]GroupOrItemSelection[/font] (the type of this property) cannot list what items it contains. If it could, this script would be trivial.

In response to this post (and other cases where we’ve encountered this limitation), we have logged an issue against Modeler aimed at exposing the items in a [font=”Courier New”]GroupOrItemSelection[/font].

Meanwhile, we need a workaround. I can think of two:

[list=1:33frbni3]
[*:33frbni3] [font=”Courier New”]GroupOrItemSelection[/font] has a predictable string representation, so one option is to call [font=”Courier New”]toString()[/font] on the value of [font=”Courier New”]selectedGroupsOrItems[/font], then match that result against the items in the filter category to determine which one to select. As it turns out, this is kind of a pain. You need to correctly parse the item name out of the selection string, which also includes other things like the current matrix, a range if more than one item is selected, etc. There are a lot of edge cases and correctly parsing all possible selection strings is nontrivial. We ultimately settled on a heuristic approach, in which you come from the other direction: iterate over the items in the filter category and see if the selection string contains one of them as a substring. Note that this is still not perfect: if you have certain redundancies in your item names, you can get false matches. I think the next solution is better, but included this one in the discussion for completeness.[/*:m:33frbni3]
[*:33frbni3] You can call [font=”Courier New”]group()[/font] on the selection, which returns a [font=”Courier New”]Group[/font] object. The [font=”Courier New”]Group[/font] [i:33frbni3]can[/i:33frbni3] tell you its items, so the approach here is to make a temporary group, ask it for its first item, and then dissolve it. At first I didn’t like this because I thought it would cause awkward UI flicker. On a small model, however, it runs so fast that I didn’t notice any. This could change for a larger, more complex model. The big advantage of this approach is that it’s dead accurate with respect to finding the selected item. The drawback is the potential for flicker. [/*:m:33frbni3][/list:o:33frbni3]

I’ve attached a model that demonstrates both methods. Let me know if you have additional questions.

-Ben

Latest Questions

Wrap text in scripted buttons? 1 Answer | 0 Votes
Claculate product 2 Answers | 0 Votes
Sum by group in the same matrix 4 Answers | 0 Votes
Constrain input – varchar 1 Answer | 0 Votes