Possible to change State Group with Script

Hi Dundas Community,

Does anyone know of a way to change the state group that is being used via a script? The use case one of the plants want is to be able to grade the same underlying data based on two sets of targets (which they want to change with a button or filter).

I looked for a method in the script documentation, but it only let’s you add or remove:

image

For reference, state 1:


and state 2:

Hi,

The methods you found seem to be from our .NET API and are for changing the definitions of the states themselves on a metric set. (States are part of the metric set so that they can be reused in different visualizations.) You can set up more than one state group through the UI so I wouldn’t think these methods are necessary, it’s just that for gauges, only one state group can be shown as ranges at one time.

If you’ve already set up two state groups and want to switch between them using script like you can with the Range State Group dropdown in your screenshot, this dropdown is in the Properties window for your gauge, and there is an equivalent property on gauges in the JavaScript API: Gauge.stateGroupId Property (dundas.com) You would need to set it to the state group ID from the metric set, which is available through script - for example:
gauge.stateGroupId = gauge.metricSetBindings[0].dataResult.metricSet.stateGroups[0].id

Just mentioning that you could do something similar using formulas with parameters instead, setting up states to compare your data against the formulas. Each formula could take input directly from the user via a connected numeric filter, or else use some logic in the formula script to determine the values.

Thanks Jamie, I will try the proposed.