Automatic change of Contract end in Employee doctype if contract renewal Doctype is Approved

if doc.status == ‘Approved’:
# Update the contract_end_date in the Employee doctype
frappe.db.set_value(‘Employee’, doc.employee, ‘contract_end_date’, doc.contract_end)
frappe.msgprint(‘The Contract End Date in the Employee record has been updated successfully.’)

This is the server script i ran . I want when the Contract Renewal Doctype is Approved the Contract end date in the Employee Doctype to change to the new contract end in the Contract Renewal. But its not working , Anyone who has an idea or view or any kind of help.

Hi

have you applied workflow on Contract Renewal Doctype?

Yes I have

What is the final state of workflow?

Pending from MD

On which state you want to update the date in Employee list?

After the State is Approved

So, Your server script will be

if doc.workflow_state == "Approved":
    emp_doc = frappe.get_doc("Employee",doc.employee)
    emp_doc.contract_end_date = doc.contract_end
    emp_doc.save()
    frappe.msgprint('The Contract End Date in the Employee record has been updated successfully.')

it has some how worked most especially the frappe.msgprint message . But the
contract_end_date in the Employee doctype has not changed.

try this edited code

Am talking about the one you shared

I updated the code

if doc.workflow_state == "Approved":
    emp_doc = frappe.get_doc("Employee",doc.employee)
    emp_doc.contract_end_date = doc.contract_end
    emp_doc.save()
    frappe.msgprint('The Contract End Date in the Employee record has been updated successfully.')

Have you tried this code?