Set default value for a column at runtime

Hi All,

Is there a way to set an auto enter value for a column at runtime?
We can successfully set a default value at design time in the table.tbl settings but I couldn’t really find a way to do it on the fly.

Or maybe there’s a different solution to our problem? What we are doing is enabling the user to set a default value for it, so next time they add a new record in that table, they don’t need to set defaults.
Clearly, we can’t do it at design time because we don’t know what they are going to be :)

Thanks in advance!

Cheers,
Maria

Hi Maria,

You can’t change the default value at runtime but you can however use a tableevent to set the value according to your users preference.
So essentially you connect a method to the table and when a new record gets created from anywhere (inside your solution) then this value is added.

Hope this helps.

How about specifying a global variable in the Lookup Value of the AutoEnter tab? That should work.

[attachment=0]AutoEnterRuntimeValue.png[/attachment]

ROCLASI:
Hi Maria,

You can’t change the default value at runtime but you can however use a tableevent to set the value according to your users preference.
So essentially you connect a method to the table and when a new record gets created from anywhere (inside your solution) then this value is added.

Hope this helps.

I guess I’ll have to, roclasi.
Thanks for your input.

Cheers,
Maria

omar:
How about specifying a global variable in the Lookup Value of the AutoEnter tab? That should work.

[attachment=0]AutoEnterRuntimeValue.png[/attachment]


At runtime, Omar? :)
I’ll have a table event instead, it’s all good.

Cheers,
Maria

Yes, no problem. I tried it and when you change the value of the globals.__AutoEnterValue it will use the new value on the next new record.

Kind regards,
Omar

omar:
Yes, no problem. I tried it and when you change the value of the globals.__AutoEnterValue it will use the new value on the next new record.

Kind regards,
Omar

This way I’ll have to set a global__AutoEnterValue for each field of each table that might ever have a default value and that’s pretty much any field in any table and there’s a hundred tables.
Nah :D

Cheers,
Maria

ROCLASI:
Hi Maria,

You can’t change the default value at runtime but you can however use a tableevent to set the value according to your users preference.
So essentially you connect a method to the table and when a new record gets created from anywhere (inside your solution) then this value is added.

Hope this helps.

Hi Robert,

I somehow assumed that onRecordInsert() (the table event you and I were talking about) would be fired when I execute controller.newRecord() or foundset.newRecord().
However, the event only happens when I save that record in the database - and it’s a little too late by then to set the defaults.

Did you mean anything else or that’s what it is? Because in this case I cannot use it.

Cheers,
Maria

This way I’ll have to set a global__AutoEnterValue for each field of each table that might ever have a default value and that’s pretty much any field in any table and there’s a hundred tables.
Nah :D

Cheers,
Maria

Ah, that’s a bit much then, I agree. Maybe the onFoundSetRecordCreate() can help, but thats even before the record is created so that may be to early. You can always code a generic global method however that contains the logic for determining the defaults and instead of appointing them to the defaults of the database place them in the corresponding dataproviders after the record has been created by looping through the available elements?

omar:

This way I’ll have to set a global__AutoEnterValue for each field of each table that might ever have a default value and that’s pretty much any field in any table and there’s a hundred tables.
Nah :D

Cheers,
Maria

Ah, that’s a bit much then, I agree. Maybe the onFoundSetRecordCreate() can help, but thats even before the record is created so that may be to early. You can always code a generic global method however that contains the logic for determining the defaults and instead of appointing them to the defaults of the database place them in the corresponding dataproviders after the record has been created by looping through the available elements?

onFoundSetRecordCreate() - is that a new thing in Servoy beta, omar? Haven’t heard of it before.

Yes, a global method will need to be called from wherever I create new records, it’s a bit of work and I wanted to keep it as automated as possible.

Cheers,
Maria

omar:

This way I’ll have to set a global__AutoEnterValue for each field of each table that might ever have a default value and that’s pretty much any field in any table and there’s a hundred tables.
Nah :D

Cheers,
Maria

Ah, that’s a bit much then, I agree. Maybe the onFoundSetRecordCreate() can help, but thats even before the record is created so that may be to early. You can always code a generic global method however that contains the logic for determining the defaults and instead of appointing them to the defaults of the database place them in the corresponding dataproviders after the record has been created by looping through the available elements?

Found it and it’s awesome! Omar, afterFoundSetRecordCreate() works perfectly for me.
Thanks heaps :D

Cheers,
Maria

You’re welcome! Glad I could help. 8)