Default value advanced features

Is it possible to set the “Default value” (from Schema items, Advanced features) of item to be currentUser value? For example login

Hi,

Default value in Schema items/Advanced features is intended just for constant value (string, number).

But you can ‘calculate’ default value in Schema Advanced settings (user custom javascript for edit form).

In this case you can use this code:

This script fills in the “My textbox” with the current user login whenever it is empty:

if (!doo.model.<[My textbox (myTextbox)]>.value)
	doo.model.<[My textbox (myTextbox)]>.value =  doo.currentUser.<[Login (login)]>;

Or

This script fills in the “My textbox” with the current user login only when creating new record:

if (doo.model.ver === -1)
	doo.model.<[My textbox (myTextbox)]>.value =  doo.currentUser.<[Login (login)]>;

Note that doo.currentUser.<[Login (login)]> has no .value property (it is system property not schema item).

If you need to better know what’s going on in custom javascript, you can debug it in Chrome console (F12 -> Console/Sources).

E.g. when you add this line on the top of your code, you can debug each line step by step in Sources window (press F10 for next step, F8 to run rest of script):

debugger;

You can also show any object to Console window and check it’s details using this command:

console.log(doo.currentUser);

Best regards
Pavel Hruschka
Tabidoo team

Hi Pavel, Thanks for the response! However, why I was asking specifically about the default value is because I would want this value to be configurable (like the default value is.) If I understand your code examples correctly, the user cannot change the value in the textbox.

Hi Martti,
user can change the value in the textbox, it is just another way how to fill in initial (default) value to the textbox.

However, it is necessary to insert these scripts into the ‘On model load’ tab - then they are run only once when the form is opened and fill the value in the textbox only if it is empty each time the form is opened (first example) or only if the edit form for adding a new record is open (second example).

If you put these scripts into the “On model change” tab, they will be run each time any value in the form changes.
Thus default value will be fill in every time when user clear the textbox for writing new value (first example - user can overwrite it, but not start in empty textbox) or default value will be fill in always when something changed in the form during adding new record (second example - user can not change the value in the textbox, because it is instantly overwritten by default value, but user can change it when editing record).

I forgot to point this out in the original post.

Best regards
Pavel Hruschka
Tabidoo team