Default Value for Integer

Default Value for Integer

  

Hello,

I would like to check if we can set default value of -1 for data type integer?

The "default value" of INTEGER is ZERO (0).
But you can set the Default property of a Variable of type INTEGER to ANY valid integer, including -1 :)

Cheers,
Eduardo Jauch

EDIT
See https://www.outsystems.com/help/servicestudio/9.0/Using_Data/Default_Values_on_database.htm

and

https://success.outsystems.com/Documentation/10/Reference/Data/Data_Types/Available_Data_Types

Hi Eduard Jauch,

Thanks noted.

I have a variable, Dimension, with Integer data type. I tried to set Dimension to -1 but when i run the application, the default value seem to change to 0 instead or i leave default value blank. This is causing my aggregate to return wrong result. Please advice


SyntaxEditor Code Snippet

Dimension = NullIdentifier() or Product.Dimension = Dimension


hi Jace2:


here are the default values of any data types in Outsystems:

https://success.outsystems.com/Documentation/10/Reference/Data/Data_Types/Available_Data_Types

I tried to assign an integer with default value -1 and then i pop it up in the preparation action. The result in my environment is -1. 

So for your case, what is the error? May be it is caused by other expression, like 

Dimension = NullIdentifier()

or at some point the Dimension variable is assigned to -1. In this case, debugging it is the best way.

regards,

bb

Hi Jace,

Is your Dimension an Identifier/Primary Key?

NullIdentifier() is for Identifier only.

Hi Jace,

There seems to be something strange with what you are trying to do:

If you have an integer variable, why are you comparing with NullIdentifier()? Why not compare it with 0 (zero)?

And where do you see the variable change to value 0? If you see it in the debugger it may be that the variable is not used anywhere: when a variable is not used it will show up with its default value (0 in your case).

Other than that, you can set the default value of an Integer variable to -1.

Cheers,

José

Hi All,

Dimension is not a Identifier/Primary Key.

I see the variable value is 0 when i debug my application. 

Hi Jace,

As a simple test, could you display that variable in a xy Expression in your screen and see if it really is 0 (zero)?

Cheers,

José

hi Jace-jace,


So, try to compare "apple to apple" then:

Dimension = 0 or Product.Dimension = Dimension


regards,

bb

Solution

Hi Jace, 

Do not compare an INTEGER variable with NullIdentifier. If Dimension is an INTEGER and you want to compare with any value, use this value instead, like this:

Dimension = 0 or Product.Dimension = Dimension

or, if you think the default value should be -1, something like this:

Dimension = -1 or Product.Dimension = Dimension

Here, the problem is not the comparison anymore, but HOW you are using this variable BEFORE the aggregate.

So, first thing, where are you DECLARING the variable? I assume its a Screen Variable, or you would not be able to use in an aggregate in the preparation (that I'm assuming is what you are doing). 

In this case, declaring the variable as Integer and setting its property DEFAULT to -1 WILL work. While you don't set a value, it will have the value -1.

So, the problem now is WHERE are you changing the value of this variable.

If you are using an INPUT to change it, as soon as you load the screen, as you are defining the DEFAULT property of the variable to -1, the input should show -1. 

And everything should work as you expected.

If not, please, attach the OML so we can take a look and go direct to the point instead of keep going in circles here :)

P.S.

Please, mark my first answer as correct, as it is the answer to your initial question and this helps keep the forum "organized" and easy to search. 

We will keep helping you with your problem anyway.

Cheers,
Eduardo Jauch

Solution

Hi All,

Apologies for not so clear question. 

Let me rephrase my question abit.

I have a table with a column "Dimension" with data type integer. Each product have a dimension itself. And there are possibilities that there is no dimension for the product. Thus 0 will be assign to that product. 

I have local variable "Dimension" to take in the value and filter according.

I have declare the Dimension = -1 in the beginning.

So in the beginning, i want to display all the product with regard which dimension it is. 

Thatwise i use 

Dimension = -1 or Product.Dimension = Dimension
Product 1
0
Product 2
1
Product 3
1
Product 4
0

Jace Jace wrote:

Hi All,

Apologies for not so clear question. 

Let me rephrase my question abit.

I have a table with a column "Dimension" with data type integer. Each product have a dimension itself. And there are possibilities that there is no dimension for the product. Thus 0 will be assign to that product. 

I have local variable "Dimension" to take in the value and filter according.

I have declare the Dimension = -1 in the beginning.

So in the beginning, i want to display all the product with regard which dimension it is. 

Thatwise i use 

Dimension = -1 or Product.Dimension = Dimension
Product 1
0
Product 2
1
Product 3
1
Product 4
0

If, when the aggregate is executed, Dimension contains the value -1, than your filter will work as expected, as for EVERY line in the results, this filter result will be TRUE, because Dimension = .1 will return true.

Cheers,
Eduardo Jauch