Help with reporting function

Other discussions about CSPro
Forum rules
New release: CSPro 8.0
Post Reply
Don
Posts: 55
Joined: February 15th, 2013, 1:28 pm
Location: Barbados

Help with reporting function

Post by Don »

Hi, I'm having trouble with the report and setreportdata functions. I created a report template and tried running a report, but I just get a blank web page. This is my template.

Code: Select all

<div id="cspro_report"></div>
<script type="application/vnd.cspro.report-template" id=cspro_report_template">
	<h2>Continuous Labour Force Sample Survey Field Officer Enumeration Report<h2>
	<h3>Name of field officer: {{ERFIELD_OFFICER}}</h3>
	<h3>Week ending: {{WEEK_ENDING}}</h3>
	<h3>ED No: {{ERED_NO}}</h3>
	<h3>Parish: {{ERPARISH}}</h3>
	
	<table>
		<tr><th>Unit No</th><th>Serial No</th><th>Head of Household Last name</th><th>Head of Household First Name</th><th>Address of Head of Household</th><th>Date Started</th><th>Date Completed</th><th>Remarks</th></tr>
		{{#ENUMERATIONREPORT_REC}}
			<tr><td>{{ERUNIT_NO}}</td><td>{{ERSERIAL_NO}}</td><td>{{ERLAST_NAME}}</td><td>{{ERFIRST_NAME}}</td><td>{{ERADDRESS}}</td><td>{{ERSTART}}</td><td>{{EREND}}</td><td>{{ERREMARKS}}</td></tr>
		{{/ENUMERATIONREPORT_REC}}
	</table>
</script>
I try to run it in my menu app with this code

Code: Select all

//fills enumeration report and opens for editing
function enumerationRpt()
	setreportdata(ENUMERATIONREPORT_REC);
	report("../Reports/enumeratorrpt.html");
end;
I would like to end up with a report that basically lists each case in ENUMERATIONREPORT_REC. How do I accomplish that?
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Help with reporting function

Post by Gregory Martin »

One issue in what you posted is that there is no " after the id before cspro_report_template. It should say:

<script type="application/vnd.cspro.report-template" id="cspro_report_template">
Don
Posts: 55
Joined: February 15th, 2013, 1:28 pm
Location: Barbados

Re: Help with reporting function

Post by Don »

That seemed to solve part of the problem. I'm now seeing the static text from the template when I run it. However, I'm not seeing any of the data that should have replaced anything between the curly brackets. Is there anything else that I must do?
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Help with reporting function

Post by Gregory Martin »

Are you calling setreportdata on ERFIELD_OFFICER, WEEK_ENDING, etc.? If not, those won't be defined.

If you want, post your application, or send it to cspro@lists.census.gov, and we can look at it further.
Don
Posts: 55
Joined: February 15th, 2013, 1:28 pm
Location: Barbados

Re: Help with reporting function

Post by Don »

Thanks, I'll email it to you.
Don
Posts: 55
Joined: February 15th, 2013, 1:28 pm
Location: Barbados

Re: Help with reporting function

Post by Don »

Just updating for posterity.

My issue was that I needed to load the cases using forcase or loadcase before calling setreportdata(). Therefore I used the following code to loop through the cases and load the ones for the ED that I wanted. It loads the data for each case into an array and then that array is used to display the data in the report.

Code: Select all

string array reportarray(50,10);
 
function enumerationRpt()
     recode ME_ED    =>   parish;         //recode ed to parish
           1-181      =>   201; //St. Michael
           182-295    =>   202; //Christ Church
           196-335    =>   203; //St. George
           336-397    =>   204; //St. Philip
           398-418    =>   205; //St. John
           419-479    =>   206; //St. James
           480-508    =>   207; //St. Thomas
           509-521    =>   208; //St. Joseph
           522-532    =>   209; //St. Andrew
           533-559    =>   210; //St. Peter
           560-583    =>   211; //St. Lucy
     endrecode;
     numeric i = 1;
     forcase ENUMERATIONREPORT_DICT where ERED_NO = ME_ED do          //for each case in enumeration report in the current ED
           reportarray(i,1) = getlabel(ERFIELD_OFFICER_VS1,ERFIELD_OFFICER);     //field officer
           reportarray(i,2) = maketext("%d",ERUNIT_NO);
           reportarray(i,3) = maketext("%d",ERSERIAL_NO);
           reportarray(i,4) = maketext("%d/%d/%d",ERWEEKYEAR,ERWEEKMONTH,ERWEEKDAY);                            //week ending
           reportarray(i,5) = ERLAST_NAME;
           reportarray(i,6) = ERFIRST_NAME;
           reportarray(i,7) = ERADDRESS;
           reportarray(i,8) = maketext("%d/%d/%d",ERSTARTY,ERSTARTM,ERSTARTD);
           reportarray(i,9) = maketext("%d/%d/%d",ERSTARTY,ERSTARTM,ERSTARTD);
           reportarray(i,10) = ERREMARKS;
           
           inc(i);
     endfor;
 
     setreportdata("PARRPT",maketext("%d",parish));
     setreportdata("EDRPT", maketext("%d",ME_ED));
     setreportdata(reportarray);
     report("../Reports/enumeratorrpt.html");
end;
The report template was changed to read the data from an array instead:

Code: Select all

<div id="cspro_report"></div>
<script type="application/vnd.cspro.report-template" id="cspro_report_template">
	<h2>Continuous Labour Force Sample Survey Field Officer Enumeration Report<h2>
	<h3>ED No: {{EDRPT}}</h3>
	<h3>Parish: {{PARRPT}}</h3>
	
	<table border="1">
		<tr><th>Name of field officer</th><th>Unit No</th><th>Serial No</th><th>Week ending</th><th>Head of Household Last name</th><th>Head of Household First Name</th><th>Address of Head of Household</th><th>Date Started</th><th>Date Completed</th><th>Remarks</th></tr>
		{{#REPORTARRAY}}
			<tr> {{#.}}<td>{{.}}</td>{{/.}}</tr>
		{{/REPORTARRAY}}
	</table>
</script>
So it works now. Thanks to the team for all your help!
Post Reply