Tim McCune 3 Posted May 13, 2019 Share Posted May 13, 2019 Using the SpotFire menus, I can manually insert a new calculated column and enter a string for the expressionand it works fine but when I try to do this with a script, the string in the expression is treated as a column name and I get an error stating that the column is missing: cols = Document.Data.Tables["Table1"].Columns newcol=cols.AddCalculatedColumn('NewColumn','abc'); Traceback (most recent call last): File "", line 2, in Exception: Could not find column 'Table1.abc'. Can this be done with a script Link to comment Share on other sites More sharing options...
Shandilya Peddi Posted May 13, 2019 Share Posted May 13, 2019 does the same expression that you are using the script work when trying from the GUI What version of Spotfire are you currently testing this Link to comment Share on other sites More sharing options...
Tim McCune 3 Posted May 13, 2019 Author Share Posted May 13, 2019 I'm using SpotFire 7.12 Yes, I'm using the same expression and it works in the GUI but not in the script. For example, in the GUI I'll do "Insert"->"Calculated Column". And then in the "Expression" box I'll enter a simple string 'abc' and then SpotFire will add the new column and all the values in the new column will be 'abc', which is what I want. But if I try to do this in a script, it will interpret the string as a column name, which it isn't, and then it will throw an error stating that it can't find column "Table1.abc". Is there a way to tell the script that I only want a string for the expression and that I'm not referencing a column Link to comment Share on other sites More sharing options...
Shandilya Peddi Posted May 13, 2019 Share Posted May 13, 2019 I think the issue is expressing string within the quotes. In the GUI you will be using 'abc' so in the script it should be something like this cols.AddCalculatedColumn("col1","'abc'") or cols.AddCalculatedColumn("col2",''abc'') Can you try the above and see if it helps Link to comment Share on other sites More sharing options...
Tim McCune 3 Posted May 13, 2019 Author Share Posted May 13, 2019 That was it! I tried your suggestion: cols.AddCalculatedColumn("col1","'abc'") And the nested quotes solved the problem, no more missing column errors! Thanks for the help, this saved me a lot of time chasing other much more complex solutions. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now