• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
2

Coldfusion with BIRT report print excel from eclipse

New Here ,
Oct 16, 2023 Oct 16, 2023

Copy link to clipboard

Copied

I have write a code in body_supportlog.cfm as below, able to download excel, but it show "The request resource are not available. It suppose link with eclipse's parameter from date and to date. The file path refer to  C:\ColdFusion11\cfusion\runtime\webapps\BIRT\test1.rptdesign

<html>
<head>

<!--- Security Check --->
<cfset mid="100000">
<cfset fid="121212121">
<cfinclude template="#rootdir#checkaccess.cfm">
<cfoutput>
 		<TITLE><cfinclude template="#rootdir#pageTitle.cfm"></TITLE>      
        <LINK REL="STYLESHEET" HREF="#css#iesync2.css" TYPE="text/css">
		<script language="javascript" src="#jslib#mainframe.js" type=text/javascript></script>
  		 <script language="javascript" src="#jslib#iesync2.js" type=text/javascript></script>
</cfoutput>
	
<script language="JavaScript">
	function urlencode(str) {
	 	str = (str+'').toString();
	 	return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
	           replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
 	}

 	function dosearch(){
					var f = document.frmSearch;
					if (checkFields(f)){
						f.SearchFlag.value = 1;
						f.submit();
					}
				}

	
// function popupWindow(fname,field) {
//         var win;
// 		var f = document.frmGVType;
//         var fvalue = eval(fname + '.' + field + ".value");
		
//         win = window.open('main.cfm?dir=System_Manager&pid=body_gv_type_popup.cfm&type='+field+'&fname='+fname+'&key='+urlencode(fvalue),'popup','screenX=220,screenY=312,top=220,left=312,width=400,height=300,scrollbars=yes');
//         if (win.opener == null) {win.opener = self;}
        
//         win.focus();
// }

// function popupWindow2(fname,field) {
//         var win;
// 		var f = document.frmGVType;
//         var fvalue = eval(fname + '.' + field + ".value");
		
//         win = window.open('main.cfm?dir=System_Manager&pid=body_gv__popup.cfm&type='+field+'&fname='+fname+'&key='+urlencode(fvalue),'popup','screenX=220,screenY=312,top=220,left=312,width=400,height=300,scrollbars=yes');
//         if (win.opener == null) {win.opener = self;}
        
//         win.focus();
// }

function clearField(){
    var objForm = document.frmType;
    
    objForm.DATEFROMSO.value = "";
    objForm.DATETOSO.value = "";

}

function DoSort(Sort,type,currentsort,fname) {
		var f = fname;
		f.bSortBy.value = Sort;
		
		if (Sort != currentsort){
			f.bsortType.value = "asc";
		}else{
			if(type == 'asc'){
				f.bsortType.value = 'desc';
			}
			else{
				f.bsortType.value = 'asc';
			}
		}
		
		f.submit();
		
}

function DoReset(f)
	{
		for (var i = 0; i<f.elements.length; i++) {
		
		        if ((f.elements[i].type == 'text')) {
		            if (f.elements[i].name == 'perpage') {
						f.elements[i].value = '20';
		            } else if (f.elements[i].name == 'oneachpage') {
						f.elements[i].value = '20';
					} else if (f.elements[i].name == 'oneachpage_1') {
		    		    f.elements[i].value = '20';
		    	    }else {
						f.elements[i].value = '';
					}
		        } else if ((f.elements[i].type == 'select-one')) {
		            f.elements[i].selectedIndex = 0;
		        } else if ((f.elements[i].type == 'checkbox')) {
		            f.elements[i].checked = false;
		        }
		       
		    } 
			

	}
	function checkFields(f) {
    var datePattern = /^\d{4}\/\d{2}\/\d{2}$/;

    if (trim(f.DATEFROMSO.value, 'both') !== "") {
        if (!datePattern.test(f.DATEFROMSO.value)) {
            alert("Invalid Date From. Please re-enter the date in this 'yyyy/MM/dd' format.");
            f.DATEFROMSO.focus();
            return false;
        }
    }

    if (trim(f.DATETOSO.value, 'both') !== "") {
        if (!datePattern.test(f.DATETOSO.value)) {
            alert("Invalid Date To. Please re-enter the date in this 'yyyy/MM/dd' format.");
            f.DATETOSO.focus();
            return false;
        }
    }

    if (trim(!datePattern.test(f.DATETOSO.value,'both')) !='' && trim(!datePattern.test(f.DATEFROMSO.value,'both')) !='' && !compareDate(f.DATEFROMSO.value,f.DATETOSO.value)) {
		alert("Date To cannot be earlier than the Date From.");
		f.DATEFROMSO.focus();
		return false ;

    }

    return true;
}

				function generate(){
					var a = document.forms['frmType'];
					if(checkFields(a)){
						a.printBirtFlag.value = 1;
						showLoadingBar();
						a.submit();
					}
				}


