I am trying to Create a pair of scripts, the first would save column names and formulas into a list and the second would bring those in thru use of namespace and apply them to another data table. I believe I have the basic namespace concept handled, but am having issues apply the properties. Any help would be much appreciated.
Script 1:
clear symbols(); //for debug
Names Default to Here(1); //namespace declaration,create variables in local scope only
ns = New Namespace("outer");
dt = Current data table();
if(isEmpty(dt),
try(dt = Open(), Throw("No data table found"))
);
nc = nCol( dt );
ns:names = dt << Get Column Names();// get column names
print(ns:names);
ns:formulaList={};
For( i = 1, i < N Items(ns:names), i++,
col = Column(i);
ns:formulaList[i] = col << get Property( "Formula");
);
print (ns:formulaList);
ns <<Lock("names","formulaList");
Output:
{Col1, umn 2, Con 4, Column}
{Empty(), :Col1 + 8, :umn 2 * 3}
Script 2:
Clear Symbols(); //for debug
Names Default to Here(1); //namespace declaration,create variables in local scope only
ms=namespace("outer");
dt = Current Data Table();
If( Is Empty( dt ),
Try( dt = Open(), Throw( "No data table found" ) )
);
colSize = N Col( dt );
ListSize = N Items(ms:names);
For( i = 1, i < ListSize + 1, i++,
if(i > colSize, New Column( "temp" ));//create columns to accomidate list size
print(ms:names[i]);
Column(i) << Set NAME(ms:names[i]);//set column names
//col << Formula( Eval(ms:formulaList[i]) );//set column formulas
);
print(ms:formulaList);
//ms << Delete;
Output:
Col1
umn 2
Con 4
Column
{Empty(), :Col1 + 8, :umn 2 * 3}
The two main issues, the column names in second data table do not take on the new names, and if uncommented col << Formula breaks. Have tried many different ways but have yet to have success with getting either to work.
*Edit- added List/Column size check to second script
*Solved first question, see answer below.
The question now, is there a specific "type" Formula or Set Formula is expecting to enable it to work?