2

Cognos Analytics 11.1.7IF9

Searching the web for "Cognos report copy" produces many results about copying a report spec to the clipboard. That's not what this question is about.

Using the interactive viewer in Cognos Analytics means users can't select text to copy from the report and paste into other apps. A user has approached me with the requirement to copy individual values from a report output to the clipboard.

Running the report to the HTML output format is preferred because of some interactive capabilities in the report. Running to PDF would create an additional workload.

I can write web page that includes a script to make clicking on items I choose copy them to the clipboard:

(Adapted from https://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_hide)

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
  var arr = ["city", "country"];
  arr.forEach(function(e){
    $("span[lid='" + e + "']").click(function() {
      navigator.clipboard.writeText($(this).html());
    });
  });
});
</script>
</head>
<body>

<span lid="city">Click me to copy my City contents to the clipboard.</span><br /><br />
<span lid="country">Click me to copy my Country contents to the clipboard.</span><br /><br />
<span lid="region">Region contents are not copied</span><br /><br />
<span>I also do nothing</span><br /><br />

</body>
</html>

But I'm not having success with this in Cognos. I have attempted this by creating a sample report...

<report xmlns="http://developer.cognos.com/schemas/report/15.5/" useStyleVersion="11.6" expressionLocale="en-us">
    <drillBehavior/>
    <layouts>
        <layout>
            <reportPages>
                <page name="Page1">
                    <style>
                        <defaultStyles>
                            <defaultStyle refStyle="pg"/>
                        </defaultStyles>
                    </style>
                    <pageBody>
                        <style>
                            <defaultStyles>
                                <defaultStyle refStyle="pb"/>
                            </defaultStyles>
                        </style>
                        <contents>
                            <list horizontalPagination="true" name="List1" refQuery="Query1" rowsPerPage="9999">
                                <noDataHandler>
                                    <contents>
                                        <block>
                                            <contents>
                                                <textItem>
                                                    <dataSource>
                                                        <staticValue>No Data Available</staticValue>
                                                    </dataSource>
                                                </textItem>
                                            </contents>
                                            <style>
                                                <CSS value="padding:16px;"/>
                                            </style>
                                        </block>
                                    </contents>
                                </noDataHandler>
                                <style>
                                    <CSS value="border-collapse:collapse"/>
                                    <defaultStyles>
                                        <defaultStyle refStyle="ls"/>
                                    </defaultStyles>
                                </style>
                                <listColumns>
                                    <listColumn>
                                        <listColumnTitle>
                                            <style>
                                                <defaultStyles>
                                                    <defaultStyle refStyle="lt"/>
                                                </defaultStyles>
                                            </style>
                                            <contents>
                                                <textItem>
                                                    <dataSource>
                                                        <dataItemLabel refDataItem="City"/>
                                                    </dataSource>
                                                </textItem>
                                            </contents>
                                        </listColumnTitle>
                                        <listColumnBody>
                                            <style>
                                                <defaultStyles>
                                                    <defaultStyle refStyle="lc"/>
                                                </defaultStyles>
                                            </style>
                                            <contents>
                                                <textItem name="city">
                                                    <dataSource>
                                                        <dataItemValue refDataItem="City"/>
                                                    </dataSource>
                                                </textItem>
                                            </contents>
                                        </listColumnBody>
                                    </listColumn>
                                    <listColumn>
                                        <listColumnTitle>
                                            <style>
                                                <defaultStyles>
                                                    <defaultStyle refStyle="lt"/>
                                                </defaultStyles>
                                            </style>
                                            <contents>
                                                <textItem>
                                                    <dataSource>
                                                        <dataItemLabel refDataItem="Year"/>
                                                    </dataSource>
                                                </textItem>
                                            </contents>
                                        </listColumnTitle>
                                        <listColumnBody>
                                            <style>
                                                <defaultStyles>
                                                    <defaultStyle refStyle="lc"/>
                                                </defaultStyles>
                                            </style>
                                            <contents>
                                                <textItem>
                                                    <dataSource>
                                                        <dataItemValue refDataItem="Year"/>
                                                    </dataSource>
                                                </textItem>
                                            </contents>
                                        </listColumnBody>
                                    </listColumn>
                                    <listColumn>
                                        <listColumnTitle>
                                            <style>
                                                <defaultStyles>
                                                    <defaultStyle refStyle="lt"/>
                                                </defaultStyles>
                                            </style>
                                            <contents>
                                                <textItem>
                                                    <dataSource>
                                                        <dataItemLabel refDataItem="Revenue"/>
                                                    </dataSource>
                                                </textItem>
                                            </contents>
                                        </listColumnTitle>
                                        <listColumnBody>
                                            <style>
                                                <defaultStyles>
                                                    <defaultStyle refStyle="lm"/>
                                                </defaultStyles>
                                            </style>
                                            <contents>
                                                <textItem>
                                                    <dataSource>
                                                        <dataItemValue refDataItem="Revenue"/>
                                                    </dataSource>
                                                </textItem>
                                            </contents>
                                        </listColumnBody>
                                    </listColumn>
                                </listColumns>
                                <sortList>
                                    <sortItem refDataItem="City"/>
                                    <sortItem refDataItem="Year"/>
                                </sortList>
                            </list>
                            <customControl path="/CognosScripts/Copy.js">
                                <configuration>{
    &quot;SpansToCopy&quot;: [
        &quot;city&quot;
    ]
}</configuration>
                            </customControl>
                        </contents>
                    </pageBody>
                    <XMLAttributes>
                        <XMLAttribute output="no" name="RS_legacyDrillDown" value="0"/>
                    </XMLAttributes>
                </page>
            </reportPages>
        </layout>
    </layouts>
    <XMLAttributes>
        <XMLAttribute output="no" name="RS_CreateExtendedDataItems" value="true"/>
        <XMLAttribute output="no" name="listSeparator" value=","/>
        <XMLAttribute output="no" name="decimalSeparator" value="."/>
        <XMLAttribute output="no" name="RS_modelModificationTime" value="2015-11-25T21:38:24.820Z"/>
    </XMLAttributes>
    <queries>
        <query name="Query1">
            <source>
                <model/>
            </source>
            <selection>
                <dataItem aggregate="none" rollupAggregate="none" name="City">
                    <expression>[Sales (query)].[Branch].[City]</expression>
                    <XMLAttributes>
                        <XMLAttribute output="no" name="RS_dataType" value="3"/>
                        <XMLAttribute output="no" name="RS_dataUsage" value="0"/>
                    </XMLAttributes>
                </dataItem>
                <dataItem aggregate="total" name="Revenue">
                    <expression>[Sales (query)].[Sales].[Revenue]</expression>
                    <XMLAttributes>
                        <XMLAttribute output="no" name="RS_dataType" value="2"/>
                        <XMLAttribute output="no" name="RS_dataUsage" value="2"/>
                    </XMLAttributes>
                </dataItem>
                <dataItem aggregate="none" rollupAggregate="none" name="Year">
                    <expression>[Sales (query)].[Time].[Year]</expression>
                    <XMLAttributes>
                        <XMLAttribute output="no" name="RS_dataType" value="1"/>
                        <XMLAttribute output="no" name="RS_dataUsage" value="0"/>
                    </XMLAttributes>
                </dataItem>
            </selection>
        </query>
    </queries>
    <modelPath>/content/folder[@name=&apos;Samples&apos;]/folder[@name=&apos;Models&apos;]/package[@name=&apos;GO sales (query)&apos;]/model[@name=&apos;model&apos;]</modelPath>
    <reportName>copy</reportName>
