Initialize a local variable of a particular data type( entity/structure) with null

Hello,

How to Initialize a local variable of a particular data type( entity/structure) with null or empty value

or

What is the best approach to initialize a local variable with empty value and also to remove the data from the local variable after a particular action is performed in the screen using the variable so that the stale data is not present in the variable while calling the action again.

I tried assigning null value to a variable of a particular entity datatype but could not do it.

Regards,

Indranil

Solution

Hi Indranil Dey,

1. Once you initialize local variable based on the data type default value will be stored in it.

For example : Structure or Entity Type : Null, number Type : 0 .. etc

2. In your scenario you can create two variables one is original variable which you want to use it for particular action, Second empty value with same data type to assign original variable with empty variable after your operation / logic .



This two variable concept I often use while lopping through list.


Hope this helps.


Sravan

Solution

Sravan Vanteru wrote:

Hi Indranil Dey,

1. Once you initialize local variable based on the data type default value will be stored in it.

For example : Structure or Entity Type : Null, number Type : 0 .. etc

2. In your scenario you can create two variables one is original variable which you want to use it for particular action, Second empty value with same data type to assign original variable with empty variable after your operation / logic .



This two variable concept I often use while lopping through list.


Hope this helps.


Sravan


Hi Sravan,

Thanks for your response.Yes, using two variables,the situation is handled.But just being curious,there is no direct assignment of null value to a variable like structure or entity,in outsystems?

Hi Indranil Dey,

As per my knowledge I don't think we can assign null or empty values to variables in OutSystems.


Sravan

There is no way to assign empty values to all Attributes of an entire Structure. You can either assign each Attribute, or do what Sravan says, have an "empty" Variable of the Structure type.

Note however, that Local Variables of Screen Actions are created with empty (default) values for all Structure Attributes, so you needn't "reset" anything in that case. So if you use a Local Variable inside the Screen Action only, and nowhere on the Screen, make it local to the Screen Action, as opposed to local to the entire Screen.