I've generated crystal report with php COM. Now I need to pass some parameters to the report without prompt. The following is the code:
<?php
//------ Variables ------
$my_report = "C:\\Apache2\htdocs\\test\\MyReport.rpt"; //This must be the full path to the file
$my_pdf = "C:\\Apache2\htdocs\\test\\MyReport.pdf";
//------ Create a new COM Object of Crytal Reports 10 ------
$ObjectFactory= new COM("CrystalReports10.ObjectFactory.1");
//------ Create a instance of library Application -------
$crapp = $ObjectFactory->CreateObject("CrystalDesignRunTime.Application.10");
//------ Open your rpt file ------
$creport = $crapp->OpenReport($my_report, 1);
//------ Set database logon info ------
$creport->Database->Tables(1)->SetLogOnInfo("MYSERVER", "Database", "user", "password");
//------ Suppress the Parameter field prompt or else report will hang ------
$creport->EnableParameterPrompting = 0;
//------ DiscardSavedData make a Refresh in your data -------
$creport->DiscardSavedData;
$creport->ReadRecords();
//------ Pass formula fields --------
// $creport->FormulaFields->Item(1)->Text = ("'My Report Title'");
$creport->ParameterFields(1)->AddCurrentValue ("Hello World"); // <-- param 1
$creport->ParameterFields(2)->AddCurrentValue (123); // <-- param 2
//------ Export to PDF -------
$creport->ExportOptions->DiskFileName=$my_pdf;
$creport->ExportOptions->FormatType=31;
$creport->ExportOptions->DestinationType=1;
$creport->Export(false);
//------ Release the variables ------
$creport = null;
$crapp = null;
$ObjectFactory = null;
//------ Embed the report in the webpage ------
print "<embed src=\"MyReport.pdf\" width=\"100%\" height=\"100%\">"
?>
In CR, in Field Explorer I right click on Parameter Fields and choose New. However, I don't know what is parameter fields name to assign and other settings, in order to get param1 and param2 value in the code above.
Help appreciated.
$creport->ParameterFields(1)->SetCurrentValue ("Hello World"); // <-- param 1
$creport->ParameterFields(2)->SetCurrentValue (123); // <-- param 2
Hope this helps you.