Need Length of Service of an Employee

Hi Friends,
I need Length of Service of an employee, the length of service means (current date - joining date ) / 365 this need in employee master and expense claim transaction automatically.
Thanks in Advance

Hi @sathya_raj,

Please try it.

frappe.ui.form.on('Employee', {
    onload: function(frm) {
        if (frm.doc.date_of_joining) {
            var diffYears = frappe.datetime.get_diff(frappe.datetime.now_date(), frm.doc.date_of_joining) / 365;
            frm.set_value('custom_length_of_service', diffYears.toFixed(2));
        }
    }
});
onload: function(frm) {

Please set your according,and you can also use (before_save or refresh).

1 Like

Thank you so much