Set username on change of Workflow status

Hi @Manan_Shah, I used one trick to go through exact same situation

  1. Create different roles for both users (the one that approves and other that will review) in your case u already have it “purchase User & Purchase manager, so no need to create”
  2. Assign to each of them respectively

What u need now, is to create a custom script as showed here:

But instead of using the validate function u will use the “onload” and u will check if the user have that role or not to fill the field.

note: to permanently fill the field the user must save the doc

frappe.ui.form.on("Quotation", {
  onload: (frm) => {
    if(frm.doc.workflow_state === 'Created' && frappe.user.has_role(['Purchase User'])){
      frm.doc.quote_prepared_by = frappe.session.user

    } 
      else if(frm.doc.workflow_state === 'Approved' && frappe.user.has_role(['Purchase Manager'])){
      frm.doc.quote_reviewed_by = frappe.session.user
    }
  }
});

Hope it helps.

Dércio Bobo

2 Likes