I recently found an article about "[How to Intercept Interactive Report Save and Delete Functions in APEX][1]", very helpful! but i need to do some validations before this events and i don't know how to do it, I would like know if you could help me solve it.
The principal goal is to restrict the number of private reports that can save a user, example limit to 1 private report saved per user.
This is the code to intercept this events:
$(document).ready(function() {
$.widget("apex.interactiveReport", $.apex.interactiveReport, {
// Saving a Default report
_saveDefault: function () {
console.log("_saveDefault");
console.log(this);
console.log(this._getId("report_name"));
console.log('stopping');
// return this._super();
},
// Saving a Public or Private reports
_save: function () {
console.log('_save');
console.log(this);
console.log(this._getId("report_name"));
console.log('stopping');
// return this._super();
},
// Deleting a report (user clicking the "X")
_remove: function () {
console.log('_remove');
console.log(this);
console.log(this._getId("report_name"));
console.log('stopping');
// return this._super();
}
});
});```
[1]: https://www.talkapex.com/2019/02/how-to-intercept-interactive-report-save-and-delete-functions-in-apex/
Note that the blog post you are referencing is using undocumented features. There is no guarantee that that functionality will not change in future versions and they are not supported.
You could do this in a different (supported way) way, using the data dictionary views and the APEX_IR API. It's not as clean as doing it javascript (which by the way, I don't know how to implement).
Here is what I did (my app is 28183 and page is 7). The logic is that after refresh of the IR (if you save a private report, the region is refreshed), check in pl/sql if the max amounts of private reports is exceeded. If it is, delete the last one and inform the user with an alert.
BEGIN
select COUNT(report_id) INTO :P7_MAX_REACHED from APEX_APPLICATION_PAGE_IR_RPT where application_id = 28183 AND page_id = 7 AND report_type ='PRIVATE';
EXCEPTION WHEN OTHERS THEN
:P7_MAX_REACHED := 0;
END;
BEGIN
FOR r IN
(SELECT report_id, ROW_NUMBER() OVER (ORDER BY created_on ASC) AS rn
FROM APEX_APPLICATION_PAGE_IR_RPT where application_id = 28183 AND page_id = 7 AND report_type ='PRIVATE'
)
LOOP
IF r.rn > 1 THEN
APEX_IR.DELETE_REPORT(p_report_id => r.report_id);
END IF;
END LOOP;
END;