Export CQ5.4/WEM Reports to Comma Separated Values (CSV)

Snapshot of exporting user report

Snapshot of exporting user report

The new Reporting Framework in CQ5.4 allows to generate customized reports on all available information. Example to help you monitor and analyze the state of your instance, CQ provides a selection of default reports, which can be configured for your individual requirements. More details click here.

This article describes three steps to export to csv.

  1. Overlay /libs/cq/reporting/components/reportpage/ to /apps/cq/reporting/components/reportpage/
  2. In /apps/cq/reporting/components/reportpage/body.jsp replace <body> section with [0] and save the changes.
  3. Navigate to the report you’d like to export. Click export link next to report title which will export report in csv format with the settings currently set in the report, so make sure that settings are as you would like them.

[0]

<body>
<script src=”/libs/cq/ui/resources/cq-ui.js” type=”text/javascript”></script>
<h2><%= actualTitle %>&nbsp;&nbsp;&nbsp;&nbsp;<a href=”javascript:exportCSV()”>Export</a></h2>
<%
if (description != null) {
%><p><%= description %></p><%
}
%>

<cq:include path=”report” resourceType=”<%= actualResourceType %>”/>

<script>
function convertJSON2CSV(objArray,rep)
{
var array = typeof objArray != ‘object’ ? JSON.parse(objArray) : objArray;
var str = ”;
for (var i = 0; i < array.length; i++) {
var line = ”;
for (var index in array[i]) {
if(line != ”){
line += ‘,’
}
if(typeof array[i][index] != ‘object’ ){
line += checkApplyClientFilter(array[i][index],index);
}else{
line += array[i][index].display;
}

}
str += line + ‘\r\n';
}
return str;
}

function checkApplyClientFilter(val,index){
var retStr = val ;
if(clientFilterList[index]){
retStr = clientFilterList[index](val);
}
return retStr;
}

function findClientFilter(rep){
for (var i = 0; i < rep.columns.length; i++) {
if(rep.columns[i].definitions.data && rep.columns[i].definitions.data.clientFilter){
clientFilterList[rep.columns[i].dataId] = rep.columns[i].definitions.data.clientFilter;
}
}
}

function downloadcsv(str){
if (navigator.appName != ‘Microsoft Internet Explorer’)
{
window.open(‘data:text/csv;charset=utf-8,’ + escape(str));
}
else
{
var popup = window.open(”,’csv’,”);
popup.document.body.innerHTML = ‘<pre>’ + str + ‘</pre>';
}
}

clientFilterList = [];

function exportCSV(){
var rep = CQ.reports.Report.theInstance;
var repurl= rep.reportPath + “.” + rep.reportSelector + CQ.HTTP.EXTENSION_JSON;
CQ.HTTP.get(repurl, function(options, success, response) {
if (success) {
var repData = CQ.Util.formatData(CQ.Ext.util.JSON.decode(response.responseText));
var csv = “result,”+ repData.resultsĀ  + ‘\r\n';
findClientFilter(rep);
csv = csv + convertJSON2CSV(JSON.parse(CQ.Ext.util.JSON.encode(repData.hits)),rep);
downloadcsv(csv);
}
}, this);
}
</script>
<div id=”CQ”>
<div id=”reportView”>
</div>
</div>
</body>

VN:F [1.9.22_1171]
Was this helpful? Please rate the content.
Rating: 0.0/10 (0 votes cast)
This entry was posted in Customer Experience Solutions and tagged , . Bookmark the permalink.

3 Responses to Export CQ5.4/WEM Reports to Comma Separated Values (CSV)

  1. Reyes Dishaw says:

    Hey all, generally converted into conscious of your weblog post thru Yahoo and google, and discovered it really is truly educational.