Initializing entity fails

I have a datatable and use a button to create a new entity which is then added to the table.
So far, this works just fine.
Only when I add a function to initialize the new entity after creating it, saving the entity fails although the toast shows “success”.

So, I have a new entity standard action attached to the button plus the function call to the init-function which is a function of the respective entity.
If the init-function is called (debugger shows no problems), saving does not work.
if the init-function is not called, saving seems to work (feedback toast says success), but it doesn’t.

I would love to not use an init-function for trivial entities, but since the default value for a bool attribute is null instead of false which leads to further complications down the line, I need to initialize.

Any ideas?

Hey Tilman,
Thank you for your feedback, which version of Qodly do you use ?

I’m using 0.14.3.
Come to think of it, that is strange, because sometime inbetween I had the impression I was on 1.0.0 beta

0.14.3 is Qodly studio’s version
1.0.0-beta.1 is Qodly’s vers (Qodly server + Qoldy studio + …)

Hello Tilman!

Can you provide us with a glimpse on the function you used?

Sure:

extends Entity

exposed function initEntity()->result: boolean

this.distrodate=currentDate()
this.completed=false
result= true

return result

Just to clarify, I tried previously with “return true” and I also tried to only assign the date, not the boolean value.
Interestingly enough, the initialization per se is working, it’s just that the save action does not work afterwards.

So here’s the interesting point: After writing this, instead of using the standard action, I created a function that saves the entity programmatically and voilá - that does the trick!

But you can include your entity saving directly in the same function:

extends Entity

exposed function initEntity()

this.distrodate=currentDate()
this.completed=false
this.save()

I could but then I take away the option to not save a new entity if I mistakenly clicked on a button to create one.

For your case, for the boolean thingy, you can try creating a boolean datasource and give it as initial value false, then copy it in your entity’s property, using that init button, perform your other actions and then save your final entity using another button.

Declaration of the datasource:

image

The “init entity” button has the init+copy actions:

After performing your other actions on that entity and save it, the output is:

image

Or you can directly combine the edition and the saving of your entity in that same function of yours.

Thank you, I have implemented individual init-functions for every Entity that I create so I can control the default values.