Try ERPNext Buy Support Partners Foundation Foundation Members

Creating a custom prompt for reason of rejection

Hi all,

Creating a custom script to prompt user to fill reason of rejection, when the action is rejected but the script is not working.
This is the code i am using:

frappe.ui.form.on('Purchase Order', {
refresh(frm) {
    if (frm.doc.workflow_state && frm.doc.workflow_state.indexOf("Rejected") > 0){
	frappe.prompt([
{'fieldname': 'rejection_reason', 'fieldtype': 'Small Text', 'label': 'Reason', 'reqd': 1}  
],
function(values){
    show_alert(values, 5);
},
'Reason for Rejection',
'Submit'
);
}
	}
});

Can someone tell me what is wrong?

can you show me your console log?

i think the problem is this frm.doc.workflow_state.indexOf("Rejected")

what do you want to reach with?

{'method_name': 'send_workflow_action_email', 'log': <function log at 0x7f2a5beba510>, 'retry': 0, 'is_async': True, 'user': 'Administrator', 'kwargs': {'users_data': [{'possible_actions': [{'action_name': 'Reject', 'action_link': 'http://13.232.57.91/api/method/frappe.workflow.doctype.workflow_action.workflow_action.apply_action?doctype=Purchase+Order&docname=PUR-ORD-2019-00004&action=Reject&current_state=Pending&user=govindjangidsj%40gmail.com&last_modified=2019-10-16+16%3A33%3A06.690518&_signature=76b7891b949d3230577e90a4126ecead'}, {'action_name': 'Approve', 'action_link': 'http://13.232.57.91/api/method/frappe.workflow.doctype.workflow_action.workflow_action.apply_action?doctype=Purchase+Order&docname=PUR-ORD-2019-00004&action=Approve&current_state=Pending&user=govindjangidsj%40gmail.com&last_modified=2019-10-16+16%3A33%3A06.690518&_signature=b55dc0072f6da862228d52ac14067781'}], 'email': 'govindjangidsj@gmail.com'}, {'possible_actions': [{'action_name': 'Reject', 'action_link': 'http://13.232.57.91/api/method/frappe.workflow.doctype.workflow_action.workflow_action.apply_action?doctype=Purchase+Order&docname=PUR-ORD-2019-00004&action=Reject&current_state=Pending&user=purchase%40mahaveergroup.net&last_modified=2019-10-16+16%3A33%3A06.690518&_signature=384f6da8eb4f3134ea2f52d197194feb'}, {'action_name': 'Approve', 'action_link': 'http://13.232.57.91/api/method/frappe.workflow.doctype.workflow_action.workflow_action.apply_action?doctype=Purchase+Order&docname=PUR-ORD-2019-00004&action=Approve&current_state=Pending&user=purchase%40mahaveergroup.net&last_modified=2019-10-16+16%3A33%3A06.690518&_signature=5f68641dec157e7d2bb8b4ab8a98d2f6'}], 'email': 'purchase@mahaveergroup.net'}, {'possible_actions': [{'action_name': 'Reject', 'action_link': 'http://13.232.57.91/api/method/frappe.workflow.doctype.workflow_action.workflow_action.apply_action?doctype=Purchase+Order&docname=PUR-ORD-2019-00004&action=Reject&current_state=Pending&user=tushar.sharma%40mahaveergroup.net&last_modified=2019-10-16+16%3A33%3A06.690518&_signature=4e3bbc7540df21d6c23385dc2cc9b7c4'}, {'action_name': 'Approve', 'action_link': 'http://13.232.57.91/api/method/frappe.workflow.doctype.workflow_action.workflow_action.apply_action?doctype=Purchase+Order&docname=PUR-ORD-2019-00004&action=Approve&current_state=Pending&user=tushar.sharma%40mahaveergroup.net&last_modified=2019-10-16+16%3A33%3A06.690518&_signature=d5b7bc2bc2938fdc723974b7b9128dcf'}], 'email': 'tushar.sharma@mahaveergroup.net'}], 'doc': <erpnext.buying.doctype.purchase_order.purchase_order.PurchaseOrder object at 0x7f2a58125ba8>}, 'job_name': '<function send_workflow_action_email at 0x7f02c73d32f0>', 'event': None, 'method': <function send_workflow_action_email at 0x7f2a580e48c8>, 'site': 'site1.local'}
Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/pdf.py", line 25, in get_pdf
    filedata = pdfkit.from_string(html, False, options=options or {})
  File "/home/frappe/frappe-bench/env/src/pdfkit/pdfkit/api.py", line 68, in from_string
    return r.to_pdf(output_path)
  File "/home/frappe/frappe-bench/env/src/pdfkit/pdfkit/pdfkit.py", line 140, in to_pdf
    raise IOError('wkhtmltopdf reported an error:\n' + stderr.decode('utf-8'))
OSError: wkhtmltopdf reported an error:
Exit with code 1 due to network error: HostNotFoundError


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/background_jobs.py", line 99, in execute_job
    method(**kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/workflow/doctype/workflow_action/workflow_action.py", line 195, in send_workflow_action_email
    common_args = get_common_email_args(doc)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/workflow/doctype/workflow_action/workflow_action.py", line 283, in get_common_email_args
    'attachments': [frappe.attach_print(doctype, docname , file_name=docname)],
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1399, in attach_print
    "fcontent": get_print(doctype, name, print_format=print_format, style=style, html=html, as_pdf=True, doc=doc, no_letterhead=no_letterhead, password=password)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1376, in get_print
    return get_pdf(html, output = output, options = options)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/pdf.py", line 32, in get_pdf
    if ("ContentNotFoundError" in e.message
AttributeError: 'OSError' object has no attribute 'message'

Not sure whether this is the right log, but this is the one that is getting generated…

I dont think so…

but what do you want to query with frm.doc.workflow_state.indexOf("Rejected").
this clause is the problem, without that, the prompt will work. if you can tell me what you want with this clause, maybe i can tell you a better clause :wink:

Try this, it should work :wink:

frappe.ui.form.on('Purchase Order', {
	refresh(frm) {
		if (frm.doc.workflow_state && cur_frm.doc.workflow_state == 'Rejected'){
			frappe.prompt([
				{'fieldname': 'rejection_reason', 'fieldtype': 'Small Text', 'label': 'Reason', 'reqd': 1}  
				],
				function(values){
					show_alert(values, 5);
				},
				'Reason for Rejection',
				'Submit'
			);
		}
	}
});
3 Likes