HR MODULE CONFIGURATION -Add Custom Fields in Employees Doctype -Add Client Scripts -Employees Work Experience in Years ‐------------------------- Codes to Enter in Scripts: --->> BUILD -->DOCTYPE --> SEARCH "EMPLOYEE" --->> BUILD -->CLIENT SCRIPT -->ADD NEW --> DOCTYPE=EMPLOYEE-->ENTER CODE ----------------------------- To Calculate Work Experienc: _________________________________________________________________________ frappe.ui.form.on('Employee', { onload: function (frm) { frm.add_fetch('date_of_joining', 'date_of_joining', 'date_of_joining'); }, refresh: function (frm) { calculateWorkExperience(frm); }, date_of_joining: function (frm) { calculateWorkExperience(frm); }, }); function calculateWorkExperience(frm) { if (frm.doc.date_of_joining) { const dateOfJoining = new Date(frm.doc.date_of_joining); const currentDate = new Date(); const diffInMilliseconds = currentDate - dateOfJoining; const years = Math.floor(diffInMilliseconds / (1000 * 60 * 60 * 24 * 365)); const months = Math.floor((diffInMilliseconds % (1000 * 60 * 60 * 24 * 365)) / (1000 * 60 * 60 * 24 * 30)); const fractionalYears = (years + months / 12).toFixed(2); frm.set_value('work_experience', parseFloat(fractionalYears)); } else { frm.set_value('work_experience', ''); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter