{"id":1039,"date":"2010-09-19T18:01:43","date_gmt":"2010-09-19T18:01:43","guid":{"rendered":"http:\/\/www.mrc-productivity.com\/techblog\/?p=1039"},"modified":"2023-05-12T13:23:56","modified_gmt":"2023-05-12T19:23:56","slug":"modifying-redundant-data-within-reports","status":"publish","type":"ht_kb","link":"https:\/\/www.mrc-productivity.com\/techblog\/?ht_kb=modifying-redundant-data-within-reports","title":{"rendered":"Modifying Redundant Data within Reports"},"content":{"rendered":"<p>&nbsp;<\/p>\n<h1>Modifying Redundant Data within Reports with Freemarker<\/h1>\n<p>Let&#8217;s say we have a Report coming from two tables &#8212; a header table and a detail table. If there are 20 detail records for 1 header record, that header record&#8217;s information is going to repeat 20 times, one for each detail record. See below:<\/p>\n<p><img decoding=\"async\" class=\"border\" src=\"https:\/\/www.mrc-productivity.com\/docs\/images\/redundantdata1.jpg\" alt=\"\" \/><\/p>\n<p>It is common for customers to want to see this header information listed only once. Here are two different ways to do that:<\/p>\n<p><strong>Method 1: Showing Header Information in Line Once per Section<\/strong><\/p>\n<p>After compiling your application, open m-Painter and toggle the Source code.<\/p>\n<p>Search for <code>section.lastDetail<\/code> as this will take you directly above the Detail Section.<\/p>\n<p>I will use Freemarker Functionality to only show each Header Information (customer number and customer name) once per section. Newly added code is in red Bold Face.<\/p>\n<pre><pre>\r\n&lt;!-- END_SORT_TABLE_HEADER --&gt;\r\n\r\n&lt;!-- END_REPORT_TABLE_HEADER --&gt;\r\n\r\n&lt;!--&lt;#assign var = 'x'&gt;--&gt;\r\n\r\n&lt;!-- &lt;#list report as section&gt; --&gt;\r\n\r\n&lt;!-- &lt;#assign lastRow = section.lastDetail \/&gt; --&gt;\r\n\r\n&lt;!-- &lt;#assign grandTotal = grandTotal0 \/&gt; --&gt;\r\n\r\n&lt;!--&lt;#if ( section.subtotalsc.size() &gt; 0)&gt; --&gt;\r\n\r\n&lt;!-- &lt;#assign subTotal1 = section.subtotalsc[1] \/&gt; --&gt;\r\n\r\n&lt;!--&lt;\/#if&gt; --&gt;\r\n\r\n&lt;!-- &lt;#list section.detailRows as row&gt; --&gt;\r\n\r\n&lt;tr class=\"ten\" nowrap =\"nowrap\" align=\"right\"&gt;\r\n\r\n&lt;!--&lt;#if row.CUSNO != var&gt;--&gt;\r\n\r\n${row.CUSNO?html}\r\n\r\n&lt;!--&lt;\/#if&gt;--&gt;\r\n\r\n&lt;\/td&gt;\r\n\r\n&lt;td nowrap =\"nowrap\" align=\"left\"&gt;\r\n\r\n&lt;!--&lt;#if row.CUSNO != var &gt;--&gt;\r\n\r\n${row.CNAME?html}\r\n\r\n&lt;!--&lt;\/#if&gt;--&gt;\r\n\r\n&lt;\/td&gt;\r\n\r\n&lt;td nowrap =\"nowrap\" align=\"left\"&gt;${row.PRDNO?html}&lt;\/td&gt;\r\n\r\n&lt;td nowrap =\"nowrap\" align=\"left\"&gt;${row.CLASS?html}&lt;\/td&gt;\r\n\r\n&lt;td nowrap =\"nowrap\" align=\"right\"&gt;${row.MTDUD?html}&lt;\/td&gt;\r\n\r\n&lt;\/ tr &gt;\r\n\r\n&lt;!--&lt;#assign var = row.CUSNO &gt;--&gt;\r\n\r\n&lt;!-- &lt;\/#list&gt; --&gt;\r\n<\/pre>\n<p>The Freemarker code states above that if the customer number (row.CUSNO) for the current record is not equal to the previous record&#8217;s customer number, print the Customer Number (CUSNO) &amp; the Customer Name (CNAME). Otherwise, ignore that section.<\/p>\n<p>In my case, I want to display the customer number and customer name fields only when the customer number (row.CUSNO) changes. In your case you will replace CUSNO in\u00a0&lt;!&#8211;&lt;#if row.CUSNO != var &gt;&#8211;&gt; and &lt;!&#8211;&lt;#assign var = row.CUSNO &gt;&#8211;&gt; with a field from your application. When the value of this field changes from record to record, the fields inside the freemarker #if tags will be output.<\/p>\n<p>Here is my output:<\/p>\n<p><img decoding=\"async\" class=\"border\" src=\"https:\/\/www.mrc-productivity.com\/docs\/images\/redundantdata2.jpg\" alt=\"\" \/><\/p>\n<p><strong>Method 2: Showing Header Information Above Records<\/strong><\/p>\n<p>Similar to Method 1, the Header information will only appear once, except now, we will add the header information in its own row above the Detail Section.<\/p>\n<p>I will use Freemarker Functionality to only show each Header Information once above each Detail Line. Newly added code is in red Bold Face.<\/p>\n<pre><pre>\r\n&lt;!-- END_SORT_TABLE_HEADER --&gt;\r\n\r\n&lt;!-- END_REPORT_TABLE_HEADER --&gt;\r\n\r\n&lt;!--&lt;#assign var = 'x'&gt;--&gt;\r\n\r\n&lt;!-- &lt;#list report as section&gt; --&gt;\r\n\r\n&lt;!-- &lt;#assign lastRow = section.lastDetail \/&gt; --&gt;\r\n\r\n&lt;!-- &lt;#assign grandTotal = grandTotal0 \/&gt; --&gt;\r\n\r\n&lt;!--&lt;#if (section.subtotalsc.size() &gt; 0)&gt; --&gt;\r\n\r\n&lt;!-- &lt;#assign subTotal1 = section.subtotalsc[1] \/&gt; --&gt;\r\n\r\n&lt;!--&lt;\/#if&gt; --&gt;\r\n\r\n&lt;!-- &lt;#list section.detailRows as row&gt; --&gt;\r\n\r\n&lt;!-- &lt;#if row.CUSNO != var &gt; --&gt;\r\n\r\n&lt;tr&gt;\r\n\r\n&lt;td colspan =\"3\" nowrap =\"nowrap\" align=\"left\"&gt;Customer # ${row.CUSNO?html} | Customer Name ${row.CNAME?html} &lt;\/td&gt;\r\n\r\n&lt;\/tr&gt;\r\n\r\n&lt;!-- &lt;\/#if&gt; --&gt;\r\n\r\n&lt;tr&gt;\r\n\r\n&lt;td nowrap =\"nowrap\" align=\"left\"&gt;${row.PRDNO?html}&lt;\/td&gt;\r\n\r\n&lt;td nowrap =\"nowrap\" align=\"left\"&gt;${row.CLASS?html}&lt;\/td&gt;\r\n\r\n&lt;td nowrap =\"nowrap\" align=\"right\"&gt;${row.MTDUD?html}&lt;\/td&gt;\r\n\r\n&lt;\/tr&gt;\r\n\r\n&lt;!--&lt;#assign var = row.CUSNO &gt;--&gt;\r\n&lt;!-- &lt;\/#list&gt; --&gt;\r\n<\/pre>\n<p>The Freemarker code above states that if the current record&#8217;s customer number (row.CUSNO) is not equal to the previous record&#8217;s customer number, create a new row, and a new data cell (notice that the colspan value should equal the number of columns you have). Once the data cell is created, print the Customer Number (CUSNO) &amp; the Customer Name (CNAME). Otherwise, ignore that section.<\/p>\n<p><strong>Note:<\/strong> I also removed the Customer # and Customer Name from the Detail, Subtotal, Grand Total, and Header sections.<\/p>\n<p>Here is my output:<\/p>\n<p><img decoding=\"async\" class=\"border\" src=\"https:\/\/www.mrc-productivity.com\/docs\/images\/redundantdata3.jpg\" alt=\"\" \/><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Modifying Redundant Data within Reports with Freemarker Let&#8217;s say we have a Report coming from two tables &#8212; a header table and a detail table. If there are 20 detail records for 1 header record, that header record&#8217;s information is going to repeat 20 times, one for each detail&#8230;<\/p>\n","protected":false},"author":1,"comment_status":"closed","ping_status":"open","template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[],"ht-kb-tag":[],"class_list":["post-1039","ht_kb","type-ht_kb","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/ht-kb\/1039","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1039"}],"version-history":[{"count":21,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/ht-kb\/1039\/revisions"}],"predecessor-version":[{"id":10208,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/ht-kb\/1039\/revisions\/10208"}],"wp:attachment":[{"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1039"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=%2Fwp%2Fv2%2Fht-kb-category&post=1039"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=%2Fwp%2Fv2%2Fht-kb-tag&post=1039"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}