COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: torre2011 on 09 May 2014 07:01:42 AM

Title: Question Resolved: Opening Report to PDF in New Window???
Post by: torre2011 on 09 May 2014 07:01:42 AM
I have a need to create a custom button or link that will open the same report in PDF.  The issue I have is that the users want it to be in a new window.

There has been some discussion in other sites on this subject, but I have not been able to get it to work properly.  I am in 10.2.1 and IE8.  Below is the code I was using and this works, but it does not open in a new window:

<script>
CViewerManager.prototype.runPDF = function () {
var oReq = new ViewerDispatcherEntry(this.getCV());
oReq.addFormField("ui.action","render");
oReq.addFormField("run.outputFormat","PDF");
this.viewPDFInNewWindow(oReq); };
</script>
<input type="button" onclick="window['oCV'+'_THIS_'].getRV().runPDF()" value="Export to PDF"/>


Any suggestions are welcome ;)
Title: Re: Opening Report to PDF in New Window???
Post by: Lynn on 09 May 2014 08:02:54 AM
You could put any image or text on the report page and then set up a drill through to the same report. You can specify a new window with PDF format. You can make that object hidden when the output format is PDF. When testing within Report Studio be sure to save your report first since it is calling itself.

Personally I'd avoid JS unless it is absolutely required for something that cannot be done out of the box.
Title: Re: Opening Report to PDF in New Window???
Post by: torre2011 on 09 May 2014 08:29:24 AM
I appreciate the feedback, and i also agree with your comment on JS use...i like the flexibility, but I try as best as I can to do it out of the box!

But in this situation, I have not seemed to find a way to do it using the drill through behavior..here is the reason why - This report is based on a cube, and the crosstab has drill down/up functionality on the edge row.  So when the user drills down a few levels and uses the drill through to the same report, there place in the hierarchy is lost...it just reverts back to the original state.

