Add Workflow action buttons to Email Notification

Hi,

I made an Email Notification,
when a user create a PO, an email send to order approver user.

I want to add Work flow Action buttons to this notification email like the one in Email Template

I need to know the html code for that.

Thanks

1 Like

I asked this same question for several years and never got an answer. It will be interesting to see if you will get what I didn’t.

This isn’t a public-facing feature, but it can definitely be done. You’d could use the existing method defined here:

You’d need to generate a signature key, I believe. I’m not sure how to do that off-hand, but it should be possible to find examples in the source code.

Thanks for replying, but I am using notification email, So i think i need to add kind of code in to HTML section. can I do it ?

Yes, the email content is generated using jinja templating, which can include Python functions.

did you solve your point ?

Unfortunately no

@Ahmed_Moustafa2 these days I was looking for a similar solution and I succeeded.
In the same python file linked by @peterg, you can find ‘get_workflow_action_url’ method.

By creating a similar method in a custom Python file, in a custom app, prefixing the @frappe.whitelist() decorator, you can create a callable method that can return a URL to interact with the workflow of a document.

# Remeber to import required modules
from frappe.utils import get_url
from frappe.utils.verified_command import get_signed_params

@frappe.whitelist()
def get_workflow_action_url(action, user, pdanum, current_state):
	apply_action_method = (
		"/api/method/frappe.workflow.doctype.workflow_action.workflow_action.apply_action"
	)

	params = {

		"doctype": 'Purchase Order', # hard-coded in my case, you can pass it as an argument if you prefer
		"docname": pdanum, # an argument in my case, you can hard-code it if you prefer
		"action": action, # an argument in my case, you can hard-code it if you prefer
		"current_state": current_state, # an argument in my case, you can hard-code it if you prefer
		"user": user # an argument in my case, you can hard-code it if you prefer
	}
    # this will return you an URL to use in the href of the e-mail button
	return get_url(apply_action_method + "?" + get_signed_params(params))

The generated link will look like this:
https://yoursite.com/api/method/frappe.workflow.doctype.workflow_action.workflow_action.apply_action?doctype=Purchase+Order&docname=PUR-ORD-2022-00033&action=Approve&current_state=Pending&user=Administrator&_signature=[AUTO-GENERATED TOKEN]

By opening the link it will be possible to interact with the document workflow
image

3 Likes