Choose Language Hide Translation Bar
Highlighted
Kelly
Level III

How can I get an if statement working in the Allocate function of Dashboard creator script?

My dashboard creates buttons using button box() just fine. But when I use an if statement it no longer works. Here is the If statement:

 

If( 1,
	Button1 = Button Box()
);
If( 1,
	Button2 = Button Box()
);

 

Everything compiles nicely and my dashboard comes up but these buttons are missing.
Thanks for the help

 

 

4 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted

Re: How can I get an if statement working in the Allocate function of Dashboard creator script?

Hi Kelly - I would caution against editing the content inside the Allocate() block for a Dashboard, unless you are just changing the value of a string.  Changing the structure can definitely result in a Dashboard (or Application) that does not execute correctly.  When I run your script with the If() blocks enabled, I see error messages in the log:

 

expecting: variable = object(); 2 times in access or evaluation of 'Plan' [...]

 

I'm not sure what you're trying to do with the conditional boxes, but Application Builder will work best if you put any additional logic that you need in the Application and Module scripts - these scripts are executed as plain JSL (or 99% so), while the other code within a JMPApp() has a very specific syntax.

View solution in original post

Highlighted

Re: How can I get an if statement working in the Allocate function of Dashboard creator script?

You could conditionally determine the expression that is evaluated when the button is clicked before the button is created by calling Button Box().

bb expr = If( 1, Expr( ... ), 2, Expr( ... ) );

Button Box( "name", bb expr )
Learn it once, use it forever!

View solution in original post

Highlighted
Kelly
Level III

Re: How can I get an if statement working in the Allocate function of Dashboard creator script?

I did not see the error message in the log possibly due to different versions. I am using JMP 14.1.0 by the way.

 

I may be missing something but I am not sure why you suggest to use the application and module script instead of dashboard because they are the same with the exception of this line of code:

Dashboard Mode( 1 ),

 

I did find a work around by putting the condition statement in the Initialize() function of the JMP App() function. I have to create a button, but I can determine later on if I will let it show on the dashboard or not.

 

Button1 << Visibility(If(1,"Visible","Hidden") );

 

Thanks!

View solution in original post

Highlighted

Re: How can I get an if statement working in the Allocate function of Dashboard creator script?

To clarify my comment about the Application and Module scripts - Application Builder exposes scripts that are tied to the top-level application and each module.  These are accessed via the Scripts tab when you toggle off Dashboard mode (text still says "Dashboard" because the document was started in Dashboard mode):

 

DashboardModuleScript.png

 

This script is saved verbatim and will preserve any changes that you make.  In your example of editing the Initialize() script, you will note that while the button visibility may appear correct the first time you run the script, if you save the script from the Dashboard builder again, the line will have changed to:

 

Button1 << Visibility("Visible");

This will likely lose your intended behavior if you want to use expressions more complex than If(1).  All of the content in the Allocate(), Organize(), and Initialize() sections are generated from scratch each time the script is saved and will not retain customizations if you use the builder interface to change and then save the script.

 

View solution in original post

6 REPLIES 6
Highlighted
Jeff_Perkinson
Community Manager Community Manager

Re: How can I get an if statement working in the Allocate function of Dashboard creator script?

I think we're going to need some more context about exactly what you're doing. We need to see the context where the If() is being used? Is it in a New Window() or a JMP App()? 

 

Can you post a more complete script that demonstrates the problem?

-Jeff
Highlighted
Kelly
Level III

Re: How can I get an if statement working in the Allocate function of Dashboard creator script?

Yes you are right. Here is a simplified version of the script I'm working on that focuses on just creating the buttons. The buttons are on lines 37-45. Using the If statement creates a dashboard without buttons.

Highlighted

Re: How can I get an if statement working in the Allocate function of Dashboard creator script?

Hi Kelly - I would caution against editing the content inside the Allocate() block for a Dashboard, unless you are just changing the value of a string.  Changing the structure can definitely result in a Dashboard (or Application) that does not execute correctly.  When I run your script with the If() blocks enabled, I see error messages in the log:

 

expecting: variable = object(); 2 times in access or evaluation of 'Plan' [...]

 

I'm not sure what you're trying to do with the conditional boxes, but Application Builder will work best if you put any additional logic that you need in the Application and Module scripts - these scripts are executed as plain JSL (or 99% so), while the other code within a JMPApp() has a very specific syntax.

View solution in original post

Highlighted
Kelly
Level III

Re: How can I get an if statement working in the Allocate function of Dashboard creator script?

I did not see the error message in the log possibly due to different versions. I am using JMP 14.1.0 by the way.

 

I may be missing something but I am not sure why you suggest to use the application and module script instead of dashboard because they are the same with the exception of this line of code:

Dashboard Mode( 1 ),

 

I did find a work around by putting the condition statement in the Initialize() function of the JMP App() function. I have to create a button, but I can determine later on if I will let it show on the dashboard or not.

 

Button1 << Visibility(If(1,"Visible","Hidden") );

 

Thanks!

View solution in original post

Highlighted

Re: How can I get an if statement working in the Allocate function of Dashboard creator script?

To clarify my comment about the Application and Module scripts - Application Builder exposes scripts that are tied to the top-level application and each module.  These are accessed via the Scripts tab when you toggle off Dashboard mode (text still says "Dashboard" because the document was started in Dashboard mode):

 

DashboardModuleScript.png

 

This script is saved verbatim and will preserve any changes that you make.  In your example of editing the Initialize() script, you will note that while the button visibility may appear correct the first time you run the script, if you save the script from the Dashboard builder again, the line will have changed to:

 

Button1 << Visibility("Visible");

This will likely lose your intended behavior if you want to use expressions more complex than If(1).  All of the content in the Allocate(), Organize(), and Initialize() sections are generated from scratch each time the script is saved and will not retain customizations if you use the builder interface to change and then save the script.

 

View solution in original post

Highlighted

Re: How can I get an if statement working in the Allocate function of Dashboard creator script?

You could conditionally determine the expression that is evaluated when the button is clicked before the button is created by calling Button Box().

bb expr = If( 1, Expr( ... ), 2, Expr( ... ) );

Button Box( "name", bb expr )
Learn it once, use it forever!

View solution in original post

Article Labels

    There are no labels assigned to this post.