ArcherPoint Dynamics NAV Business Central Developer Digest - vol 341
In this edition of Developer Digest, we go deep into a problem with printing a report from the Sales Header in Microsoft Dynamics Business Central.
The Dynamics NAV and Business Central community, including the ArcherPoint technical staff, is made up of developers, project managers, and consultants who are constantly communicating, with the common goal of sharing helpful information with one another to help customers be more successful.
As they run into issues and questions, find the answers, and make new discoveries, they post them on blogs, forums, social media…so everyone can benefit. We in Marketing watch these interactions and never cease to be amazed by the creativity, dedication, and brainpower we’re so fortunate to have in this community—so we thought, wouldn’t it be great to share this great information with everyone who might not have the time to check out the multitude of resources out there? So, the ArcherPoint Microsoft Dynamics NAV Developer Digest was born. Each week, we present a collection of thoughts and findings from NAV/BC experts and devotees around the world. We hope these insights will benefit you, too.
Problem with Printing a Report from the Sales Header in BC
Ian inquires: “I have a problem with a report (pick list) for a customer where it’s doing something very weird. The customer is using Business Central SaaS. The report is based off the Sales Header, and it prints fine every time if you print them individually. However, if you print a range of Sales Headers, the problem occurs. So far, it seems to only happen on one specific Sales Order, but I cannot tell what is causing it. The problem is that the particular Sales Order causes the report to print two pages; not a big deal, but if that order is included in the range you are printing, then you will have a problem. All the lines show up properly on both pages. However, the header on the second page advances to the next header in sequence. Then, the headers going forward are wrong for the lines. Also, that second page has the correct “Page No.”, so I know the report thinks that it’s the second page within the group, but the header data is from the upcoming Sales Header in sequence.
Things I’ve tried include:
- Moving the SetData function to different lines (specifically lines that are from detail line), and it doesn’t make a difference.
- Verifying that SetData is only being set once and is within the grouping of the Header No., so it should be passing the correct header data.
- Flattening out the groups down to Header and Details (there used to be four groups)
- Checking the values being passed to the header for invalid characters, but there aren’t any. I was thinking this might have been confusing the SetData function.
- Writing additional code to check for the page no. and then only print the header data from the first page on the second, third, fourth page, etc. by checking the PageNumber global variable. That seemed to work, but when I tested it, I noticed other headers getting out of sequence. I might revisit this solution, though.
If you can help me figure this out, I will pay you 5 bucks!!”
Len responds: “Ian, just a suggestion in the meantime: Try not using SetData. Just create new row at the top of the table and make it Hidden. For now, try just putting one of the fields (like Sell-to Customer Name) in a field in this row (as Fields!FIELDNAME.Value) and give this new field a name (I usually use the same name as the FIELDNAME). Change one of the expressions in the Sell-to fields from GetData… to ReportItems!FIELDNAME.Value. See if that works; couldn’t hurt. This will pull the data from the name of the field on the report. If it does work, it could be that SetData just isn’t called in the correct place; my reports are all rewritten using ReportItems!FIELDNAME.Value now instead of using the SetData…I hate that! 🙂 Just a thought if you want to play around in the meantime.
Ian replies: “Here is an update on this. I tried SOOO many things, but I finally got it working correctly. I think it boils down to one thing (removing the header rows), but here are the last two things I did. I removed all Header rows within the table, and I removed all other nested tables and created new groups to handle repeating rows. I think those Sales Header rows were somehow causing it to jump to the next header even though the lines from the previous Sales Order weren’t finished printing. The odd thing is that the page numbers were always correct which were connected to the top group (Sales Header No.). It didn’t have anything to do with the margins as they were always set correctly, and I also left the SetData in, but I moved it down to the next group (which I had already tried anyway). Whew… confidence hit on this one!!”
Figure 1 – Printing from the Sales Header in Microsoft Dynamics Business Central
If you are interested in Dynamics NAV and Business Central development, be sure to see our collection of NAV/BC Development Blogs.
Read the “How To” blogs from ArcherPoint for practical advice on using Microsoft Dynamics NAV and Dynamics 365 Business Central.