Focal Point
[SOLVED] HTML Report with Excel and PDF options

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/9391009331

October 21, 2005, 04:13 PM
Saif K
[SOLVED] HTML Report with Excel and PDF options
Hi,
I have a selfservice app with several drill-down reports. All reports are displayed in html format like this..
-HTMLFORM BEGIN
{html}
{head} {title}{/title}{/head}
{body}
{center}
!IBI.FIL.COMREP1;
{br}
{a href="http://wfdevrp01/approot/commisson/comcac01.htm" target="_blank"}Report Definitions{/a}
{/center}
{/body}
{/html}
-HTMLFORM END

Now the requirement is to show excel and pdf gifs in the header of each report, so that the users can click the gif and re-run the same report in the format of their choice.

I will appreciate any help on how to get this done. If possible without or minimum javascript code.

Thanks

This message has been edited. Last edited by: Kerry,
October 24, 2005, 03:28 PM
Francis Mariani
You will require JavaScript code to do this. You should have none or very minimal changes to make, which I can give you a hand with.

Function fnRunReport is called when clicking on an output gif image, the output type is passed. The function takes the URL of the current HTML report and calls function fnReplaceParmValue to replace the value of the OUTPUT parameter with the new setting.
(The nice thing about fnReplaceParmValue is that it can be used to replace the value of any parameter with a new value and if the parameter does not exist, it adds it to the end of the URL.)

The JavaScript:
<script language="JavaScript">
// Rerun the report replacing WebFOCUS variables -----------
function fnRunReport(vOutput)
{
// Determine if the report is run from a WebFOCUS Dashboard
vWorpPostion1 = document.URL.indexOf('Controller;jsessionid');
vWorpPostion2 = document.URL.indexOf('&IBIMR_action=MR_RUN_FEX');

if (vWorpPostion1 == -1)
{
vURL = document.URL;
}
else
{
vURL =
document.URL.substring(0,vWorpPostion1) +
'WFServlet?' +
document.URL.substring(vWorpPostion2,document.URL.length);
}

vNewURL = fnReplaceParmValue(vURL,'OUTPUT',vOutput);
vNewURL = fnReplaceParmValue(vNewURL,'RANDOM',Math.floor((Math.random()*100000)));

// Construct the FormattedReport window's features
var vFeatures =
"menubar=yes,toolbar=no,status=yes,resizable=yes,scrollbars=yes" +
",width=" + (screen.availWidth - 90) +
",height=" + (screen.availHeight - 150) +
",screenX=30,screenY=30,top=30,left=30";

// Open a new window and run the URL
FormattedReport = window.open(vNewURL,"FormattedReport",vFeatures);
}

// Function to replace the value of a selected WebFOCUS Parm with another value
function fnReplaceParmValue(vURL,vParm,vValue)
{
vParmString = '&' + vParm + '=';

vStringPosition = vURL.indexOf(vParmString);

if (vStringPosition == -1)
{
vNewURL = vURL + vParmString + vValue;
}
else
{
vNextParmPosition = vURL.indexOf("&", vStringPosition + 1);

vURLBeforeParm = vURL.substring(0, vStringPosition);

if (vNextParmPosition == -1)
vURLAfterParm = "";
else
vURLAfterParm = vURL.substring(vNextParmPosition, vURL.length);

vNewURL = vURLBeforeParm + vParmString + vValue + vURLAfterParm;
}
/*
alert("Old URL: " + "\n" + vURL + "\n" +
"New URL: " + "\n" + vNewURL);
*/
return vNewURL;
}
</script>

The HTML:
<table border="0">
<tr>
<td>
<a href="java_script:fnRunReport['PDF');" class="Navigation">
<IMG SRC="/approot/app1/media/as_pdf.gif" align="middle"></a>

<a href="java_script:fnRunReport['EXL2K');" class="Navigation">
<IMG SRC="/approot/apop1/media/as_xls2k.gif" align="middle"></a></td>
</tr>
</table>

This message has been edited. Last edited by: Francis Mariani,


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
October 24, 2005, 08:02 PM
Saif K
Thank you Francis.

It worked like a charm. Since I am working outside the Dashboard, I have modified the function fnRunReport.

function fnRunReport(vOutput)
{
vURL = document.URL;
vNewURL = fnReplaceParmValue(vURL,'OUTPUT',vOutput);

// Construct the FormattedReport window's features
var vFeatures =
"menubar=yes,toolbar=no,status=yes,resizable=yes,scrollbars=yes" +
",width=" + (screen.availWidth - 90) +
",height=" + (screen.availHeight - 150) +
",screenX=30,screenY=30,top=30,left=30";

// Open a new window and run the URL
FormattedReport = window.open(vNewURL,"FormattedReport",vFeatures);
}
October 25, 2005, 12:32 AM
Francis Mariani
Those were sixty-four dollar JavaScript functions!

I'm glad it worked out.

