Is it possible to set the “Default value” (from Schema items, Advanced features) of item to be currentUser value? For example login
Default value in Schema items/Advanced features is intended just for constant value (string, number).
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)]>;
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).
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):
You can also show any object to Console window and check it’s details using this command:
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.
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.