If you are unable to create a new account, please email support@bspsoftware.com

 

News:

MetaManager - Administrative Tools for IBM Cognos
Pricing starting at $2,100
Download Now    Learn More

Main Menu

Run report in PDF or HTML based on Prompt selection

Started by cognosguru, 10 May 2017 03:20:50 PM

Previous topic - Next topic

cognosguru

Gang,

I have a user who wants to have a prompt with 2 options - "PDF", "Interactive".  Upon running the report (in HTML) and selecting the "PDF" prompt option the output should render in PDF.  I haven't found any out of the box functionality that allows me to do so.  I have seen Java scripts which build a prompt (not Cognos just HTML with options for values ) and then render based on PDF selection.  I have seen Java scripts that access Cognos prompt values.  What I haven't seen is one that does both so I can have a Cognos regular dropdown prompt and then use the value to render in PDF.  Any JS people here that have done it or is there a setting I am not privy to inside of Cognos?  Would love some assistance.

New_Guy


AnalyticsWithJay

Have you considered drill-through links? You don't have to go through the hassle of JS.

Create two drill-through text items, and have them drill to self. You'll pass all the prompt parameters, except for one you set the output type to PDF, and the other to HTML.

This solution would be ideal if your prompts re-submit on selection, or if you had multiple pages of prompting.

cognosguru

New Guy, thanks for your response.  That is the code I have seen that is HTML/JS creation of the prompt selection and is not using Cognos.  I know it works but I want a Cognos prompt and then tie this code into rendering it. 

CognoidJay - good idea.  The prompt is on the prompt page, I will give it a try and see.

BigChris

Have you had a look at Conditional Layouts? I read something recently from CognosPaul that you can probably bend to suit your requirement:
http://cognospaul.com/2017/02/21/3-reports-1-email/

cognosguru

Gang,

I used CognoidJay's idea of Drill Through links but took it further.  I just created a Prompt Button which is the drill through on the Prompt Page.  Thus no need to resubmit and the report will render in PDF.  Attaching the 10.2.1 GoSales example.  Thanks guys!

cognosguru

BigChris, it's funny in all of my years of RS I have never seen the Conditional Layouts option.  I have done Conditional blocks, styles, render, etc.  but never noticed the Conditional Layouts :)  I looked through Paul's blog and it's cool.  Not sure this will work because I am not trying to render certain elements depending on output but rather the whole report in PDF/HTML etc. based on a prompt value.  Now, never having used it I may be way off but will play will it and see.  Thanks for letting me know!

AnalyticsWithJay

Quote from: cognosguru on 11 May 2017 08:43:02 AM
BigChris, it's funny in all of my years of RS I have never seen the Conditional Layouts option.  I have done Conditional blocks, styles, render, etc.  but never noticed the Conditional Layouts :)  I looked through Paul's blog and it's cool.  Not sure this will work because I am not trying to render certain elements depending on output but rather the whole report in PDF/HTML etc. based on a prompt value.  Now, never having used it I may be way off but will play will it and see.  Thanks for letting me know!

It's likely one of the least used features because of the popularity of it's alternatives :). Whenever I'm asked to help interview candidates, I like to include this at the end as a "fun" bonus question to lighten the mood. I've seen many advanced developers not know what this is :)

PS, nice job on extending the functionality of the drill through for a better user experience.

cognosguru

QuoteWhenever I'm asked to help interview candidates, I like to include this at the end as a "fun" bonus question to lighten the mood.

I do the same, I ask about Adornments  ;D

MFGF

Quote from: CognoidJay on 11 May 2017 09:02:31 AM
Whenever I'm asked to help interview candidates, I like to include this at the end as a "fun" bonus question to lighten the mood. I've seen many advanced developers not know what this is :)

Remind me never to apply for a job at your place :)

MF.
Meep!

AnalyticsWithJay

Quote from: MFGF on 11 May 2017 11:21:40 AM
Remind me never to apply for a job at your place :)

MF.

;D  Mention "Cognoise" and I'll omit the "bonus" question  :P :)

CognosPaul

Personally I don't like the drillthrough approach. It's a new request, meaning everything is run from scratch, and the drillthrough wizard doesn't always show all of the parameters. Using the export buttons is a much better proposal.

Try the following code:

<script>

CViewerManager.prototype.runExport = function (type)
{
  var oReq = new ViewerDispatcherEntry(this.getCV());
  oReq.addFormField("ui.action","render");
  oReq.addFormField("run.outputFormat",type);
  this.viewInNewWindowWithResize(oReq);
};

 

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['oCV_THIS_'].getRV().runExport('PDF')" value="PDF"/>
<input type="button" onclick="window['oCV_THIS_'].getRV().runExport('spreadsheetML')" value="Excel"/>


There  I have two separate buttons, one for PDF and Excel, but you could easily adapt that to call a prompt with:

<input type="button" onclick="window['oCV_THIS_'].getRV().runExport(paulScripts.getControl('exportType').getValues()[0].use))" value="Run Export"/>

Assuming, of course, the prompt name is exportType and you already have paulScripts.getControl defined somewhere (and why wouldn't you?).

cognosguru

Paul,

Any way not to use any of this at all?  Isn't there a way to pass some Cognos output parameter (internal to application ) that will allow me to just render a page in PDF and another one in HTML?

CognosPaul

The script here is really just to ensure the PDF exports to a new window. For some reason the native function runs it in the same window.

Can you tell me what the desired workflow is? I'm a little confused why this wouldn't work for you.

cognosguru

Prompt Page 1 - Prompt with 2 choices - PDF, HTML
Depending on selection one of two Report pages show up, either Page 1 in HTML or Page 2 in PDF.

I am hoping I don't have to jump through hoops of JS or Drill to self buttons and there exists Cognos internal functionality using ReportOutput() or something like that allowing me to display 1 page in PDF format and another in HTML based on prompt selection. 

CognosPaul

You're going to have some hassle here. There's no native function to use a prompt to specify an export to PDF.

In this case, you can use the conditional layouts for the separate PDF and HTML layouts. Then no matter what method you use to run PDF or HTML, you'll get the correct results.

Again, I prefer the JS solution as it's an extension of the native export buttons found at the top. Take a look at the attached report.

AnalyticsWithJay

Quote from: CognosPaul on 11 May 2017 12:41:53 PM
Personally I don't like the drillthrough approach. It's a new request, meaning everything is run from scratch, and the drillthrough wizard doesn't always show all of the parameters. Using the export buttons is a much better proposal.

While I very much value your opinion, I'd have to respectfully disagree with the JS approach in this scenario. Since the report hasn't already rendered, there's no affect on performance as it is not running twice. I do agree with your approach though, if the desire is to have the buttons on the report page.

The other thing to consider is the maintenance of this code, as JS is a bit of a unique skillset in the BI world. While I love the flexibility of using JS, I'm hesitant to recommend it in places where there are alternatives, particularly if it's not fully using the native API.

cognosguru

Guys,

I was able to solve the issue of 2 different pages being displayed based on prompt selection either in PDF or HTML.  There are some aspects that are less than elegant but it works fast and does what I need.