2- To Calculate Age
------------------------------
--->> BUILD -->DOCTYPE --> SEARCH "EMPLOYEE"
--->> BUILD -->CLIENT SCRIPT -->ADD NEW --> DOCTYPE=EMPLOYEE-->ENTER CODE
//RENAME "age" TO YOUR CUSTOM FIELD NAME.//
_____________________________________________
frappe.ui.form.on('Employee', {
date_of_birth: function(frm) {
if (frm.doc.date_of_birth) {
var birthDate = new Date(frm.doc.date_of_birth);
var today = new Date();
var ageInMilliseconds = today - birthDate;
var ageInYears = Math.floor(ageInMilliseconds / (365.25 * 24 * 60 * 60 * 1000));
frm.set_value('age', ageInYears);
}
}
});
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