I have attempted to try and figure out how to pass the current level but to no avail  :(

Any ideas?
Title: Re: Opening Report to PDF in New Window???
Post by: CognosPaul on 09 May 2014 08:55:58 AM
The JS I wrote seems to malfunction for a lot of people. I'll be able to work on it Sunday, when I'll have access to a functional 10.2.1 environment.
Title: Re: Opening Report to PDF in New Window???
Post by: torre2011 on 09 May 2014 01:25:59 PM
Ok Paul...i look forward to it!!!

On a side note, have you come accross  a way to create a drill through report from an OLAP modeled report that already has drill up/down capability?  As i mentioned in my previous reply, this report that i am working with is a simple crosstab with drill up/down behavior on the left edge row, allowing the user to navigate through the dimension hierarchy.  But if they wanted to drill through to another report and pass the current level they are on in the report...i am unaware of how to accomplish this???

Thanks!
Title: Re: Opening Report to PDF in New Window???
Post by: MFGF on 10 May 2014 05:43:31 AM
Quote from: torre2011 on 09 May 2014 01:25:59 PM
Ok Paul...i look forward to it!!!

On a side note, have you come accross  a way to create a drill through report from an OLAP modeled report that already has drill up/down capability?  As i mentioned in my previous reply, this report that i am working with is a simple crosstab with drill up/down behavior on the left edge row, allowing the user to navigate through the dimension hierarchy.  But if they wanted to drill through to another report and pass the current level they are on in the report...i am unaware of how to accomplish this???

Thanks!

Perhaps not quite what you are looking for, but here's a technique to allow one-click drill-down until the lowest level of the hierarchy is reached, then one-click drill-through at that level. No javascript required either! :)

http://www.cognoise.com/index.php/topic,19458

Of course, you could always just teach your users to right-click and select the relevant drill down/up option from the right-click menu (or the Go To option to drill though).

Cheers!

MF.
Title: Re: Opening Report to PDF in New Window???
Post by: torre2011 on 12 May 2014 03:05:18 PM
Yes MFGF, that is definitely an option for the drill through!  I have instructed them how to right click to do the drill up/down, but the drill through would only be used in my scenario to pass the current state of the hierarchy to a copy of the report that is formatted for PDF.

That is why I was hoping to get an answer on building a custom link to output the exisitng report into PDF but open in a new window.  This would mean using the existing logix for PDF output but writing it into a link function.

I know Cognos Paul has a solution, so I am just waiting to see if he sees a way to do it for 10.2.1.

Thanks again!
Title: Re: Opening Report to PDF in New Window???
Post by: CognosPaul on 12 May 2014 10:05:10 PM
I attached an updated version to my post. Let me know if you still have problems with it. http://cognospaul.com/2013/08/26/quickie-pdf-report-in-new-window/
Title: Re: Opening Report to PDF in New Window???
Post by: torre2011 on 13 May 2014 07:33:09 AM
CognosPaul,

I applied the following code to my report and I am still getting an error:

<script>
CViewerManager.prototype.runPDF = function () {
   var oReq = new ViewerDispatcherEntry(this.getCV());   
oReq.addFormField("ui.action","render"); 
oReq.addFormField("run.outputFormat","PDF");   
this.viewInNewWindowWithResize(oReq); };
</script>

Then in a separate html object i have the button to call it:
<input type="button" onclick="window['oCV'+'_THIS_'].getRV().runPDF()" value="Export to PDF"/>


..this time the error is: Object does not support this property or method
When I dive into the error it seems to be pointing to this line of code
oReq.addFormField("run.outputFormat","PDF");

Is there something that I am doing wrong or missing?

Thanks
Title: Re: Opening Report to PDF in New Window???
Post by: CognosPaul on 13 May 2014 11:09:48 AM
Try:

<script>
CViewerManager.prototype.runPDF = function ()
{
  var oReq = new ViewerDispatcherEntry(this.getCV());
  oReq.addFormField("ui.action","render");
  oReq.addFormField("run.outputFormat","PDF");
  this.viewInNewWindowWithResize(oReq);
};

var fW = (typeof getFormWarpRequest == "function" ? getFormWarpRequest() : document.forms["formWarpRequest"]);
if (!fW || fW == undefined) {
  fW = (formWarpRequest_THIS_ ? formWarpRequest_THIS_:formWarpRequest_NS_);
}

  var preFix = "";
  if (fW.elements["cv.id"]) { preFix = fW.elements["cv.id"].value;}
  var nameSpace = "oCV" + preFix;

 

CViewerManager.prototype.viewInNewWindowWithResize = function(oReq, browserHandle)
{
var oldUnload=window.onbeforeunload;
window.onbeforeunload=null;

if (browserHandle != null) {
browserHandle.close();
}
var target = "winNAT_" + ( new Date() ).getTime();
var sPath = this.getCV().getWebContentRoot() + "/" + "rv/blankNewWin.html?cv.id=" + this.getCVId();

var sFormID = "viewForm" + this.getCVId();
var oForm = document.getElementById(sFormID);
if (oForm) {
oForm.parentNode.removeChild(oForm);
}

oForm = document.createElement("form");
oForm.setAttribute("method", "post");
oForm.setAttribute("id", sFormID);
oForm.setAttribute("action", this.getCV().getGateway());
oForm.style.display = "inline";

var oFWR = document["formWarpRequest" + this.getCVId()];
if (oFWR && oFWR["run.outputFormat"]) {
oReq.addFormField("previousFormat", oFWR["run.outputFormat"].value);
}


var formFieldNames = oReq.getFormFields().keys();
for (var index = 0; index < formFieldNames.length; index++)
{
var name = formFieldNames[index];

// we'll force the action and respons format later on so we don't indirectly send this request to the fragment server
// since we're now doing a render, don't pass along the tracking. We still need to pass the
// conversation since we want to reuse the parameters and options
if(name != "cv.responseFormat" && name != "b_action" && name != "m_tracking")
{
oForm.appendChild(createHiddenFormField(name, oReq.getFormField(name)));
}
}

oForm.appendChild(createHiddenFormField("cv.responseFormat", "page"));
oForm.appendChild(createHiddenFormField("b_action", "cognosViewer"));
oForm.appendChild(createHiddenFormField("BIline1", RV_RES.RV_RUNNING));
oForm.appendChild(createHiddenFormField("BIline2", RV_RES.RV_PLEASE_WAIT));


document.body.appendChild(oForm);
oForm.target = target;

browserHandle = window.open(sPath, target, "rv,resizable=1");

window.onbeforeunload=oldUnload;
};


</script>

<input type="button" onclick="window[nameSpace].getRV().runPDF()" value="10.2+"/>
Title: Re: Opening Report to PDF in New Window???
Post by: torre2011 on 13 May 2014 01:02:03 PM
That did it!!!

Thanks!
Title: Re: Question Resolved: Opening Report to PDF in New Window???
Post by: sukanya on 18 May 2020 11:27:09 AM
how do i make this as hyperlink to click (PDF). please advise.