what I want is when I choose a date the another field will get date after two weeks as read only
var currentDate = [your date field];
var dateAfterTwoWeeks = frappe.datetime.add_days(currentDate, 14);
@Nada-86 check your code multiple times carefully, you will find mistake,
I have not provided you the whole code, it’s just a hint for solution
Here i did my code for 180 days based on joining date in Employee Doc type,.you will change based on your requirements like Name,Field name and No of days,i hope this will help.
Automatically Calculate 180 days from Date of Joining:
Code:
frappe.ui.form.on(‘Employee’, {
refresh: function(frm) {
// Add a custom button or trigger the function on form load, if needed
},
// Trigger when the date_of_joining field changes
date_of_joining: function(frm) {
// Get the joining date from the form
var dateOfJoining = frm.doc.date_of_joining;
// Check if date_of_joining is set
if (dateOfJoining) {
// Convert the joining date to a JavaScript Date object
var jsDateOfJoining = frappe.datetime.str_to_obj(dateOfJoining);
// Calculate the probation end date (date of joining + 180 days)
var probationEndDate = frappe.datetime.add_days(jsDateOfJoining, 180);
// Format the probation end date to match ERPNext date format
var formattedEndDate = frappe.datetime.obj_to_str(probationEndDate);
// Set the probation end date on the form
frm.set_value('probation_end_date', formattedEndDate);
} else {
// If date_of_joining is not set, set probation_end_date to blank
frm.set_value('probation_end_date', '');
}
}
};
Output:
1 Like
Thank YOOUUU
Welcome