Hello,
I am creating a Website Form for my employees to register their arrival and departure from work.
I am having several issues. One of them, is that in Date and Time, I set the default value with Now (as happens in ERPNext on Employee Register), and no default value is inserted in the field.
I don’t know why this is working on default Doctype Form for Employee Register, but not on a Custom Form when done in the same way.
Also, is it possible to insert Employee Name based on who is logged in?
Thanks and kind regards,
Alb
Hello @pagliaso ,
This behavior is expected and can be a bit confusing at first.
1) Why “Now” does not work as default value
In Web Forms, ERPNext / Frappe does not support dynamic default values like Now() or Today() the same way it does in DocType forms.
DocType forms run inside the Desk and support server-side expressions.
Web Forms are rendered on the client side, so dynamic values are not automatically evaluated.
That’s why it works in standard Employee forms, but not in custom Web Forms.
How to fix it
You need to set the value using a Web Form Client Script, for example:
frappe.web_form.on('load', function() {
if (!frappe.web_form.get_value('hora')) {
frappe.web_form.set_value('hora', frappe.datetime.now_datetime());
}
});
This will populate the Date/Time field when the form loads.
2) Auto-filling the Employee based on the logged-in user
Yes, this is possible.
In Web Forms, you can access the logged-in user via:
frappe.session.user
Typical approach:
-
Get the logged-in user (email)
-
Fetch the related Employee record
-
Set the Employee field automatically
Example (simplified):
frappe.web_form.on('load', function() {
frappe.call({
method: "frappe.client.get_list",
args: {
doctype: "Employee",
filters: { user_id: frappe.session.user },
fields: ["name"],
limit: 1
},
callback: function(r) {
if (r.message && r.message.length) {
frappe.web_form.set_value('empleado', r.message[0].name);
}
}
});
});
You can also:
Summary
-
Now() does not work in Web Forms by default → use a client script
-
Web Forms require manual handling for dynamic values
-
Logged-in user → Employee mapping is possible via script
This approach is commonly used for attendance, check-in/out, and self-service forms.
2 Likes
Hello @shaileshsaini , many thanks for your reply and explain
2 Likes
Hello @brunoobueno ,
Many thanks for your detailed explanation!!
I was able to do everything as you suggested. I am only getting a bit problem when I make the employee field read only to set its value. I am going to try to hide it based on permission, but I have to study how to do it.
Many thanks and kind regards,
Alb