</script>	

<cfscript>
			reportParameter = createObject('component', '#cflib#getParameter').init('#cflib#');
			printBirt = createObject("component", "#cflib#printBirtRpt").init(ds);
		</cfscript>
</head>

<!--- javascript validation checking functions ---> 
<cfinclude template="#jslib#js_others.cfm">
<cfinclude template="#jslib#js_validation.cfm">

<cfparam name="DATEFROMSO" default="">
<cfparam name="DATETOSO" default="">
<cfparam name="OUTLETCODE" default="">
<cfparam name="SONO" default="">
<cfparam name="NEW" default="">
<cfparam name="CLOSED" default="">
<cfparam name="STATUS" default="">
<cfparam name="CREATEDDATETIME" default="">
<cfparam name="bSearch" default="">

<!--- defind default searching page --->
<cfparam name="SearchFlag" default="">
<cfparam name="ClickSearchFlag" default="">
<cfparam name="sortBy" default="so.CREATEDDATETIME">
<cfparam name="oneachpage" default =20>
<cfparam name="startRow" default="1">

<cfif isdefined("startRow")>
    <cfset startRow = startRow>
    <cfset endRow = startRow + onEachPage - 1>
<cfelse>
    <cfset endRow = onEachPage>= 20>
<cfparam name="pagenum"    default = 1>
</cfif>

