Please note you will need jQuery for this example
Step 1: Create Log Table
CREATE TABLE tir_search_filter_log(
search_filter VARCHAR2(255) NULL,
search_date DATE DEFAULT SYSDATE NOT NULL,
username VARCHAR2(255) NOT NULL);
Step 2: Create Application Process
Create an On Demand Application Process. Call it: AP_LOG_SEARCH_FILTER
BEGIN
INSERT INTO tir_search_filter_log
(search_filter,
search_date,
username
)
VALUES (apex_application.g_x01,
SYSDATE,
:app_user
);
END;
Step 3: Create Interactive Report
Create a IR Page
SELECT *
FROM emp
Step 3: Javascript
Create a HTML region and add the following javascript code:
// Function to call our Application Process to log the search
function fLogSearch(){
var get = new htmldb_Get(null,$v('pFlowId'),'APPLICATION_PROCESS=AP_LOG_SEARCH_FILTER',$v('pFlowStepId'));
get.addParam('x01',$v('apexir_SEARCH')); // IR Search Filter Value
gReturn = get.get(); // Call AP Log Search Filter to insert log
// Call APEX IR Search
gReport.search('SEARCH');
}
// Run the following once the document is ready
$(document).ready(function(){
// -- Handle Go Button --
// Unbind all events. Important for order of execution
$('input[type="button"][value="Go"]').attr('onclick',''); //unbind click event
// Rebind events
$('input[type="button"][value="Go"]').click(function(){fLogSearch()});
// -- Handle "Enter" in input field --
$('#apexir_SEARCH').attr('onkeyup',''); //unbind onkeyup event
// Rebind Events
$('#apexir_SEARCH').keyup(function(event){($f_Enter(event))?fLogSearch():null;});
});
Great post & a smart solution!
ReplyDeleteRoel
hey martin ...great work its really gud for us (beginner)
ReplyDeleterommy
Hi Martin,
ReplyDeletereally nice! I was asked if your example is also possible without using jQuery and I want to share my findings. I also added a new parameter x02 which will hold the column name if the search is restricted to a specific column. I also avoid to redefine all the events, I just replace the existing search function of IR.
(function(){
var lOldSearch = gReport.search;
gReport.search = function(pThis){
if (pThis == 'SEARCH') {
// AJAX call to log the result
var lGet = new htmldb_Get(null,$v('pFlowId'),'APPLICATION_PROCESS=AP_LOG_SEARCH_FILTER',$v('pFlowStepId'));
lGet.addParam('x01',gReport.item.search().value); // IR Search Filter Value
lGet.addParam('x02',gReport.item.search_column().value); // IR Search Column
var lReturn = lGet.get(); // Call AP Log Search Filter to insert log
};
// execute original code
lOldSearch(pThis);
};
}());
Regards
Patrick
Hi Patrick,
ReplyDeleteThanks for the feedback and the updated solution.
Martin
Hey Patrick,
ReplyDeleteI am new to Apex. I want to add this functionality to my Project without using jQery but not understanding where I can put this code and how this code will get triggered i.e. on which event it will call this function?
Could you please help me on this?