Support Topics Documentation Slack YouTube Blog

Custom default value for data colum

Hi there, I need to create a column where the default value would be an empty array. When I try to get the data from the table to receive [ ] for the property instead of null. Is it possible to achive this?

Hello @Viktor_Viktorov

Seems like we are talking about JSON Data Type and for this type there is no way to setup a default value.

So, I can recommend you to create a BeforeCreate EventHandler to assign an empty array if it is missed, or you can create an AfterFind EventHandler and assign an empty for all items where it is missed.

However, I would say the best way it is to archive this on your client side in both ways save/retrieve

Regards, Vlad

Hi @vladimir-upirov, thank you for the suggestion. As I am still learning is there a documentation on how to create BeforeCreate and EventHandlers?

yes, sure https://backendless.com/docs/codeless/codeless_what_is_a_codeless_event_handl.html

this is for Codeless, you can do it using JS and Java as well

Regards, Vlad

Thanks a lot, @vladimir-upirov , it made it work as I wanted!