Search code examples
pythonironpythonspotfire

Spotfire: changing formula in calc column using IronPython


Long time user very first question:

I am trying to update the formula in a calculated column in Spotfire using ironpython. I have a table called tbl_test with calculated column 'Biz_rule'. I create a string called str_statement and try to use it to replace the expression in the caluclated column with the code below:

calc_col = tbl_test.Columns.Item['Biz_rule']
calc_col = calc_col.As<CalculatedColumn>()
calc_col.Expression = str_statement;

I get the following error.

Traceback (most recent call last):
  File "Spotfire.Dxp.Application.ScriptSupport", line unknown, in ExecuteForDebugging
  File "<string>", line 25, in <module>
  AttributeError: 'bool' object has no attribute 'Expression'

I assume because

calc_col.As<CalculatedColumn>() 

returns a boolean indicating whether or not the operation succeeded. How do I get an instance of the calculated column so I can update the expression?


Solution

  • tbl_test = Document.Data.Tables['data source scott']
    calc_col = tbl_test.Columns.Item['Job Job']
    calc_col.Properties.SetProperty('Expression','[JOB]')
    

    The above code works for me. Is it what you tried to do ? The question is why did you use

    'calc_col.As<CalculatedColumn>()' 
    

    ?