Question

I am very, very new to Iron Phyton and I am trying to create a script that will allow a user to select the 'All' function in a drop down list. Here is the code that I have so far, but I get an error message saying that "The type 'System.String[]' of the property value does not match the expected 'System.String' type"

I am coding in Spotfire and I can not store arrays in properties as only strings are allowed. Ive searched that I could use ', '.join(mylist)

But I just do not know where to place it...Please help, thanks..Code is below

from System import Array
from Spotfire.Dxp.Data import IndexSet
from Spotfire.Dxp.Data import DataValueCursor

#Get access to the Column from which we want to get the values from
myCol = Document.ActiveDataTableReference.Columns["Business Group"]

rowCount = Document.ActiveDataTableReference.RowCount
rowsToInclude = IndexSet(rowCount,True)


#Create a cursor to the Column we wish to get the values from
cursor1 = DataValueCursor.CreateFormatted(Document.ActiveDataTableReference.Columns ["BusinessGroup"])


strArray = Array.CreateInstance(str,rowCount)


#Loop through all rows, retrieve value for specific column, and add value into array
 for  row in  Document.ActiveDataTableReference.GetRows(rowsToInclude,cursor1):
 rowIndex = row.Index
 value1 = cursor1.CurrentValue
 strArray[rowIndex-1] = value1   

#Set property to array created above
myCol.Properties.SetProperty("BusinessGroup",strArray)
Was it helpful?

Solution

Assuming that your code fails in the last line of your snippet because "BusinessGroup" should be a string and not an array of strings you could use join the following way:

myCol.Properties.SetProperty("BusinessGroup", ', '.join(strArray))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top