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

Drill through to open a small new window using javascript

Started by bioCam, 04 Sep 2013 09:49:27 PM

Previous topic - Next topic

bioCam

Hi,

The Shipment Report has all the Cargo and its short description (1st 100 words only).  There is a hyperlink to click to open a new window that will display the full cargo description and an image of the location of the cargo in the ship.

I could use the drill through method to achieve this but I prefer to use javascript to open a new window because I do not want to see all other icons in the Cognos report if I use the drill through method.

Is this possible?  If yes, could you please let me know how to achieve this?  Thank you in advance.

CognosPaul

Drillthroughs probably won't meet your needs. There are simply no options in the drillthrough definitions which control the window that's opened. What you probably can do is set up a button that runs a javascript function that will open a window to the report.

For example, you can create the report let's call it cargo description. The report takes one parameter, cargo ID. So we can open the report directly using:
http://server/ibmcognos/cgi-bin/cognosisapi.dll?b_action=cognosViewer&ui.action=run&ui.object=%2fcontent%2ffolder%5b%40name%3d%27Reports%27%5d%2freport%5b%40name%3d%27cargo%20description%27%5d&ui.name=report%20runs&run.outputFormat=&run.prompt=false&cv.header=false&cv.toolbar=false&p_cargoid=123

Note that the parameter is being called with p_. So if, in your report, you're using p_cargoid url would be p_p_cargoid.

That will open the report without the toolbar and header. Now you just need the button. Let's make it easier on ourselves and define a JS function. Drag in an HTML item to the top of the page and paste this in:

<script>
<script>
function openCargo(id){
  var url='http://server/ibmcognos/cgi-bin/cognosisapi.dll?b_action=cognosViewer&ui.action=run&ui.object=%2fcontent%2ffolder%5b%40name%3d%27Reports%27%5d%2freport%5b%40name%3d%27cargo%20description%27%5d&ui.name=report%20runs&run.outputFormat=&run.prompt=false&cv.header=false&cv.toolbar=false&p_cargoid='+id
  , params = 'width=640, height=480, status=no, menubar=no, toolbar=no';
  win = window.open(url, 'cargoDescription',params);
  win.focus();
}
</script>


Next, drag an HTML item into the list, set it to report expression, and use the following expression:

'<input type="button" onclick="openCargo('+[Query].[Cargo ID]+')" value="Cargo Description"/>'

Make sure you include the Cargo ID field in the properties of the list or you'll get a error.

bioCam

Thank you CognosPaul.  I will try this out and let you know how it goes.

torre2011

I have attempted to utilize the suggested javascript function within my own report...so that I could open a new window and pass appropriate parameters. 

Unfortunately I am getting an windows error stating that the value of the 'ID' is Undefined!

Here is the script I am using:

<script>
function openInsertComments(id){
  var url='http://servername/cognos10/cgi-bin/cognosisapi.dll?b_action=cognosViewer&ui.action=run&ui.object=%2fcontent%2fpackage%5b%40name%3d%27COMMENT_TEST%27%5d%2freport%5b%40name%3d%27Comments%20Test%27%5d&ui.name=Comments%20Test&run.outputFormat=&run.prompt=false&cv.header=false&cv.toolbar=false&p_pMemberID='+id, params = 'width=640, height=480, status=no, menubar=no, toolbar=no';
  win = window.open(url, 'InsertComments',params);
  win.focus();
}
</script>

..and here is the HTML item that I added to the list, and changed to a Report Expression:
'<input type="button" onclick="openInsertComments('+[Query].[MEMBER_ID]+')" value="Insert Comments"/>'
So i see no error when the report loads, but when I click on the button in the list, it shows the error...and it is accurately grabbing the MEMBER_ID but seems not to know what to do with it.  Below is a sample of the error:

Webpage error details

Message: 'A0303870500' is undefined
Line: 157
Char: 1
Code: 0
URI: http://cognosdev/cognos10/cgi-bin/cognosisapi.dll


Is there any suggestions you could give to assist me here?  Thanks!

CognosPaul

change
'<input type="button" onclick="openInsertComments('+[Query].[MEMBER_ID]+')" value="Insert Comments"/>'

