Feild status change automatically

so I HAVE A FEILD CALLED-MD Approval Date
AND I WANT THAT WHENEVER THE INVOICE STATUS CHANGED TO MD APPROVED THE (MD Approval Date) SHOULD BE CHANGED ACCORDING TO THAT DATE.

SORRY FOR BAD ENGLISH.

THANKS.

Hi @rs115199789,

Please try with client script or server script, Here provide the client script so try it and check it.

frappe.ui.form.on('Sales Invoice', {
    validate: function(frm) {
        if (frm.doc.status === 'MD Approved') {
            frm.set_value('md_approval_date', frappe.datetime.nowdate());
        }
    }
});

I hope this helps.

Thank You!

Thanks for the reply, But i dont know why it’s not working, maybe this image will help you to understand my fields.

Thank you

Please apply it.

frappe.ui.form.on('Sales Invoice', {
    validate: function(frm) {
        if (frm.doc.workflow_state === 'MD Approved') {
            frm.set_value('custom_md_approval_date', frappe.datetime.nowdate());
        }
    }
});

Please check your doctype and field name and set it in the script.

Thank You!

Not working must be some other issue :frowning:

Hi @rs115199789,

I tried the updated code and it’s working on my end.

frappe.ui.form.on('Sales Invoice', {
    after_workflow_action: function(frm) {
        if (frm.doc.workflow_state === 'MD Approved') {
            frm.set_value('custom_md_approval_date', frappe.datetime.nowdate());
            frm.save();
        }
    }
});

Thank You!

@NCP @revant_one
The thing is there is no error message is coming, everything seems fine but the MD Approval Date Field is showing just empty even after i change the workflow status of Purchase Invoice to MD Approved.
I wrote the script in client script as you mentioned.

Please help. Thanks


Do i need to set the feild to read only ? Because when i do it becomes invisible.
Thanks.

here is my old script which frappe or backend team made and it was working fine in erpnext version 13, but not working in 14.

frappe.ui.form.on(‘Purchase Invoice’, {

before_workflow_action: (frm) => {
    
    if(frm.selected_workflow_action == "Send for Re-Submission" && frm.doc.workflow_state == "Submitted for PC Approval" && !frm.doc.rejected_reason_by_project_coordinator){
        frappe.throw("Please mention Rejected reason by Project Manager !");
        frappe.validated = false;
       
    }
    else{
        frappe.validated = true;
         
    }
    // for account manager approval 
    if(frm.selected_workflow_action == "Send for Re-Submission" && frm.doc.workflow_state == "Submitted for Accounts Approval" && !frm.doc.reject_reason_by_accounts_manager_invoice_checker){
        frappe.throw("Please mention Reject Reason by Accounts Manager (Invoice Checker) Reason !");
        frappe.validated = false;
    }
    else{
        frappe.validated = true;
    }
    // for md approval 
    if(frm.selected_workflow_action == "Send for Re-Submission" && frm.doc.workflow_state == "Submitted for MD Approval" && !frm.doc.reject_reason_by_md_user){
        frappe.throw("Please mention Reject Reason by MD User Reason !");
        frappe.validated = false;
    }
    else{
        frappe.validated = true;
    }
    // set MD Approval date time
    if(frm.selected_workflow_action == "Approve"){
        cur_frm.doc.md_approval_date = frappe.datetime.nowdate()
    }
},

})

Thank you

@NCP
Thanks it’s working now.
But on the other hand it’s not working on local server erp which i installed few days ago.

i updated the erp and now its working thank you