issue in for loophello All, I am not able to figure out why this for loop formula is not working. It simply creating a new column if units are in time and then covert it into Hours. Sample data is also attached. Thanks.
ColNames = dt << get column names( string, Numeric, character, continuous, Nominal );
N Items( ColNames );
For( i = 1, i <= N Items( ColNames ), i++,
If( Ends With( ColNames[i], "(secs)" ),
New Column (Concat(ColNames[i], "_to_", "Hr"), Formula(AS Column(ColNames[i])/3600) ),
Ends With( ColNames[i], "(min)" ),
New Column (Concat(ColNames[i], "_to_", "Hr"), Formula(AS Column(ColNames[i])/60) ),)
);
Wait( 0 );
ScriptingRe: issue in for loopThe issue is that the Formula element does not parse the formula presented and then place the resulting code into the formula. Therefore, what is presented to the formula element, needs to be exactly the JSL the formula needs to be. Below is a rework of your jsl
Names Default To Here( 1 );
dt = Current Data Table();
ColNames = dt << get column names( string, Numeric, character, continuous, Nominal );
//N Items( ColNames );
For( i = 1, i <= N Items( ColNames ), i++,
If(
Ends With( ColNames[i], "(secs)" ),
New Column( Concat( ColNames[i], "_to_", "Hr" ),
Formula( Eval( Parse( ":\!"" || ColNames[i] || "\!"n / 3600" ) ) )
),
Ends With( ColNames[i], "(min)" ),
New Column( Concat( ColNames[i], "_to_", "Hr" ),
Formula( Eval( Parse( ":\!"" || ColNames[i] || "\!"n / 60" ) ) )
),
)
);Re: issue in for loopYou might also consider using JSL Quote(), which allows the code to remain highlighted
Names Default to Here( 1 );
dt = Current Data Table();
For( i = 1, i <= N Cols( dt ), i++,
column name = Column( dt, i ) << Get Name;
If( Ends With( column name, "(secs)" ),
Eval( Parse( Eval Insert( JSL Quote(
dt << New Column( "^column name^_to_Hr", Formula( :Name("^column name^" ) / 3600 ) )
) ) ) )
,
Ends With( column name, "(min)" ),
Eval( Parse( Eval Insert( JSL Quote(
dt << New Column( "^column name^_to_Hr", Formula( :Name("^column name^" ) / 60 ) )
) ) ) )
)
);