Hi everyone,
I know that a List variable can be cleared by using the ListClear action.
However, I'm not sure how to reset a Structure variable.
For example, I have a local variable named `SearchCondition` with the data type `WarehouseBoxPackingMaterialItem`.
It contains multiple attributes such as:
- LGNUM
- WERKS
- LGORT
- MATNR
- MAKTX
- ZREPAIR
- ZBQTY
- BOXSIZE
- BOXCNT
- VERME
- MEINS
- CHARG
- BOXNO
After using this variable, I'd like to reset all of its attributes back to their default values (empty strings, zeros, False, etc.).
Is there a built-in way to initialize or clear a Structure variable, similar to `ListClear` for Lists?
Or is the recommended approach to assign each attribute individually?
Any advice would be appreciated. Thank you!
There is actually a workaround. You can create a local variable of the same structure type and leave it with its default (empty) values. Whenever you need to clear the values of another variable of that structure (the one you are using), simply assign the empty local variable to it. This will reset all of its fields to their default null values.
Hi @sangwoo jee,
I’m not sure there’s a built-in way to clear all of them automatically.
The approach I know is to explicitly assign each attribute back to its corresponding null value.
I can't believe it.
Is there no action that performs a similar function to ListClear?
감사합니다.
저는 이미 그 방법을 사용하고 있지만, 제 아마추어적인 실력이 그대로 드러나는 것 같아서 제대로 하는 방법을 알고 싶었습니다.
As far as I know, there isn't a built-in way to clear a structure in OutSystems. Assigning an empty instance of the same structure is the standard approach, so you're not doing anything wrong it isn't an amateur solution.
marked @Sherif El-Habibi answer as solution.
as he said, there is nothing amateur about this.
If you are using this same structure all over your application and often need to reset it to default, you could make your code a little cleaner (no extra local variables all over the place) by creating a little helper function that exports this structure and does nothing to it.
Or one step further, if you often want to initialize certain fields to some non default value in the same way (like userid to logged in user, datetime to currdatetime, some code to some site property,etc...) that function can do that for you as well and make it consistent all over your application.