I would like to set a new page per group on my report. Actually, the report, is group by three fields(Fund No, Shortcut Dimension 2 Code, Shortcut Dimension 3 Code) from Purchase Line Table. So, under the group footer, I put the following code into it: Purchase Line, GroupFooter (4) - OnPreSection() IF CurrReport.TOTALSCAUSEDBY IN [FIELDNO(“Fund No.”), FIELDNO(“Shortcut Dimension 3 Code”)] THEN CurrReport.SHOWOUTPUT(FALSE); IF CurrReport.TOTALSCAUSEDBY IN [FIELDNO(“Fund No.”), FIELDNO(“Shortcut Dimension 3 Code”), FIELDNO(“Shortcut Dimension 2 Code”)] THEN CurrReport.NEWPAGE; When I preview the report, the group footer will be printed separately on the next page, not on the same page as the group header and body do. Do u know why and how to solve it? Thanks!
Iris, the OnPreSection trigger gets called before the section actually get’s printed, therefore calling a “CurrReport.NEWPAGE” will insert the page break before the section itself gets printed. You solve this by adding a new GroupFooter, Width = 0, witout any fields, where you simply add your code in the OnPreSection trigger as before.
Thanks Nil, The whole group(Group Header and Group) Footer finally is printed on the same page, but, I donno why there is still a blank page between each group? Can you help me with this again? Thanks! Iris
Iris, similiar to your previous topic with the group headers, you’ll have to ask which field you actually “group by”. Even if you print 3 fields (Fund No, Dimension 2, Dimension 3) this does not mean that you group by these 3 fields. As you print the group header section only for groups caused by Dimension 2, I assume that you really group by “Dimension 2”. I’d rather review the group total property of you report and stick to the only field that in fact triggers your group. Otherwise, just modify your CurrReport.NEWPAGE code like this:
IF CurrReport.TOTALSCAUSEDBY = FIELDNO("Shortcut Dimension 2 Code") THEN CurrReport.NEWPAGE; Saludos Nils
Thanks Nil, I group it by three fields – Fund No, Dimension 3, Dimension 2. So, I put them also into GroupTotalFields. So, what should I do if I wanna group the report by the above three fields and not only one field?
Hi, Maybe not a direct answer to your problems, but I have tip. I also rumbled with grouping in reports and to understand it all I used the report-wizard “Tabular-Type Report Wizard”. Look at the properties and the C/AL-code in the various triggers. It helped me to understand grouping better. Too bad you have to use C/AL-code to accomplish grouping. [:(] Would be nice if setting properties was enough.
So, what should I do if I wanna group the report by the above three fields and not only one field?
Please use the code I posted in my previous reply, in fact you have to make sure that you create a new page only once, not three times… (IF CurrReport.TOTALSCAUSEDBY = FIELDNO(“Shortcut Dimension 2 Code”) THEN CurrReport.NEWPAGE;) Tino’s suggestion is really helpful, and have a look at the Application Designer’s Guide, especially the flow chart part on reports at the end. Saludos Nils
Thanks tinoruijs, your suggestion is really good! I use the wizard to make the report, it works! Thanks Nil, I follow your code, it has a page break between each group, but, the only problem I left here is there is a blank page at the end of the report, I cannot take it out, do you know why?
… the last group footer will raise the new page, no matter if there are more records to print or not. This is actually always the problem with grouped reports, to handle the new pages. In your case, I would rather control the page break before a new group header is printed, instead of inserting a page break after a group footer. When you create a new grouped report with the wizard, you’ll have a complete code example on how to handle this, with the variables LastFooterPrinted and so on. This will me much easier to achieve than to avoid the last page break if there are no more record to process - this is also possible, by creating a new variable on the same dataitem, copy the current record to this new variable, and checking if there are records left to process before inserting the new page. Saludos Nils
I don’t fully understand how to control the page break in Group Header, coz I tried it, it still gives me a page break at the very beginning page. Can you specify the steps? Thanks!
As suggested Tino before, create a simple grouped report with the wizard. Copy all the code that has to do with the grouping (variables with FooterPrinted and LastFieldNo) to your existing report. In a new group header, without any fields you put the following code:
IF FooterPrinted THEN CurrReport.NEWPAGE; This means, that a new page will only be inserted if a Footer has been printed previously, and therefore you won’t have a blank first page.