Getting company_name from another doctype

Hi, I tried and searched the last 3 hours to solve my problem, but I didn’t find a proper solution.

I’m creating a standard printing format, where people can insert their own letter head, but don’t have to.
If they don’t, a standard header should be shown instead, that also show the correct company_name (and logo).
I’m trying to get the the company_name via: {{ frappe.db.get_value(“setup”, “Company”, “company_name”) }}
but only “None” is returned.

Where is my mistake?

Thanks for your help!

From which document are your trying to get company name?

The syntax is

frappe.db.get_value(doctype, docname, fieldname)

Thanks for your quick answer!

I made it now with :{{ frappe.db.get_value(“Company”, “example company”, “company_name”) }}

But now my problem is to get “example company” dynamically. My idea is to get it from “Global Defaults” → “default_company”, but {{ frappe.db.get_value(“Global Defaults”, “default_company”) }} returns “Global Defaults”

How can I get this value?

Other topic:
Would something like { frappe.db.get_value(“Company”, frappe.db.get_value(“Global Defaults”, “default_company”), “company_name”) }} work in general?

Thank you!

1 Like

@eldorim , Try with following code -

{{ frappe.db.get_value(“Company”, frappe.db.get_value(“Global Defaults”, None, “default_company”), “company_name”) } }

5 Likes

Thanks!!! This works :slight_smile:

A better way of doing this would be frappe.db.get_single_value(“Global Defaults”, “default_company”)

Thank you Neil, but are you sure? I get an exception with this call. Seems like the function is unknown

What is the exception msg ?

Traceback (innermost last):
File “/home/justadmin/frappe-bench/apps/frappe/frappe/app.py”, line 67, in application
response = frappe.handler.handle()
File “/home/justadmin/frappe-bench/apps/frappe/frappe/handler.py”, line 77, in handle
execute_cmd(cmd)
File “/home/justadmin/frappe-bench/apps/frappe/frappe/handler.py”, line 94, in execute_cmd
ret = frappe.call(method, **frappe.form_dict)
File “/home/justadmin/frappe-bench/apps/frappe/frappe/init.py”, line 788, in call
return fn(*args, **newargs)
File “/home/justadmin/frappe-bench/apps/frappe/frappe/templates/pages/print.py”, line 139, in get_html_and_style
no_letterhead=no_letterhead, trigger_print=trigger_print),
File “/home/justadmin/frappe-bench/apps/frappe/frappe/templates/pages/print.py”, line 118, in get_html
html = template.render(args, filters={“len”: len})
File “/home/justadmin/frappe-bench/env/local/lib/python2.7/site-packages/jinja2/environment.py”, line 989, in render
return self.environment.handle_exception(exc_info, True)
File “/home/justadmin/frappe-bench/env/local/lib/python2.7/site-packages/jinja2/environment.py”, line 754, in handle_exception
reraise(exc_type, exc_value, tb)
File "

I have added frappe.db.get_default to jinja.py, so in next release you should be able to do frappe.db.get_default("company_name")

6 Likes

frappe.db.get_value(“Global Defaults”, None, “default_company”) works!!

1 Like