IntroductionIn this article, i will explain how to fix the a important javascript error with crystal report export or print screen in version 11 R2. ProblemThe JavaScript error "object required" may be thrown in a .NET web application using the Crystal Reports XI R2 components. The error occurs when clicking on the "Ok" button in the export or print dialog window. When you click Ok button to print or export, you able to see this error , opener.document.getElementById("crystal_handler_page") is null CauseThis error is caused because the export.js file is not updated after Service Pack 2 is installed for Crystal Reports XI R2. Before Service Pack 2 the line on 105 of export.js look like this: " document.dlgform.action = opener.document.getElementById(\"crystal_handler_page\").value;" + After Service Pack 2 line 105 looks like this: " document.dlgform.action = opener.location;" + This problem could happen with custom web sites where the crystalreportviewers115 is copied into a new folder. The new folder is not updated by service or fix packs provided by Business Objects. Only the following export.js files are updated by service and fix packs: - Inetpub\wwwroot\aspnet_client\system_web\2_0_50727\crystalreportviewers115\js\export.js
- Program Files\Business Objects\Common\3.5\crystalreportviewers115\js\export.js
- WINDOWS\Microsoft.NET\Framework\v2.0.50727\ASP.NETClientFiles\crystalreportviewers115\js\export.js
ResolutionTo resolve this issue you will need to modify the export.js files on your system. The best way to do that is to search the entire C:\ drive for "export.js". There are three possible locations for the export.js files and possibly more if copies have been made. - Right click your C:\ drive and select "Search..."
- Type in "export.js" and click the "Search" button
- Take note of all the export.js files found and only edit the ones found under crystalreportviewer115 directories.
- Replace line 105 in export.js that looks like this:
" document.dlgform.action = opener.document.getElementById(\"crystal_handler_page\").value;" +
with this:
" document.dlgform.action = opener.location;" +Once you are replace correctlly, then you able see the code of export.js as like below // export.js
// This file contains the funcitons needed to construct the HTML for the export / print dialog.
//
// Global variable
var print = false; // default to export, so set print to false
var crystal_postback =
"<INPUT type=\"hidden\" name=\"reportsource\" id=\"reportsource\"/>" +
"<INPUT type=\"hidden\" name=\"viewstate\" id=\"viewstate\"/>";
function getPageTitle() {
if (print) {
return L_PrintPageTitle;
}
else {
return L_ExportPageTitle;
}
}
function getOptionsTitle() {
if (print) {
return L_PrintOptions;
}
else {
return L_ExportOptions;
}
}
function getFormatDropdownList() {
if (print) {
return "<INPUT type=\"hidden\" name=\"exportformat\" id=\"exportformat\" value=\"PDF\"/>";
}
else {
var list =
"<select id=\"exportformatlist\" class=\"crexportselect\" name=\"exportformat\" onchange=\"checkDisableRange();\">";
if( rpt )
{
list += "<OPTION value=\"CrystalReports\">" + L_CrystalRptFormat + "</OPTION>";
}
else
{
list += "<OPTION value=\"\">" + L_Formats + "</OPTION>";
}
if( pdf )
{
list += "<OPTION value=\"PDF\">" + L_AcrobatFormat + "</OPTION>";
}
if( xls )
{
list += "<OPTION value=\"MSExcel\">" + L_ExcelFormat + "</OPTION>";
}
if( recXls )
{
list += "<OPTION value=\"RecordToMSExcel\">" + L_ExcelRecordFormat + "</OPTION>";
}
if( word )
{
list += "<OPTION value=\"MSWord\">" + L_WordFormat + "</OPTION>";
}
if( ertf )
{
list += "<OPTION value=\"EditableRTF\">" + L_EditableRTFFormat +"</OPTION>";
}
if( rtf )
{
list += "<OPTION value=\"RTF\">" + L_RTFFormat +"</OPTION>";
}
list += "</SELECT>"
return list;
}
}
function getSelectPageRangeSentence() {
if (print) {
return L_PrintPageRange;
}
else {
return L_ExportPageRange;
}
}
function getExportDialog() {
var exportDialog =
"<HTML>" +
"<HEAD>" +
"<LINK rel=\"stylesheet\" type=\"text/css\" href=\"../css/default.css\">" +
"<script type=\"text/javascript\" src=\"../js/exportdialog.js\"></script>" +
"<script type=\"text/javascript\">" +
" function checkValuesAndSubmit() {" +
" if (document.forms[\"dlgform\"].isRange != null &&" +
" document.forms[\"dlgform\"].isRange[1].checked) {" +
" if (!isValidNumber(document.forms[\"dlgform\"].from.value) ||" +
" !isValidNumber(document.forms[\"dlgform\"].to.value) ||" +
" (parseInt(document.forms[\"dlgform\"].from.value, 10) > parseInt(document.forms[\"dlgform\"].to.value, 10))) {" +
" alert(\"" + L_InvalidPageRange + "\");" +
" return;" +
" }" +
" }" +
" if (document.forms[\"dlgform\"].exportformat != null &&" +
" document.forms[\"dlgform\"].exportformat.value == \"\") {" +
" alert(\"" + L_ExportFormat + "\");" +
" return;" +
" }" +
" document.dlgform.action =opener.location;" +
" document.dlgform.submit();" +
" document.getElementById(\"submitexport\").disabled = true;" +
" }" +
"</script>" +
"<TITLE>" + getPageTitle() + "</TITLE>" +
"</HEAD>" +
"<BODY class=\"crexportpage\" bottommargin=\"5\" topmargin=\"5\" onload=\"checkDisableRange();\">" +
"<FORM name=\"dlgform\" method=\"POST\">" +
crystal_postback +
"<TABLE cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" height=\"100%\" valign=\"bottom\" halign=\"center\" border=\"0\">";
if (!print) {
exportDialog +=
" <TR><TD align=\"left\"><table width=\"100%\" border=\"0\">" +
" <tr>" +
" <td width=\"35%\"><span class=\"crexportmessage\"><label for=\"exportformatlist\">" + L_Formats + "</label></span></td>" +
" <td align=\"left\" width=\"65%\" class=\"crexportselect\">" +
getFormatDropdownList() +
" </td>" +
" </tr>" +
" </table></TD></TR>" +
" <TR><TD><hr class=\"crexportruler\"></TD></TR>";
}
exportDialog +=
" <TR><TD align=\"left\"><table width=\"100%\" border=\"0\">" +
" <tr>" +
" <td width=\"35%\"><span class=\"crexportmessage\">" + L_PageRange + "</span></td>" +
" <td width=\"65%\" align=\"left\"><input type=\"radio\" id=\"radio1\" name=\"isRange\" value=\"all\" onclick=\"return toggleRangeFields(this);\"/><span class=\"crexportmessage\"><label for=\"radio1\">" + L_All + "</label></span></td>" +
" </tr>" +
" <tr>" +
" <td rowspan=\"2\"></td>" +
" <td align=\"left\"><input type=\"radio\" id=\"radio2\" checked name=\"isRange\" value=\"selection\" onclick=\"return toggleRangeFields(this);\"/><span class=\"crexportmessage\"><label for=\"radio2\">" + L_Pages + "</label></span></td>" +
" </tr>" +
" <tr>" +
" <td> <span class=\"crexportmessage\"><label for=\"from\">" + L_From + "</label></span> <input class=\"crexporttextbox\" type=\"text\" width=\"20\" size=\"6\" maxlength=\"6\" name=\"from\" value=\"1\"> <span class=\"crexportmessage\"><label for=\"to\">" + L_To + "</label></span> <input class=\"crexporttextbox\" type=\"text\" width=\"20\" size=\"6\" maxlength=\"6\" name=\"to\" value=\"1\"></td>" +
" </tr>" +
" </table></TD></TR>" +
" <TR><TD><hr class=\"crexportruler\"></TD></TR>";
if (print) {
exportDialog +=
" <TR><TD>" +
" <input type=\"hidden\" name=\"exportformat\" value=\"PDF\">" +
" <table>" +
" <tr><td><span class=\"crexportmessage\">" + L_PrintStep0 + "</span></td></tr>" +
" <tr><td><span class=\"crexportmessage\">" + L_PrintStep1 + "</span></td></tr>" +
" <tr><td><span class=\"crexportmessage\">" + L_PrintStep2 + "</span></td></tr>" +
" </table>"+
" </TD></TR>";
}
exportDialog +=
" <TR valign=\"top\"><TD align=\"right\"><input class=\"crexportbutton\" id=\"submitexport\" type=\"button\" value=\"" + L_OK + "\" onclick=\"checkValuesAndSubmit();\"/> <input class=\"crexportbutton\" type=\"button\" value=\"" + L_Cancel + "\" onclick=\"window.close();\"/></TD></TR>" +
"</TABLE>" +
"</FORM>" +
"</BODY>" +
"</HTML>";
return exportDialog;
}
Note:It is important to only change the export.js files which are in crystalreportviewers115 directories Hope help and save you time. thank you for reading. |