Hi,
I’m trying to get value using frappe.client.get_value from a web form.
I put the js code on the Client Script tab of the web form.
The webform is for guest so users are not logged in.
The value I try to get is a field in a custom app.
When the code runs in the webform, I got popup saying Not Permitted.
How do I get around this?
Thank you.
I tried both. What is not throwing exception anymore is to make own whitelisted API. I copied the get_single_value from frappe and giving the allow_guest=True.
But it still doesn’t work because the browser console now giving Error 500.
What I want to achieve is when a field in webform is filled with name, the code retrieve the address from a setting (single doctype) and return it to the address field in the webform.
@frappe.whitelist(allow_guest=True)
def get_alamat(doctype, field):
if not frappe.has_permission(doctype):
frappe.throw(_("No permission for {0}").format(doctype), frappe.PermissionError)
value = frappe.db.get_single_value(doctype, field)
return value
It’s tough (except in some cases) to reply to “It doesn’t work.”
Can you provide more information?
e.g. Is there a message/stack trace in the browser console? Any response included with the 500 status code? Any message/stack trace from bench start, or logs/web.log and logs/web.error.log if you’re running in production.
b'Traceback (most recent call last):\n
File "/home/frappe/frappe-bench/apps/frappe/frappe/website/render.py", line 50, in render\n
data = render_page_by_language(path)\n
File "/home/frappe/frappe-bench/apps/frappe/frappe/website/render.py", line 177, in render_page_by_language\n
return render_page(path)\n
File "/home/frappe/frappe-bench/apps/frappe/frappe/website/render.py", line 193, in render_page\n
return build(path)\n
File "/home/frappe/frappe-bench/apps/frappe/frappe/website/render.py", line 200, in build\n
return build_page(path)\n
File "/home/frappe/frappe-bench/apps/frappe/frappe/website/render.py", line 218, in build_page\n
html = frappe.render_template(context.source, context)\n
File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/jinja.py", line 80, in render_template\n
return get_jenv().from_string(template).render(context)\n
File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 76, in render\n
return original_render(self, *args, **kwargs)\n
File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/jinja2/environment.py", line 1008, in render\n
return self.environment.handle_exception(exc_info, True)\n
File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception\n
reraise(exc_type, exc_value, tb)\n
File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise\n
raise value.with_traceback(tb)\n
File "<template>", line 5, in top-level template code\n
File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/jinja2/sandbox.py", line 440, in call\n
return __context.call(__obj, *args, **kwargs)\n
File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 549, in get_single_value\n
if fieldname in self.value_cache[doctype]:\n
TypeError: unhashable type: \'list\'\n'