Default variable in grid

I have a variable [test] that I use in the sql select of the grid. If I launch the grid without passing the parameter the grid ask me for it. How can I say to the grid to use a default value 0 if [test] is not passed?
I try to put the variable as optional but nothing sees to change…
Thank You

onScriptInit

if(!isset([test]) || empty([test]))
{
[test] = 0;
}

Also set the variable to OUT.

jsb

Hi , you can set the value of [test] when loading the grid in onInit() event like : [test] = 0.
If you want to use the [test] variable in the grid without passing the parameter you should change the type of the variable to “out”

Untitled.png

If, in the developer environment, you run an app in isolation (to test it, say) that is expecting parameters, it will ask you to supply a value.

The app knows it is expecting parameters when you reference a global var in either SQL, or code in events (unless that app is actually creating or updating the variable). When you a reference to a global var in the app and save it, the variable is added under “Application -> Global Variables”.

In there you will see something like (for each variable in your app):

in the example you can see there is a global variable [company] - and the key bit is Type. In this case it’s “Out” - this means that this app creates / updates this variable, i.e the app isn’t “reading” it - hence it’s an output variable. If this app is run in isolation it won’t ask for the parameter value because it creates or updates it, and does not need to read the value to run. If the variable referenced is set elsewhere outside this app, such that this app only wants to read the value - then Type is “in” as it’s an input variable.

In your case [test] is clearly set as “In” because SC believes nothing in this app is writing to that variable. Either because it is clear in the code that this variable is only being read (or you have manually changed Type from Out to In). NOTE: SC may determine the in/out incorrectly if the variables usage is ambiguous (being read and written conditionally say) - so sometimes you will need to manually change the in/out yourself you notice the app is misbehaving.

So, ALL apps, when run in isolation, will prompt for a value for a variables of type In. So, if you do not want to see the prompt, then either:

a) don’t run it in isolation, instead call it “naturally” in your system’s overall framework (whereby it will receive the required parameter automatically).

or

b) hardcode the value you need in the app itself whilst testing, e.g. in the apps onApplicationInit event have:

[test] = 0;

This should make the variable’s type be “out” - check if it changed after saving the code, if it isn’t then change the Type to “out”. When you are done remember to remove the code above and change type back to in.

Capture.JPG

ok, thanks… it works…
I see that the grid store the [test] variable as a global variable… So, after the first time I call the grid all the other times he has the value setted… If I want to reinitialize the value after the page is fully loaded, so in the next interrogation the value is null, which is the correct procedure?

A number of ways.

From within the app itself - if it always needs re-initialising do it in onScriptInit:

[test] = xxx;

Or if its selective - do it in an event in an app (or all apps) that “call” that grid.