Skip to main content

Export Application Search Results to CSV file

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.

Export Application Search Results to CSV file

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

Popular posts from this blog

Interactive Grid - Conditional Enable/Disable

In this blogpost, I am going to discuss few approaches using which we can conditionally enable/disable Interactive Grid (IG) column(s) based on other column(s) values. Note:    There is a bug  30801170  in APEX 19.2/20.1 with respect to "enable/disable" dynamic actions for IG columns. Workaround for this bug is provided at the end of this blogpost . This bug has been fixed in APEX version 20.2. Client Side Only Conditions If conditions to enable/disable are simple, then we can check those conditions easily on the client side. For e.g. let's consider IG on EMP table with following SQL Query. SELECT EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO FROM EMP Let's consider the requirement as - Enable "Commission" column only when JOB is equals to 'SALESMAN' and disable "Commission" column in all other cases. This can be done declaratively using dynamic actions (DA) DA "Enable/Disable Commission - 1" Create DA and give it a prope...

Interactive Grid - Bulk Operation on Selected Rows

What's the Problem? Let's say you have an IG on employee table and you want to update selected employees commission based on user's input. Ideally, it should be very simple, where you can write UPDATE statement in page process and select IG region as "Editable Region" under "Execution Options" of the page process. But, when you select rows and submit page, you can see that, this process won't get executed! The reason is  Selection of 'Row Selector' check-boxes is not considered as row-change. Thus selected rows are not submitted to server. So, is there any work around?  Yes! Luckily there are lot of JavaScript (JS) APIs available to work with IG. If you are not already aware, you can refer "APEX IG Cookbook"  or  JavaScript API Reference documentation. If we continue with above Employee IG example, when user selects IG rows, enters "Commission %" and clicks on "Update Commission" button, then we can writ...

Interactive Grid - Process Filtered Data on Server Side

Recently one of the APEX developers has reached out to me and asked if it's possible to capture filtered rows data of the Interactive Grid on the server-side and do some processing. In APEX 20.1, there is a new API APEX_IG , using which we can achieve this. Photo by Jakub Kapusnak on Unsplash The approach is very simple and straightforward. Get the internal region id based on the Static ID given for the IG region Get the last viewed report id based on region id Open query context for the region and report using region id and report id Fetch and loop through the rows using the query context Do something with fetched rows And finally, close the query context If you have already done this for interactive reports, then you should be already aware of these steps. The only difference here is, we use APEX_IG APIs instead of APEX_IR APIs. For the demo purpose, let's Build an Interactive Grid on EMP table and let's give it a Static ID as emp Create a Textarea page item with...