<cfif isdefined("printBirtFlag") AND printBirtFlag EQ 1>

			<cfset userid = #session.userid#>
			<cfset reportname = "test1.rptdesign">
			<cfset reportparam = reportParameter.getReportParameter("SO_report_xls")>
			<cfset filetype = "xls">
			<cfset downloadPath = SO_Report_excel>

			<cfset printBirt.print(#userid#,#reportname#,#filetype#,#reportparam#,#form#,#fid#,#downloadPath#)>
			<cfoutput>
				<script language="javascript">
					var filename = '#file['rptfile']#';
					var downloadPath = '#urlencodedformat(downloadPath)#';
					var fn = urlencode(filename);
					window.open('cflib/download_birt_xls.cfm?downloadPath='+downloadPath+'&filename='+fn);
				</script>
			</cfoutput>
		</cfif>

<cfset currentpage = "main.cfm?dir=System_Manager&pid=body_supportlog.cfm&">

<cfset querystringRaw = "bsearch=#bsearch#&OUTLETCODE=#urlencodedformat(OUTLETCODE)#&SONO=#urlencodedformat(SONO)#&NEW=#urlencodedformat(NEW)#&CLOSED=#urlencodedformat(CLOSED)#&DATEFROMSO=#URLEncodedFormat(DATEFROMSO)#&DATETOSO=#URLEncodedFormat(DATETOSO)#">
<!--- <cfset querystringRaw = "http://127.0.0.1:55980/viewer/frameset?__report=C%3A%5CColdFusion11%5Ccfusion%5Cruntime%5Cwebapps%5CBIRT%5Ctest1.rptdesign"> --->
<cfset querystring = querystringRaw & "&oneachpage=#oneachpage#">
<cfif isdefined("PageNum")>
	<cfset querystringPage = querystring & "&startRow=#startRow#&pagenum=#PageNum#">
</cfif> 

<cfif not isdefined("form.Status") AND (isdefined("ClickSearchFlag") AND ClickSearchFlag eq 1)>
	<cfset Status = "">
</cfif> 

<cfif trim(bSearch) neq "" and trim(bSearch) eq "1">
  <cfset flag=0>
  <cftransaction isolation="#isolationType#">
    <cfquery name="qrySearch" datasource="#ds#">
      SELECT so.OUTLETCODE,
       COUNT(so.SONO) AS SONO,
       SUM(CASE WHEN so.STATUS = 'N' THEN 1 ELSE 0 END) AS NEW,
       SUM(CASE WHEN so.STATUS = 'C' THEN 1 ELSE 0 END) AS CLOSED
       FROM T_SVC_SO_MASTER so
      WHERE so.CREATEDDATETIME >= <cfqueryparam value="#DATEFROMSO#" cfsqltype="cf_sql_date">
       AND so.CREATEDDATETIME <= <cfqueryparam value="#DATETOSO#" cfsqltype="cf_sql_date">

       --
		GROUP BY so.OUTLETCODE
    </cfquery> 
  </cftransaction>     
</cfif>



<!--- Begin of the table--->
<body>
<cfoutput>
<form name="frmType" action="#currentpage#bsearch=1&ClickSearchFlag=1&SearchFlag=1" method="post" enctype="multipart/form-data">
					<input type="hidden" id="usertypeid" name="usertypeid" value="#SESSION.USERTYPEID#">
					<input type="hidden" id="outletcode" name="outletcode" value="#SESSION.OUTLETCODE#">
					<input type="hidden" name="SearchFlag" value="">
					<input type="hidden" name="printBirtFlag" value="">
<center>
<table border="0" width="100%" cellpadding="0" cellspacing="1">
    <tr>
        <cfif IsDefined("msg") and trim(msg) NEQ ''>
            <td class="cssOkMsg"><img src=#images#msg_ok.gif align=absmiddle>#msg#</td>
        <cfelse>
            <td class="cssOkMsg">&nbsp;</td>
        </cfif>
    </tr>
</table>
</center>

<center>
<table border="0" width="95%">
  	<tr>
    	<td class="cssPageTitle" align="left">Search</td>
		<td class="cssPageTitle" align="right"><cfinclude template="#rootdir#pageTitle.cfm"> </td>
	</tr>
</table>
</center>

<center>
<table width="95%" class="cssSearchBorder" border="0" cellpadding="2" cellspacing="0">
<tr>
     <td class="cssLabel" width="40%">DATE FROM SO
		 <br><input class="cssForm" maxLength="10" name="DATEFROMSO" size="25" value="#DATEFROMSO#" id="DATEFROMSO">
		 <a href="javascript&colon;popupWindow('frmType','DATEFROMSO')">

     </td>
     <td class="cssLabel" width="30%">DATE TO SO
		 <br><input class="cssForm" maxLength="10" name="DATETOSO" size="25" value="#DATETOSO#" id="DATETOSO">
		 <a href="javascript&colon;popupWindow('frmType','DATETOSO')">

     </td>
</tr>

</table>

<center>
<table border=0 width=95%>
    <tr>
        <td colspan="3" class=cssButtonLine>
        	  #ButtonCall.GenerateButton("button", "btndownload", "sbttndownloadExcel", "", "generate();")#
		      #ButtonCall.GenerateButton("button", "btnreset", "sbttnreset", "", "DoReset(document.frmType);")#
		      #ButtonCall.GenerateButton("submit", "btngenerate", "sbttnsearch", "", "dosearch();")#
        </td>
    </tr>
</table>
</center>        
</form>
</cfoutput>
		
<cfif IsDefined("bSearch") and trim(bSearch) neq "">
<cfoutput>
<cfset rowsCount = Int(qrySearch.recordCount/onEachPage)>
<cfset last = Val(rowsCount*onEachPage) + 1>		

<form name = "frmSearch" action = "#currentpage#bsearch=1" method = "post">
<table border="0" cellpadding="3" cellspacing="2" width="95%">
	 <cfif qrySearch.recordcount gt 0>
        <tr>
            <td colspan="4">
                <table width=100% border=0 cellpadding=0 cellspacing=0>
                    <tr>
                    <td class="cssButtonLineL" height="26" width=30%>
                         <cfinclude template="#rootdir#/cflib/pageCount2.cfm">
                    </td>
                    <td class="cssButtonLine" width=70%>
                        <cfset urlextra = #queryString#>
                        <cfset queryname="qrySearch">
                        <cfinclude template="#rootdir#/cflib/navi_criteria.cfm">
                    </td>
                    </tr>
                </table>
            </td>
        </tr>
    	<tr>
	      <td class="cssSubTitleC" width="5">No</td>
		  <td class="cssSubTitleL" width="35%"><span onclick="DoSort('so.OUTLETCODE',document.frmSearch)" class="HandCursor">OUTLET CODE</span> </td>
		  <td class="cssSubTitleL" width="35%"><span onclick="DoSort('so.SONO',document.frmSearch)" class="HandCursor">SONO</span> </td>
		  <td class="cssSubTitleL" width="35%"><span onclick="DoSort('NEW',document.frmSearch)" class="HandCursor">NEW</span> </td>
		  <td class="cssSubTitleL" width="35%"><span onclick="DoSort('CLOSED',document.frmSearch)" class="HandCursor">CLOSED</span> </td>
	    </tr>
		<cfset i = 0>
        <cfloop query="qrySearch" startRow=#startRow# endRow=#endRow#>
            <cfif i mod 2 eq 0>
                <cfset cssClass="cssLine1">
            <cfelse>
                <cfset cssClass="cssLine2">
            </cfif>
            
            <cfset i = i + 1>
	
	         <!--- <tr>
                <td class=#cssclass#C>#qrySearch.currentrow#</td>
                <td class=#cssclass#L>
					<a href="#editpage#&GVTYPEID=#trim(qrySearch.GVTYPEID)#&#querystring#">#trim(qrySearch.GVTYPECODE)#</a>
                </td>
				<td class=#cssclass#L>#qrySearch.GVTYPEDESC#</td>
            </tr>  --->
        </cfloop>
		<tr>
            <td class="cssButtonLine" colspan="9">
                <table width=100% cellpadding=0 cellspacing=0>
                    <tr>
	                    <td class="cssButtonLineL">&nbsp;
							<input type="hidden" name="DATEFROMSO" value="#DATEFROMSO#">
							<input type="hidden" name="DATETOSO" value="#DATETOSO#">
							<input type="hidden" name="OUTLETCODE" value="#OUTLETCODE#">
							<input type="hidden" name="SONO" value="#SONO#">

							<input type="hidden" name="NEW" value="#NEW#">
							<input type="hidden" name="CLOSED" value="#CLOSED#">

	                    </td>
                    </tr>
					<tr>	
						<td class="cssButtonLineL">
	                         <cfinclude template="#rootdir#/cflib/navi_criteria_noperpage.cfm">
	                     </td>
						 <td class="cssButtonLine">
	                         <cfinclude template="#rootdir#/cflib/navi_criteria.cfm">
	                     </td>
					</tr>
                </table>
            </td>
        </tr>	
    <cfelse>
        <tr><td class="cssLine1C">&nbsp;</td></tr>
        <tr><td class="cssLine2C">No record found</td></tr>
        <tr><td class="cssLine1C">&nbsp;</td></tr>
    </cfif> 
</table>
</center>
</form>
</cfoutput>
</cfif>
</body>

</html>

. Please let me know if you need more information 

TOPICS
Advanced techniques , cfchart , Database access , Getting started , Reporting

Views

73

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation
Resources
Documentation