to
'<input type="button" onclick="openInsertComments('''+[Query].[MEMBER_ID]+''')" value="Insert Comments"/>'

The problem is Cognos is resolving the expression to:

<input type="button" onclick="openInsertComments(A0303870500)" value="Insert Comments"/>

so when you try to run the report, the JS engine is looking for the variable A0303870500, which doesn't exist and is therefor undefined. By adding a quote before and after, you're turning that into a string. Because this is a report expression, you need to escape the single quote with another quote. So

'test(''' + [MEMBER_ID] + ''')'

will resolve to
test('A0303870500')

torre2011

Thanks for the reply...this does make sense!

Unfortunately, for some reason I am unable to get past a javascript error - Expected ')'

I have used everything exactly as was stated in this thread, with the only change being the one you suggested.

But here it is again:
Javascript
<script>
function openInsertComments(id){
  var url='http://servername/cognos10/cgi-bin/cognosisapi.dll?b_action=cognosViewer&ui.action=run&ui.object=%2fcontent%2fpackage%5b%40name%3d%27COMMENT_TEST%27%5d%2freport%5b%40name%3d%27Comments%20Test%27%5d&ui.name=Comments%20Test&run.outputFormat=&run.prompt=false&cv.header=false&cv.toolbar=false&p_pMemberID='+id, params = 'width=640, height=480, status=no, menubar=no, toolbar=no';
  win = window.open(url, 'InsertComments',params);
  win.focus();
}
</script>

HTML within Report Expression:
'<input type="button" onclick="openInsertComments('''+[Query].[MEMBER_ID]+''')" value="Insert Comments"/>'

Am I missing something??

torre2011

...as a follow up...i noticed that if i remove one of the single quotes from around the data item within the report expression, it treats the data item [Query].[MEMBER_ID] as a string...output is --> '[Query].[MEMBER_ID]' ..rather than 'A0303870500'.

So i am trying to figure out how to get the function to recognize the data item as a data object rather than a string...


CognosPaul

I can't debug the problem from here - the JS looks fine. Have you ever used web developer tools before? If you're using IE, press F12 and go to the scripts tab. Refresh the report, and when you get the error you'll be able to click on the error in the console to see the problematic script.

If you're still having problems, attach the report xml here and I'll take a look.

torre2011

No I have not used tools like that in some time...even then only a little.

So it seems to be referring to the following line of code within the report:

<div id="cvSkipToNavigationRS" style="display:none;" class="skip"><a accesskey="n" href="#CVNavLinksRS">Skip to page navigation. Ctrl + Shift + n link.</a></div>

Not sure what is wrong with this???

Below is the xml for the report:
<report xmlns="http://developer.cognos.com/schemas/report/9.0/" useStyleVersion="10" expressionLocale="en-us">
<modelPath>/content/package[@name='COMMENT_TEST']/model[@name='model']</modelPath>
<drillBehavior modelBasedDrillThru="true"/>
<queries>
<query name="Query">
<source>
<model/>
</source>
<selection autoSummary="false"><dataItem name="MEMBER_ID" aggregate="none" rollupAggregate="none"><expression>[DIWD1].[SC_COMMENT_TEST].[MEMBER_ID]</expression><XMLAttributes><XMLAttribute name="RS_dataType" value="3" output="no"/><XMLAttribute name="RS_dataUsage" value="attribute" output="no"/></XMLAttributes></dataItem><dataItem name="MEMBER_LASTNAME" aggregate="none" rollupAggregate="none"><expression>[DIWD1].[SC_COMMENT_TEST].[MEMBER_LASTNAME]</expression><XMLAttributes><XMLAttribute name="RS_dataType" value="3" output="no"/><XMLAttribute name="RS_dataUsage" value="attribute" output="no"/></XMLAttributes></dataItem><dataItem name="MEMBER_FIRSTNAME" aggregate="none" rollupAggregate="none"><expression>[DIWD1].[SC_COMMENT_TEST].[MEMBER_FIRSTNAME]</expression><XMLAttributes><XMLAttribute name="RS_dataType" value="3" output="no"/><XMLAttribute name="RS_dataUsage" value="attribute" output="no"/></XMLAttributes></dataItem><dataItem name="PRODUCT_CAT_CODE" aggregate="none" rollupAggregate="none"><expression>[DIWD1].[SC_COMMENT_TEST].[PRODUCT_CAT_CODE]</expression><XMLAttributes><XMLAttribute name="RS_dataType" value="3" output="no"/><XMLAttribute name="RS_dataUsage" value="attribute" output="no"/></XMLAttributes></dataItem><dataItem name="COMMENTS" aggregate="none" rollupAggregate="none"><expression>[DIWD1].[SC_COMMENT_TEST].[COMMENTS]</expression><XMLAttributes><XMLAttribute name="RS_dataType" value="3" output="no"/><XMLAttribute name="RS_dataUsage" value="attribute" output="no"/></XMLAttributes></dataItem><dataItem name="LOAD_DATE" aggregate="none" rollupAggregate="none"><expression>[DIWD1].[SC_COMMENT_TEST].[LOAD_DATE]</expression><XMLAttributes><XMLAttribute name="RS_dataType" value="4" output="no"/><XMLAttribute name="RS_dataUsage" value="identifier" output="no"/></XMLAttributes></dataItem><dataItem name="ADDED_BY" aggregate="none" rollupAggregate="none"><expression>[DIWD1].[SC_COMMENT_TEST].[ADDED_BY]</expression><XMLAttributes><XMLAttribute name="RS_dataType" value="3" output="no"/><XMLAttribute name="RS_dataUsage" value="unknown" output="no"/></XMLAttributes></dataItem><dataItem name="UROW" aggregate="none" rollupAggregate="none"><expression>[DIWD1].[SC_COMMENT_TEST].[UROW]</expression><XMLAttributes><XMLAttribute name="RS_dataType" value="3" output="no"/><XMLAttribute name="RS_dataUsage" value="unknown" output="no"/></XMLAttributes></dataItem><dataItem name="Update"><expression>'Update'</expression></dataItem><dataItem name="Insert"><expression>'Insert'</expression></dataItem><dataItem name="User"><expression>#sq($account.defaultName)#</expression></dataItem></selection>
<queryHints><localCache value="false"/></queryHints></query>
</queries>
<layouts>
<layout>
<reportPages>
<page name="Page1"><style><defaultStyles><defaultStyle refStyle="pg"/></defaultStyles></style>
<pageBody><style><defaultStyles><defaultStyle refStyle="pb"/></defaultStyles></style>
<contents>
<promptButton type="reprompt">
<contents/>
<style>
<defaultStyles>
<defaultStyle refStyle="bp"/>
</defaultStyles>
</style>
</promptButton><list horizontalPagination="true" name="List1" rowsPerPage="1000" refQuery="Query">
<noDataHandler>
<contents>
<block>
<contents>
<textItem>
<dataSource>
<staticValue>No Data Available</staticValue>
</dataSource>
<style>
<CSS value="padding:10px 18px;"/>
</style>
</textItem>
</contents>
</block>
</contents>
</noDataHandler>
<style>
<defaultStyles>
<defaultStyle refStyle="ls"/>
</defaultStyles>
<CSS value="border-collapse:collapse"/>
</style>
<listColumns><listColumn><listColumnTitle><style><defaultStyles><defaultStyle refStyle="lt"/></defaultStyles></style><contents><textItem><dataSource><dataItemLabel refDataItem="MEMBER_ID"/></dataSource></textItem></contents></listColumnTitle><listColumnBody><style><defaultStyles><defaultStyle refStyle="lc"/></defaultStyles></style><contents><textItem><dataSource><dataItemValue refDataItem="MEMBER_ID"/></dataSource></textItem></contents></listColumnBody></listColumn><listColumn><listColumnTitle><style><defaultStyles><defaultStyle refStyle="lt"/></defaultStyles></style><contents><textItem><dataSource><dataItemLabel refDataItem="MEMBER_LASTNAME"/></dataSource></textItem></contents></listColumnTitle><listColumnBody><style><defaultStyles><defaultStyle refStyle="lc"/></defaultStyles></style><contents><textItem><dataSource><dataItemValue refDataItem="MEMBER_LASTNAME"/></dataSource></textItem></contents></listColumnBody></listColumn><listColumn><listColumnTitle><style><defaultStyles><defaultStyle refStyle="lt"/></defaultStyles></style><contents><textItem><dataSource><dataItemLabel refDataItem="MEMBER_FIRSTNAME"/></dataSource></textItem></contents></listColumnTitle><listColumnBody><style><defaultStyles><defaultStyle refStyle="lc"/></defaultStyles></style><contents><textItem><dataSource><dataItemValue refDataItem="MEMBER_FIRSTNAME"/></dataSource></textItem></contents></listColumnBody></listColumn><listColumn><listColumnTitle><style><defaultStyles><defaultStyle refStyle="lt"/></defaultStyles></style><contents><textItem><dataSource><dataItemLabel refDataItem="PRODUCT_CAT_CODE"/></dataSource></textItem></contents></listColumnTitle><listColumnBody><style><defaultStyles><defaultStyle refStyle="lc"/></defaultStyles></style><contents><textItem><dataSource><dataItemValue refDataItem="PRODUCT_CAT_CODE"/></dataSource></textItem></contents></listColumnBody></listColumn><listColumn><listColumnTitle><style><defaultStyles><defaultStyle refStyle="lt"/></defaultStyles></style><contents><textItem><dataSource><dataItemLabel refDataItem="COMMENTS"/></dataSource></textItem></contents></listColumnTitle><listColumnBody><style><defaultStyles><defaultStyle refStyle="lc"/></defaultStyles></style><contents><textItem><dataSource><dataItemValue refDataItem="COMMENTS"/></dataSource></textItem></contents></listColumnBody></listColumn><listColumn><listColumnTitle><style><defaultStyles><defaultStyle refStyle="lt"/></defaultStyles></style><contents><textItem><dataSource><dataItemLabel refDataItem="LOAD_DATE"/></dataSource></textItem></contents></listColumnTitle><listColumnBody><style><defaultStyles><defaultStyle refStyle="lc"/></defaultStyles></style><contents><textItem><dataSource><dataItemValue refDataItem="LOAD_DATE"/></dataSource></textItem></contents></listColumnBody></listColumn><listColumn><listColumnTitle><style><defaultStyles><defaultStyle refStyle="lt"/></defaultStyles></style><contents><textItem><dataSource><staticValue>Insert New Comment</staticValue></dataSource></textItem></contents></listColumnTitle><listColumnBody><style><defaultStyles><defaultStyle refStyle="lc"/></defaultStyles></style><contents><HTMLItem>
<dataSource>
<reportExpression>'&lt;input type="button" onclick="openInsertComments('''+[Query].[MEMBER_ID]+''')" value="Insert Comments"/&gt;'
</reportExpression></dataSource>
</HTMLItem></contents></listColumnBody></listColumn><listColumn><listColumnTitle><style><defaultStyles><defaultStyle refStyle="lt"/></defaultStyles></style><contents><textItem><dataSource><dataItemLabel refDataItem="ADDED_BY"/></dataSource></textItem></contents></listColumnTitle><listColumnBody><style><defaultStyles><defaultStyle refStyle="lc"/></defaultStyles></style><contents><textItem><dataSource><dataItemValue refDataItem="ADDED_BY"/></dataSource></textItem></contents></listColumnBody></listColumn><listColumn><listColumnTitle><style><defaultStyles><defaultStyle refStyle="lt"/></defaultStyles></style><contents><textItem><dataSource><dataItemLabel refDataItem="UROW"/></dataSource></textItem></contents></listColumnTitle><listColumnBody><style><defaultStyles><defaultStyle refStyle="lc"/></defaultStyles></style><contents><textItem><dataSource><dataItemValue refDataItem="UROW"/></dataSource></textItem></contents></listColumnBody></listColumn></listColumns><sortList><sortItem refDataItem="LOAD_DATE"/></sortList><propertyList><propertyItem refDataItem="MEMBER_ID"/><propertyItem refDataItem="MEMBER_LASTNAME"/><propertyItem refDataItem="MEMBER_FIRSTNAME"/><propertyItem refDataItem="PRODUCT_CAT_CODE"/><propertyItem refDataItem="COMMENTS"/><propertyItem refDataItem="LOAD_DATE"/><propertyItem refDataItem="ADDED_BY"/><propertyItem refDataItem="UROW"/><propertyItem refDataItem="Update"/><propertyItem refDataItem="Insert"/><propertyItem refDataItem="User"/></propertyList></list>
</contents>
</pageBody>
<pageHeader>
<contents>
<HTMLItem>
<dataSource>
<staticValue>&lt;script&gt;
function openInsertComments(id){
  var url='http://servername:80/cognos10/cgi-bin/cognosisapi.dll?b_action=cognosViewer&amp;ui.action=run&amp;ui.object=%2fcontent%2fpackage%5b%40name%3d%27COMMENT_TEST%27%5d%2freport%5b%40name%3d%27Comments%20Test%27%5d&amp;ui.name=Comments%20Test&amp;run.outputFormat=&amp;run.prompt=false&amp;cv.header=false&amp;cv.toolbar=false&amp;p_pMemberID='+id, params = 'width=640, height=480, status=no, menubar=no, toolbar=no';
  win = window.open(url, 'InsertComments',params);
  win.focus();
}
&lt;/script&gt;</staticValue>
</dataSource>
</HTMLItem><block><style><defaultStyles><defaultStyle refStyle="ta"/></defaultStyles></style>
<contents>
<textItem><style><defaultStyles><defaultStyle refStyle="tt"/></defaultStyles></style>
<dataSource>
<staticValue/>
</dataSource>
</textItem>
</contents>
</block>
</contents>
<style>
<defaultStyles>
<defaultStyle refStyle="ph"/>
</defaultStyles>
<CSS value="padding-bottom:10px"/>
</style>
</pageHeader>
<pageFooter>
<contents>
<table>
<tableRows>
<tableRow>
<tableCells>
<tableCell>
<contents>
<date>
<style>
<dataFormat>
<dateFormat/>
</dataFormat>
</style>
</date>
</contents>
<style>
<CSS value="vertical-align:top;text-align:left;width:25%"/>
</style>
</tableCell>
<tableCell>
<contents>
<pageNumber/>
</contents>
<style>
<CSS value="vertical-align:top;text-align:center;width:50%"/>
</style>
</tableCell>
<tableCell>
<contents>
<time>
<style>
<dataFormat>
<timeFormat/>
</dataFormat>
</style>
</time>
</contents>
<style>
<CSS value="vertical-align:top;text-align:right;width:25%"/>
</style>
</tableCell>
</tableCells>
</tableRow>
</tableRows>
<style>
<defaultStyles>
<defaultStyle refStyle="tb"/>
</defaultStyles>
<CSS value="border-collapse:collapse;width:100%"/>
</style>
</table>
</contents>
<style>
<defaultStyles>
<defaultStyle refStyle="pf"/>
</defaultStyles>
<CSS value="padding-top:10px"/>
</style>
</pageFooter>
</page>
</reportPages>
</layout>
</layouts>
<XMLAttributes><XMLAttribute name="RS_CreateExtendedDataItems" value="true" output="no"/><XMLAttribute name="listSeparator" value="," output="no"/><XMLAttribute name="RS_modelModificationTime" value="2014-03-14T18:48:29.950Z" output="no"/></XMLAttributes><reportName>Parent Comments Test</reportName><reportVariables><reportVariable type="boolean" name="varTest">
<reportExpression>ParamDisplayValue('pComments') is null</reportExpression>
<variableValues>
<variableValue value="1"/>
</variableValues>
</reportVariable></reportVariables></report>

CognosPaul

I've converted your report to the Sales and Marketing cube, replaced Member ID with Product Line, and it runs perfectly. Can you check your data? Is it possible there is a MEMBER ID with a single quote? Are there any with spaces? Are there any with null values?

torre2011

YUP!   That was it  :D

Now that obstacle is overcome, i wanted to add a few more components to the function, and it seems that when I add more variables, i am not able to pass all the appropriate parameters???  Puzzling!

Here is a new function:
<script>
function openUpdateComments(id,lname,fname,user,urow){
  var url='http://servername/cognos10/cgi-bin/cognosisapi.dll?b_action=cognosViewer&ui.action=run&ui.object=%2fcontent%2fpackage%5b%40name%3d%27COMMENT_TEST%27%5d%2freport%5b%40name%3d%27Update%20Comments%27%5d&ui.name=Update%20Comments&run.outputFormat=&run.prompt=true&cv.header=false&cv.toolbar=false&p_pMemberID='+id+'+&p_pMemberLastName='+lname+'+&p_pMemberFirstName='+fname+'+&p_pUser='+user+'+&p_pUROW='+urow, params = 'width=640, height=480, status=no, menubar=no, toolbar=no';
  win = window.open(url, 'UpdateComments',params);
  win.focus();
}
</script>

Here is the Report Expression:
'<input type="button" onclick="openUpdateComments('''+[Query].[MEMBER_ID]+''','''+[Query].[MEMBER_LASTNAME]+''','''+[Query].[MEMBER_FIRSTNAME]+''','''+[Query].[User]+''','''+[Query].[UROW]+''')" value="Update Comments"/>'
Why i assume it is due to not all of the parameters passing, is that when I turn on the run.prompt, the 2 required prompts (MEMBER_ID and UROW) appear, but only UROW has a value.  So when I select a MEMBER_ID from the value in the prompt page, it takes me to the report, and runs as it should.

But when I turn off the run.prompt, it will not pass the parameter not allowing the report to run properly.

I should note, that the target report is tied to a stored procedure that is looking for values to be passed to the variables...not sure if that helps in assisting me, but I thought i should include ;)

So, if you have any ideas, I would be glad to hear them, but regardless, I am glad to have learned something thus far!

torre2011

I forgot to add, that the drill through to this specific report works as it should, and I have copied over all the correct parameters to pass to the target report.  So this at least tells me the target report is working fine once the correct parameters are passed to it.

Thanks Again!