How to use jinja tag in this case. it is returning [object object]

in a custom report’s print format .this {{ frappe.get_all (“Bank Account”, filters={‘bank’:bank}, “bank_account_no”) }} is fetching correctly but showing [object object] in the html template. how to achieve this ?
i have also tried with js function and it is showing same output

{% var bank = filters.bank_name; %}
 our Bank Account No.: <strong>
{{ frappe.get_all ("Bank Account", filters={'bank':bank}, "bank_account_no") }}
</strong> 
in the name of maintained with your bank.</p>

Why you are using frappe.get_all ?

@Usama_Naveed i tried using get_value and get_doc . it was not working . this was the last function i tried . that’s why it is there .

Use this for getting single value

frappe.db.get_value('Bank Account', {'bank':bank}, 'bank_account_no')

it shows up with this error
microtemplate.js:104 Uncaught TypeError: frappe.template.compile(…) is not a function

Where you are using in Custom Print Format or Report Print?

report print . i created an html file in the same directory of the custom report’s js and py file. and i am doing the temple-ting there

In the HTML file of report these methods are not worked.

For this case you can do one thing.

Write code before return of execute function in .py file

get the account no there and add in the dict of filters.

fetch from filters.fieldname in the HTML File

1 Like
{{frappe.get_all (doctype="Bank Account", filters={'bank':bank}, fields="bank_account_no")[0].bank_account_no}}

Try this and check if it works for you; it worked for me.

@ejaaz did you do it for a report’s print format ?

@Usama_Naveed something like this ? it is printing correctly but for some reason it is not showing up empty in my html template ? i have used filters.bank_name which is a filter in the report it showed up correctly

def execute(filters=None):
    if not filters:
        filters = {}

    # Default to the current month and year if not provided
    if not filters.get("month"):
        filters["month"] = datetime.datetime.now().month

    if not filters.get("year"):
        filters["year"] = datetime.datetime.now().year



    if filters.get("bank_name"):
        name_of_bank = filters.get('bank_name')
        bank_account_no = frappe.db.get_value("Bank Account", {"bank": name_of_bank}, "bank_account_no")
        if bank_account_no:
            filters["bank_account"] = bank_account_no
            print('>>>>>>>>>>>>>>>>>>.11')
            print(filters["bank_account"])
        else:
            filters["bank_account"] = "N/A"  # Handle missing bank account case
    else:
        filters["bank_account"] = "N/A"

    columns = get_columns()
    data = get_data(filters)

    return columns, data

I did this in Jinja print format.
Are you encountering any issues with the code I provided?

@ejaaz it is not rendering the template . i think this works with Print formats for doctypes not with Report’s

Hi @rik_sanchez

try to print filters dict in the html template.

then we will get idea. is it going into HTML template or not

Do some debugging; try printing in different ways.

{{frappe.get_all (doctype="Bank Account", filters={'bank':bank}, fields="bank_account_no")[0]}}
{{frappe.get_list (doctype="Bank Account", filters={'bank':bank}, fields="bank_account_no")}}
{{frappe.get_list (doctype="Bank Account", filters={'bank':bank}, fields="bank_account_no")[0]}}

@Usama_Naveed yes . it is not being passed to html

i printed it . it is only passing month ,year and bank_name
Screenshot from 2024-10-15 11-30-32

were you able to use these in a report’s Html format ? @ejaaz

Try using it in HTML file.

1 Like