Whenever I need to modify any backend object (altering table, modifying view or changing function/procedure specifications etc.), then I search for object usage in APEX using "Application Search". Sometimes, I find several references for the object and I wish if I could just export them into a excel/csv file, so that I can review them at later point. However, there is no "export" functionality available in "Application Search" pop-up page (APEX Builder Application 4000, Page 8000).
So, I have written below JavaScript code to export search results into a CSV file.
(function () {
// CSV delimiter
var csvDelimiter = ",";
var encloseChar = '"';
// define array to hold search results
var refArr = [];
var refPath, refAttr, refPathPrev;
// add headers
refArr.push("Reference Path" + csvDelimiter + "Attribute");
// append search results to array
$("table.htmldbStandard3").each(function(){
refPath = $("td#PATH span strong",this).text();
refAttr = $("td.header:contains(Attribute)",this).next().text();
// if refPath is null, then use path from previous iteration
if (refPath)
refPathPrev = refPath;
else
refPath = refPathPrev;
// push row to array
if (refAttr)
refArr.push(encloseChar+refPath+encloseChar+csvDelimiter+encloseChar+refAttr+encloseChar);
});
// convert array to string, seperated by new line character
var refCSVData = refArr.join("\n");
// create dummy anchor tag for downloading data as CSV
var downloadLink = document.createElement("a");
downloadLink.setAttribute("href", "data:text/csv;charset=utf8," + encodeURIComponent(refCSVData));
downloadLink.setAttribute("download", "search_results.csv");
document.body.appendChild(downloadLink);
// trigger click event
downloadLink.click();
// remove dummy anchor
document.body.removeChild(downloadLink);
})();
In the "Application Search" pop-up page, right click anywhere and choose "inspect element" (or similar option). This will open browsers developer toolbar. Next, choose "Console" tab and paste above JS code and run. That's it.
I have been using this technique from long back. If I remember correctly, I have first used it with APEX ver 4.2. I have tested it with APEX version 20.1 and it's working fine. So, it should work with any APEX version between 4.2 and 20.1. It may work in future APEX versions as-well, if nothing gets changed in APEX "Application Search" page.
Note: If you use different separator for CSV file, then you can change "csvDelimiter" variable value accordingly. CSV column values are enclosed with "double quote" and its specified in "encloseChar" variable. You may need to change it, if either reference paths or attribute values have "double quote" in it.
Thank you.
Comments