ERPNext.com Frappe Cloud Support Partners Foundation Frappe School

Print Preview Error {{body}}

Hello anyone!
After customizing the print format but error with this {{body}} when I click on print preview.
Source Code

Thank you.

Hi,
@Hor_Kimhab did you get it finally resolved?

In my case, this was because I had an error in my template. (I can’t see your source code)

Could you share me clear about it?

For me it turned out to be ghost entries. For asset naming series, I reset it to match the last entry, but it wanted to be about last entry + 40 which made printing started working.

make new naming series of asset

It already was a new series, and its problematic, when there are around 5k assets and naming series value corresponds already to a barcode thats on the asset

In my case, the issue comes because the duplication in the naming series of Access Log DocType,
So I had solved it by edit the naming series of Access Log from the database (the table name is tabSeries) then edit the current value of the empty name with the latest number of Access Log.

1 Like
--access your system, then users and go to access log, order by last modified (descending), check the last value, e.g. AL-233601
--Go to your frappe-bench folder on the cmd, and do as below
bench --site site1.local mariadb
--then run an update of tabSeries table as below, with the last number on the access log: AL-233601
update `tabSeries` set current=233601 where name in(" ");
--In my case, I got this error after I updated Employee naming series, while changing from using Employee Number, to Naming Series

This week, one of my clients and I discovered this problem, where PDF generation creates an empty page with {{ body }}. I want to discuss in detail, including the solution.

As others have mentioned, when you try to print a PDF, ERPNext must write a document to a DocType named Access Log. That DocType has a related MySQL table named "tabAccess Log"

If ERPNext cannot write a record to this table? Then the PDF generation fails. On your web browser, all you see is {{ body }}. That’s not helpful, because it doesn’t describe the root cause to the User. Probably the Frappe code should be improved around this.

However, if you examine the ERPNext logging on the server, the problem is described in more detail:

pymysql.err.IntegrityError: (1062, "Duplicate entry 'AL-00001' for key 'PRIMARY'")

Aha! ERPNext needs to write a record to this table. It’s trying to use a name “AL-00001.” But MySQL is throwing an error, because that number was already been used. How do we resolve?

Well, normally there would exist a Naming Series named “AL”. You could find this on the Naming Series form in ERPNext. Alternately, you could query the MySQL table directly:

SELECT name, current FROM `tabSeries` WHERE name like 'AL%'

Next, you would find the highest number in Access Log. And make sure the current value in tabSeries is greater (or equal) to that number. You can edit that in ERPNext itself on the Naming Series form.

However… that solution won’t work for Access Log. Because there is no row in “tabSeries” named “AL”.

This is because Access Log is kind of special. Its Naming Series is different. Here’s a screenshot of the “DocType” form for Access Log.

image

It uses a Naming Series option called “format”. DocTypes with “format” don’t reference unique rows in tabSeries. Instead, they share a single Naming Series row with all other DocTypes using “format”.

This special Naming Series record has a empty name (no characters) in SQL table “tabSeries.”

image

Why does “format” work this way? I don’t know. Probably some Python developer just wanted it to work that way, so you could share a global numbering.

Now that we know the correct row in tabSeries, we can fix the problem. Increment the “current” value for that row with the empty name. Make sure the value is greater than the highest name value in “Access Log” (and also, every other DocType that uses the “format” option. I had to write some code to identify that)

After I fixed this problem with the Naming Series for Access Log? All PDF documents were generated successfully. :partying_face:

~Brian

7 Likes

Interesting…

Worthy of a PR @brian_pond?

The only PR opportunity I can think of is improving the error message to the end user. Instead of displaying a {{ body }} on the PDF, open a pop-up with a meaningful message.

Otherwise, this is a one-time Data cleaning event. Once the Naming Series is updated, this problem should not happen again.

done with your suggestion, but still one of the custom print still showing {{body}} error. Adding hostname in site_config.json didn’t solve it either.

You’ll have to review the logs. Somewhere in there should be an Error message, which you can use to debug the root cause behind the {{ body }}.

there are no errors in /frappe-bench/logs