Update 'date' field with today's date on workflow state change

We are using the Workflow module in ERPNext to monitor some Document states (like Initiated, Started, Ending, Closed, etc.). There are Workflow State fields named ‘Update field’ and ‘Update Value’. I would like to update the ‘actual_end_date’ field in a Document when state changes to ‘Closed’.

What I tried:
Update Field: actual_end_date
Update Value: frappe.utils.nowdate()

Update Field: actual_end_date
Update Value: datetime.datetime.now()

But this results in an error:

ValueError: ('Unknown string format:', 'datetime.datetime.now()')

Does anyone know what I’m doing wrong? How can I use the today date/time inside the Workflow States?



@stiemi you will need add a custom script, something like that

frappe.ui.form.on(cur_frm.doctype, {
    "workflow_state": frm => {
           if (frm.doc.workflow_state == "My Target State"){
               frm.set_value("actual_end_date", frappe.datetime.nowdate());


Thanks for your reply. We’ll try that, instead of doing it directly from the Workflow State ‘Update Field’ option.


Unfortunately this doesn’t work… For some reason the workflow_state change event is not triggered when the state changes using Actions → [New state name].