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

Author Topic: Copying from report output  (Read 139 times)

Offline dougp

  • Statesman
  • ******
  • Join Date: Jul 2014
  • Posts: 790
  • Forum Citizenship: +29/-1
Copying from report output
« on: 27 Jul 2022 02:14:38 pm »
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)


But I'm not having success with this in Cognos.  I have attempted this by creating a sample report and adding a custom control:

Code: [Select]
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...

Quote
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? 


This site doesn't seem to like source code.  For more details, see https://stackoverflow.com/questions/73143394/copying-from-report-output