How to code Update Value in workflow

Hi, I’m doing a date update in one of my fields. The field is a Date data type and what I want to happen is that when the user changes the worflow_state the Date field would update to the current date. how can I do that?

Hi @Rabie_Moses_Santilla,

If the worflow_state trigger does not work then use before_save.

Thanks.

Hi Rabie

For ex your workflow state draft means below code use that condition
if self.workflow == “Draft”:
filed_name = now_datetime()

Hello,
I have developed similar code to update date, when workflow is executed and doc status changes. How to use ‘before_save’ here to achieve the goal?

frappe.ui.form.on('Purchase Order', {
	before_workflow_action: (frm) => {
    if(frm.selected_workflow_action === 'Submit for Approval'){
      frm.doc.custom_created_by = frappe.session.user,
      frm.doc.custom_created_time = frappe.datetime.now_datetime()
    } 
      else if(frm.doc.workflow_state === 'Approve'){
      frm.doc.custom_approved_by = frappe.session.user,
      frm.doc.custom_approved_time = frappe.datetime.now_datetime()
    }
    frm.save();
	}
});

Comment: It just shows values on the screen, but they are not saved in database.

please check the reference of before_save.

Another reference: