cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
martin_snogdahl
Level III

Report and button box references

Dear community,

I hope you can help with this. The example script below creates a table and opens the profiler platform. Additionally it appends two controls to the report. The functionality of the ‘Turn On’ button is to set the value of the Check Box to 1/true. The controls are added by using a reference to the profiler report, ‘PF’. Now, the problem arises when running the script twice in a row. By doing this, the ‘PF’ reference will be overwritten to refer to the newest report. When I use the ‘Turn On’ button on the old report, it now sets the value of the Check Box in the new report. Of course, this is not the behavior I want. I guess I must somehow use a unique reference for every report. Can anyone help? Thank you.

 

Table 1 = New Table( "Table 1",
	Add Rows( 1 ),
	New Column( "p1", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2] ) ),
	New Column( "p2", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [3] ) ),
	New Column( "model",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Formula( :p1 ^ 2 + :p2 ^ 2 ),
		Set Selected
	),
	Set Row States( [1] )
);
PF = Profiler(
	Y( :model ),
	Profiler(
		1,
		Term Value(
			p1( 2, Min( 1.9 ), Max( 2.1 ), Lock( 0 ), Show( 1 ) ),
			p2( 3, Min( 2.9 ), Max( 3.1 ), Lock( 0 ), Show( 1 ) )
		)
	)
);
Report( PF )["Prediction Profiler"] << Append(
	NewButton = Button Box( "Turn On" );
  //NewIndicator = Radio Box();
);
Report( PF )["Prediction Profiler"] << Append( CheckBox = Check Box( "Item 1" ) );
Report( PF )[Button Box( 1 )] << Set Script(
	CheckBox << Set( 1 )
);

 

4 REPLIES 4
txnelson
Super User

Re: Report and button box references

The way that I handle such issues is to create the references to the different objects with different memory variables using substitute

Names Default To Here( 1 );
// Create a counter that initializes only the first time it is run, so it increments for each execution
 
If( Is Empty( counter ) == 1,
	counter = 0
);
counter = counter + 1;
 
Eval(
	Substitute(
			Expr(
				Report( PF )["Prediction Profiler"] << Append(
					__NewButton__ = Button Box( "Turn On" );
  //NewIndicator = Radio Box();
				)
			),
		Expr( __NewButton__ ), Parse( "NewButton" || Char( counter ) )
	)
);

this will create NewButton1, NewButton2, etc. for each subsequent execution.

Jim
martin_snogdahl
Level III

Re: Report and button box references

So this did the trick, thank you.

 

Eval(
	Substitute(
			Expr(
				Report( PF )["Prediction Profiler"] << Append( _NewButton_ = Button Box( "Turn On" ) );
 
 
 				Report( PF )["Prediction Profiler"] << Append( _CheckBox_ = Check Box( "Item 1" ) );
				_NewButton_ << Set Script( _CheckBox_ << Set( 1 ) );
			),
		Expr( __NewButton__ ), Parse( "NewButton" || Char( counter ) ),
		Expr( _CheckBox_ ), Parse( "CheckBox" || Char( counter ) )
	)
);

 

Craige_Hales
Super User

Re: Report and button box references

Your example has a check box that is the next sibling of a button box, which means it is really easy for the button box to find the checkbox, if only the button box can find itself.  It can, if you use setFunction rather than set script.  Bold text, below.  The variable is gone.  You now have an anonymous function (not assigned to a JSL variable) that the button box can pass "this" to.  "this" is the button box, and the sibling of "this" is the checkbox.  The PF variable is still changed, but I'm not sure you need it.  It is possible for the function to crawl up through the <<parent chain to find the platform that holds the button.

 

Table 1 = New Table( "Table 1",
	Add Rows( 1 ),
	New Column( "p1", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2] ) ),
	New Column( "p2", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [3] ) ),
	New Column( "model",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Formula( :p1 ^ 2 + :p2 ^ 2 ),
		Set Selected
	),
	Set Row States( [1] )
);
 
PF = Profiler(
	Y( :model ),
	Profiler(
		1,
		Term Value(
			p1( 2, Min( 1.9 ), Max( 2.1 ), Lock( 0 ), Show( 1 ) ),
			p2( 3, Min( 2.9 ), Max( 3.1 ), Lock( 0 ), Show( 1 ) )
		)
	)
);
Report( PF )["Prediction Profiler"] << Append(
	Button Box( "Turn On" );
  //NewIndicator = Radio Box();
);
Report( PF )["Prediction Profiler"] << Append( Check Box( "Item 1" ) );
Report( PF )[Button Box( 1 )] << Set Function( Function( {this}, (this << sib) << Set( 1 ) ) );

 

Craige
martin_snogdahl
Level III

Re: Report and button box references

Hi Craige

Thank you for this. The checkbox in this example was just for illustrating the behaviour. In my 'real' application the Button Box creates a journal from a report. So the issue was to have the button reference the right report window. Your solution might come in handy some other time. Thank You.