Cheers,
April 04, 2007, 10:09 AM
Francis Mariani
A complete example, with annotation (remove the alerts after JavaScript functions have been understood:

-SET &ECHO=ALL;

-? &

-DEFAULT &OUTPUT = 'H';
-DEFAULT &COUNTRY = 'FOC_NONE';

-SET &OUTPUT_CMD = DECODE &OUTPUT (
- 'H' 'ON TABLE HOLD AS HOLDREP1 FORMAT HTMTABLE'
- 'P' 'ON TABLE PCHOLD FORMAT PDF'
- 'E' 'ON TABLE PCHOLD FORMAT EXL2K'
- ELSE 'ERROR');

TABLE FILE CAR
SUM
SALES
BY COUNTRY

WHERE COUNTRY EQ '&COUNTRY'

&OUTPUT_CMD

END
-RUN
-IF &OUTPUT EQ 'H' GOTO REP_HTML;

-EXIT

-REP_HTML

-HTMLFORM BEGIN
<HTML>
<HEAD>
<TITLE>WebFOCUS Report</TITLE>

<script language="JavaScript">

// Replace the Output parameter with the selected format and rerun the same URL -----
function fnRerunReport(vOutput)
{
// Capture the URL of the WebFOCUS request -----------------
vURL = document.URL;
// Replace the Output parameter with the selected format ---
vNewURL = fnReplaceParmValue(vURL,'OUTPUT',vOutput);
// Replace the RANDOM parameter with a new value -----------
vNewURL = fnReplaceParmValue(vNewURL,'RANDOM',Math.floor((Math.random()*100000)));

// Construct the FormattedReport window's features ---------
var vFeatures =
"menubar=yes,toolbar=no,status=yes,resizable=yes,scrollbars=yes" +
",width=" + (screen.availWidth - 90) +
",height=" + (screen.availHeight - 150) +
",screenX=30,screenY=30,top=30,left=30";

// Open a new window and run the URL -----------------------
FormattedReport = window.open(vNewURL,"FormattedReport",vFeatures);
}

// Function to replace the value of a selected WebFOCUS Parm with another value -----
function fnReplaceParmValue(vURL,vParm,vValue)
{
alert('1 Parm name/value to replace: ' + vParm + ' / ' + vValue);

// Set up the parm string --------------------------------------------
vParmString = '&' + vParm + '=';

// Determine the beginning position of the parm in the URL string ----
vStringPosition = vURL.indexOf(vParmString);
alert('2 Beginning position of the parm in the URL string: ' + vStringPosition);
// If the parm string was not found, add it to the end of the URL string ---
if (vStringPosition == -1)
  {
  vNewURL = vURL + vParmString + vValue;
  }
else
  {
  // Determine the beginning position of the next parm in the URL string
  vNextParmPosition = vURL.indexOf("&", vStringPosition + 1);
  alert('3 Beginning position of the next parm in the URL string: ' + vNextParmPosition);
  // Determine the URL string before the selected parm ---------------
  vURLBeforeParm = vURL.substring(0, vStringPosition);
  alert('4 URL string before the selected parm: ' + vURLBeforeParm);

  // If the selected parm is the last parm in the URL string, do nothing
  if (vNextParmPosition == -1)
    {
    vURLAfterParm = "";
    }
  // If the selected parm is not the last parm in the URL string, ----
  // determine the URL string after the selected parm
  else
    {
    vURLAfterParm = vURL.substring(vNextParmPosition, vURL.length);
    alert('5 URL string after the selected parm: ' + vURLAfterParm);
    }

  // Build the new URL string ------------------------------
  vNewURL = vURLBeforeParm + vParmString + vValue + vURLAfterParm;
  alert('6 Old URL: ' + vURL);
  alert('7 New URL: ' + vNewURL);
  }

return vNewURL;
}
</SCRIPT>
</HEAD>

<BODY>
<DIV>
<FORM>
<input type="button" class="cssButton" value="Close" onClick="window.close[);">
<input type="button" class="cssButton" value="PDF"   onClick="fnRerunReport['P');">
<input type="button" class="cssButton" value="Excel" onClick="fnRerunReport['E');">
</FORM>
</DIV>

!IBI.FIL.HOLDREP1;
</BODY>
</HTML>
-HTMLFORM END

This message has been edited. Last edited by: Francis Mariani,


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
April 05, 2007, 01:41 PM
Jeff Elam
Very cool, Francis. This is probably pie in the sky, but is there any way to add this to a stylesheet, so it could be done automatically for any report?

WF7.6 BI Dashbaord/Windows XP


Jeff Elam
WF 8 in Windows
April 09, 2007, 10:52 AM
Francis Mariani
I just stick most of this -HTMLFORM in a -INCLUDE and then use it when necessary.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
March 04, 2009, 12:43 PM
Francis Mariani
I should mention that this technique will only work when the form that originally submitted the WebFOCUS request has a METHOD of GET. One could probably use AJAX to do this for FORM METHOD POST but I haven't looked in to that.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server