I am trying to capture which user Created the Doctype, let’s say Quotation and which Manager Approved the Quotation.
I am using the Update Value function in Workflow to update a custom field with the Workflow Status since I don’t want to override the default Status (Draft, Open,etc)
[Workflow screenshots]
Since I want to capture the Current user’s name on change of Workflow State, I think the username will have to be set on certain event. What event should I use to set the username? Also I am assuming this will have to be done via Server side custom script.
What is the best way to do it @tmatteson ? Thanks for your help.
@asd’s solution is likely going to be the most simple, but it isn’t the only path. And to implement it as a customization (since this is a standard ERPNext doctype), you would want to do it with a document hook.
frappe.session.user is an available javascript object and would likely fit your needs. If you are running on ERPNext.com then this is easier to implement as a custom script.
I don’t think your setting of all the ‘Update Field’ and ‘Update Value’ columns are having the intended effect. I rarely use these fields.
If you need to override the workflow action logic entirely, here’s a pattern for that, but this approach is surgery, not applying hand lotion; I would not recommend it for any but the most extreme cases.
Thanks @tmatteson and @asd for your help.
However, we have tried these solutions and the problem is validate event is not called when the workflow state changes since you are not saving the document per se.
If someone can point towards which event is triggered on change of workflow state that will help.
Hi @Manan_Shah, I used one trick to go through exact same situation
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”
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
Only because I made this mistake today (and well, many other days) you need to check if the quote_prepared_by already has a value. Using onload or validate without checking will overwrite and when you go to view the submitted document again you’ll have a “cannot change ‘quote_prepared_by’ after submission” problem.
Go to Customize Form and select “In List View” for the custom field you want to show on the List view.
You may have to remove unwanted fields if you have too many fields on List View
@Manan_Shah Did this solution work for you?
Or you used some other method to achieve the goal of adding quotation created by and approved by usernames in the doc?