Frappe workflow actions

Hi team,
I am trying to add events on top of a workflow in frappe. When user tries to execute a workflow action, then I should be able to capture a value in the field. I am not able to do that.

Explanation:

Frappe provides a support to write an event function “before_workflow_action” before the workflow is executed. I used this trigger and returned a promise. Now if I try to modify any value inside before_workflow_action using
frm.doc.field1 = “new_value”
my field1 is not changed. I think it is because the frm was already read before it enters this before_workflow_action. So I tried to use
frappe.client.set_value to change the value of field1 to ‘new_value’
But if I do this after I resolve the promise in the before_workflow_action, the next workflow is not getting executed and it failing saying that the document has been modified after you opened it. Try after refreshing the page.

Just FYI:

  1. I am using frappe.ui.Dialog to capture the value of the field.
  2. And also in order to make the frappe.ui.Dialog work, I unfreezed the frappe dom.

You can use the following apporach

frappe.ui.form.on('Doctype Name', {
    before_workflow_action: async(frm) => {
        if (frm.doc.workflow_state === 'Some Condition if you want') {
			let promise = new Promise((resolve, reject) => {
			    let dialog = new frappe.ui.Dialog({
                });
                dialog.show();
            })
			frappe.dom.unfreeze();
			await promise.catch(() => {
				throw '';
			});
			frm.reload_doc();
		}
	}
});