Subscribe Bookmark RSS Feed

create dynamic script to a table

YuxinHuang

New Contributor

Joined:

Apr 20, 2017

Hi, 

I am trying to dynamically change the content of the script before adding to a data table  using the  dt << new script(name, script_content) where script_content is a variable containing the script to be added . However, new script() treats the script_content as a string instead of a variable.  

here is an example, the contnet of script "test" in table "Dynamic Script" will show "script_content" instead of  "show("First half year")". Could someone help?

 

if (month(today()) > 6,
script_content = expr(show("Second half year")), script_content = expr(show("First half year")));
dt = New Table("Dynamic Script");
dt << new script ("test", script_content);

thank you very much,

Yuxin Huang 

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson

Super User

Joined:

Jun 22, 2012

Solution

Here is how I solve such problems

If( Month( Today() ) > 6,
	script_content = Expr(
		Show( "Second half year" )
	),
	script_content = Expr(
		Show( "First half year" )
	)
);
dt = New Table( "Dynamic Script" );
Eval( Parse( "dt << new script (\!"test\!"," || Char( Eval Expr( script_content ) ) || ";)" ) );
Jim
2 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

Solution

Here is how I solve such problems

If( Month( Today() ) > 6,
	script_content = Expr(
		Show( "Second half year" )
	),
	script_content = Expr(
		Show( "First half year" )
	)
);
dt = New Table( "Dynamic Script" );
Eval( Parse( "dt << new script (\!"test\!"," || Char( Eval Expr( script_content ) ) || ";)" ) );
Jim
YuxinHuang

New Contributor

Joined:

Apr 20, 2017

Thank you very much Jim. This is a very smart solution.