Jump to content

How to add a constant value column using a script


Tim McCune 3

Recommended Posts

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

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

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

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

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...