</report>

...and adding a custom control:

define( ["jquery"], function() {
    "use strict";
    
    var log = function (label, message) {
        console.log("    ****    Copy :  " + label + " : " + message);
    };
    
    function Copy() {};
    
    Copy.prototype.initialize = function( oControlHost, fnDoneInitializing ) {
        log("Copy", "Control.initialize" );
        
        /*
        Sample Configuration:
        {
            "SpansToCopy": ["city", "country"]
        }
        
        If I name a text item in the report, the resulting span is given an attribute named "lid".
        */
    
        this.controlHost = oControlHost;
        this.oConfig = this.controlHost.configuration;
        
        $(document).ready(function(){
            this.oConfig.SpansToCopy.forEach(function(e){
                $("span[lid='" + e + "']").click(function() {
                    navigator.clipboard.writeText($(this).html());
                });
            });
        });
        
        fnDoneInitializing();
    };
    
    Copy.prototype.draw = function( oControlHost ) {};
    
    return Copy;
});

I'm getting...

jQuery.Deferred exception: e is not a function TypeError: e is not a function

...when the $(document).ready function runs.

Is there some incompatibility between current jQuery code and the version of jQuery Cognos is using?
Is there some scope issue I'm not seeing?
Other than reverting to the compatible viewer, is there a better way to enable the user to copy from the report output?

dougp
  • 2,810
  • 1
  • 8
  • 31

1 Answers1

0

The copy raw value functionality is available in 11.2 and higher.

https://www.ibm.com/docs/en/cognos-analytics/11.2.0?topic=reporting-copy-values-from-html-report-output

Daniel Wagemann
  • 741
  • 4
  • 6
  • Ah, the software vendor's promise: The heavily-used feature we removed will be reimplemented in a kludgy way in a future version as long as you continue paying us the license fee. Thanks for the info, but upgrading will take time for testing and, quite frankly, organizational change management. I have 3000 users who don't like change and the UI differences between 11.1 and 11.2 are dramatic enough I'll get backlash. But I suppose that by the time I have a solution, it will be time to upgrade. I guess I need to get better at RequireJS. – dougp Aug 08 '22 at 22:11
  • For anybody reading this: I have installed 11.2.3 and tried this. It kind of works. The "copy" tool places the value from the first single object selected onto the clipboard. You still can't select the entire page. If you have multiple items selected (like click a column body, SHIFT+click another column body) it doesn't copy the entire selection -- only the highlighted cell. After a discussion with the user who wanted this, it turned out he wanted to paste the value into another web-based app. I provided a click-through using a hyperlink instead. It works better than his plan. – dougp Sep 13 '22 at 15:21