Capturing Name of Approver of Workflow Action that Submits a Document

Hi,

We seem to struggling more than we should about this:

Let’s say there is a Workflow action that submits a document (say a Purchase Order). All we want is for the name of the person (carrying out the workflow action that submitted the document) to be captured in a custom field of the document.

Is is possible to do this? If yes, how.

We tried to replicate the suggestions in this link: After workflow action, but without too much success.

Thanks

Jay

if you only need to make the submit user name available on print format, maybe you can refer to the below monkey patch

in print format you can use {{doc.get_submit_username()}}

you can access the source erpnext_oob/monkey_patches/base_document.py · 余则霖/ERPNext开箱即用 - Gitee.com

I’m using this to get the Approve User and Date

{% set approve_user, approve_date = frappe.db.get_value(“Comment”, {“reference_name”: doc.name, “content”: “Approved”}, [“owner”, “modified”]) %}

Hope that help

This is possible. I created three fields: a check field, a data field for storing the person’s name, and a date field to hold the date. All three fields are filled and saved BEFORE the workflow action is triggered. See the image below:

See the JS code below:

frappe.ui.form.on(‘Leave Application’, {
 sick_leave_approval_check:function (frm) {
       if (frm.doc.sick_leave_approval_check == 1){
           frm.set_value({
        sick_leave_approved_by: frappe.session.user_fullname,
        sick_leave_approval_date: frappe.datetime.nowdate()
 });
       }
       
if (frm.doc.sick_leave_approval_check !== 1){
           frm.set_value({
        sick_leave_approved_by: null,
        sick_leave_approval_date: null
           });
       }        
}
});

Hey @Syd
But in this solution, the user has to manually activate the checkbox before any workflow action.

Did you find a solution where these fields are populated and filled by the workflow button (Submit/Approve/Verify, etc.)

Please post solution if achieved this result. Thanks

Thanks @Syd. Your solution helped me develop this!

frappe.ui.form.on('Purchase Order', {
    validate: (frm) => {
        
        // Doc Creation:
        if (!frm.doc.custom_created_by && frm.doc.workflow_state === 'Draft') {
            frm.doc.custom_created_by = frappe.session.user,
            frm.doc.custom_created_time = frappe.datetime.now_datetime();
        }

        // Doc Verification:
        else if ((frm.doc.custom_read_and_verified == 1) && (frm.doc.workflow_state === 'Verification Pending')){
            frm.doc.custom_verified_by = frappe.session.user,
            frm.doc.custom_verified_time = frappe.datetime.now_datetime();
        }
        else if ((frm.doc.custom_read_and_verified != 1) && (frm.doc.workflow_state === 'Verification Pending')){
            frm.doc.custom_verified_by = null,
            frm.doc.custom_verified_time = null
        }

        // Doc Approval:
        else if ((frm.doc.custom_read_and_approved == 1) && (frm.doc.workflow_state === 'Approval Pending by Manager')){
            frm.doc.custom_approved_by = frappe.session.user,
            frm.doc.custom_approved_time = frappe.datetime.now_datetime();
        }
        else if ((frm.doc.custom_read_and_approved != 1) && (frm.doc.workflow_state === 'Approval Pending by Manager')){
            frm.doc.custom_approved_by = null,
            frm.doc.custom_approved_time = null
        }
    }
});

The verifier and approver just has to tick the checkbox and save doc before making the next workflow action of verification/approval.