Tips   >   Reports   >   Dynamic Report Page Header
Ask yourself the following questions:
There is a relatively easy solution for this. Leave the page header blank in all your reports that use a standard page header and add the page header fields and text to each report instance using notation. Omnis Studio can add your standard page header fields to a report instance in the blink of an eye! The beauty of adding report page header fields on-the-fly is that if you want to make a change to the page header in your standard reports, you only have to change the code in one place and presto, all of your standard reports will immediately reflect the change.
As with anything in Omnis Studio there are many ways to accomplish the above. For this solution we are going to structure the code as follows:
The sequence of event for this solution is as follows:
To make it easy for you to edit the fields for your standard page header we will create a page header template report class.
The report tools object class contains the code which adds the template fields to the report instance.
; $constructPageHeader (method)
; Figure out the page report width.
If pfrReportInst.$orientation=kOrientPortrait
Calculate Width as (pfrReportInst.$paperwidth-pfrReportInst.$leftmargin-pfrReportInst.$rightmargin)*100/pfrReportInst.$scale
Else
Calculate Width as (pfrReportInst.$paperlength-pfrReportInst.$leftmargin-pfrReportInst.$rightmargin)*100/pfrReportInst.$scale
End If
; Find the page header template report class.
Do $clib.$classes.$findname('rPageHeader_template') Returns irTemplateRpt
If irTemplateRpt
; Print Info
Calculate FieldName as 'PrintInfo'
Do method addTemplateField (pfrReportInst,FieldName) Returns rField
If not(isnull(rField))
Do rField.$left.$assign(0)
; Page Count
Calculate FieldName as 'PageCount'
Do method addTemplateField (pfrReportInst,FieldName) Returns rField
If not(isnull(rField))
Do rField.$left.$assign(Width-rField.$width)
; Company Name
Calculate FieldName as 'CompanyName'
Do method addTemplateField (pfrReportInst,FieldName) Returns rField
If not(isnull(rField))
Do rField.$left.$assign(0)
Do rField.$width.$assign(Width)
; Title
Calculate FieldName as 'Title'
Do method addTemplateField (pfrReportInst,FieldName) Returns rField
If not(isnull(rField))
Do rField.$left.$assign(0)
Do rField.$width.$assign(Width)
; SubTitle
Calculate FieldName as 'SubTitle'
Do method addTemplateField (pfrReportInst,FieldName) Returns rField
If not(isnull(rField))
Do rField.$left.$assign(0)
Do rField.$width.$assign(Width)
; Page header notes
Calculate FieldName as 'PageHeaderNotes'
Do method addTemplateField (pfrReportInst,FieldName) Returns rField
If not(isnull(rField))
Do rField.$left.$assign(0)
Do rField.$width.$assign(Width)
Calculate FlagOK as kTrue
End If
End If
End If
End If
End If
End If
End If
Quit method FlagOK
; addTemplateField (private method)
If len(pLineMarkerName_opt)=0
Calculate pLineMarkerName_opt as con(pFieldName,'_linemarker')
End If
; Find the linemarker
Do pfrReportInst.$objs.$findname(pLineMarkerName_opt) Returns rMarker
If rMarker
; Find the template object.
Do irTemplateRpt.$objs.$findname(pFieldName) Returns rSourceField
If rSourceField
; Add the field to the report.
; $add(type[,cComponentLibrary,cComponentControl],iTop,iLeft,iHeight,iWidth) inserts a new object and returns an item reference to it
If rSourceField.$objtype=kComponent
Calculate Lib as rSourceField.$componentlib
Calculate Control as rSourceField.$componentctrl
Do pfrReportInst.$objs.$add(kComponent,Lib,Control) Returns rField
If rField
Do rField.$name.$assign(rSourceField.$name)
Do rField.$fieldstyle.$assign(rSourceField.$fieldstyle)
Do rField.$lineno.$assign(rMarker.$lineno)
Do rField.$left.$assign(rSourceField.$left)
Do rField.$width.$assign(rSourceField.$width)
Do rField.$height.$assign(rSourceField.$height)
Do rField.$align.$assign(rSourceField.$height)
End If
Else
Do pfrReportInst.$objs.$add(kEntry) Returns rField
If rField
; Copy all of the source field attributes to the target added field.
Calculate rField as rSourceField
Do rField.$fieldstyle.$assign(rSourceField.$fieldstyle)
Do rField.$lineno.$assign(rMarker.$lineno)
End If
End If
End If
End If
Quit method rField
Click the oReportTools report class. Free free to copy the object class from StudioTips to your library.
button in the to see theThe oReportTools object class in StudioTips includes a $setHorzLines method which can be called to dynamically position and stretch the horizontal lines across the report paper width.
Each standard report class will need to include the page header lines and appropriate linemarker fields for each standard page header field you want to include in the report page header.
; Construct the standard page header.
Do ioReportTools.$constructPageHeader($cinst) Returns FlagOK