Jump to content

Error Reading Checked Values in Check Box Filter using IronPython Script


Marcus Cowan

Recommended Posts

Hello,

Using a Python script, I am attempting to pull the values selected in a checkbox filter into a string list document property. I have used the code as explained on this page: https://community.spotfire.com/wiki/how-read-and-modify-checked-values-check-box-filter-tibco-spotfire-using-ironpython-scripting but I am getting the following error message when executing the script. "Could not execute function call: value argument has incompatible value type.

The error details are below and myline 60 is:Document.Properties["SCOPEFILTER"] = checkedValues

Traceback (most recent call last):

File "Spotfire.Dxp.Application.ScriptSupport", line unknown, in ExecuteForDebugging

File "", line 60, in

File "Spotfire.Dxp.Data", line unknown, in set_Value

ValueError: value argument has incompatible value type

 

System.ArgumentException: value argument has incompatible value typeMy document property called "SCOPEFILTER" is set to a "String" and I noticed in the suggested code above that the document property must beof type 'String List' - however, I do not see 'String List' as an available document property type. I only see 'string' and I'm not sure if these are synonymous.

Below is the full code I am using, just for reference. Any help or insight would be appreciated, as numerous web searches on the error turned up nothing useful.

# Get the Scope Checkbox Filter Values

from Spotfire.Dxp.Application import Filters as filters

 

# Define filtering scheme

FilterSelection = Document.Data.Filterings["Reading List"]

 

# Define column filter

filt = Document.FilteringSchemes[FilterSelection][Document.Data.Tables["CAT_MVIEW"]]["SCOPE"].As[filters.CheckBoxFilter]()

 

# Create list to store values

checkedValues = []

 

# Loop selected values

for value in filt.Values:

 

# Toggle values using IsChecked(), Check(), Uncheck()

#if value == 'my Data Value':

#if filt.IsChecked(value) == True:

#filt.Uncheck(value)

#else:

#filt.Check(value)

 

# Store checked values

if filt.IsChecked(value) == True:

checkedValues.append(value)

 

# Output checked values to existing document property of type 'String List' named 'myStringListProp'

# Note: the line below is triggering the script error where "SCOPEFILTER" is a document property of data type "string"

Document.Properties["SCOPEFILTER"] = checkedValues

Link to comment
Share on other sites

You can create a String List document property by creating a 'list box (multi select)' property control in a text area. But it is a lot easier to use a string doc prop.

Just convert your list to string as describedbyShandilya Peddi.

If you want to use the value in another script, you can use the eval() functionto convert it back to a list.

Link to comment
Share on other sites

  • 11 months later...

Hi,

I was trying to do something similar. Im trying to retrieve the marked data and find the max and min values among the marked data. But, my Category axes has a Hierarchy. Also, i want it to consider uniqueCount(ValueAxis). Using the code below its not showing me the unique count of records of Value Axis. I only need the unique count of records.

How do i do it Your help is much appreciated. Attached sample code.

from Spotfire.Dxp.Data import DataValueCursor

 

dataTable=Document.Data.Tables['DataTable']

intCursor = DataValueCursor.CreateFormatted(dataTable.Columns["Month"])

 

markings = Document.ActiveMarkingSelectionReference.GetSelection(dataTable)

 

myPanel = Document.ActivePageReference.FilterPanel

keys=dict()

 

for row in dataTable.GetRows(markings.AsIndexSet(),intCursor):

if intCursor.CurrentValue in keys:

keys[intCursor.CurrentValue]+=1

else:

keys[intCursor.CurrentValue]=1

 

#print keys

#print 'nn'

 

#print max(keys.values())

#print min(keys.values())

 

Document.Properties["maxValue"] = str(max(keys.values()))

Document.Properties["minValue"] = str(min(keys.values()))

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...