Saturday, 31 August 2013

When clicking on report link populate confirm dialogue box and then process the record

When clicking on report link populate confirm dialogue box and then process the record : 

Create a report with delete option : 
Create one text item to hold the selected empno when click on report link (delete) ex : P1_DELETE_EMP

Go to report attributes > 'Delete' column attributes >
Add below java script in URL field : 

javascript:apex.confirm('Are you sure you want to delete this record', {request: 
'DELETE',SET : {'P1_DELETE_EMP': #EMPNO#}})

Write a PL/SQL process to delete the selected record : 
Add condition to the process : 
Request = Expression1 
Expressoin : 'DELETE'
 That's it, when you click on delete report link you can see the confirm dialogue box and clicking on 'OK', Record will be deleted.

Wednesday, 28 August 2013

Scheduling Reports



Scheduling a report(s) from the database using APEX utility : 

Till now using subscription, we can schedule the interactive report only.
Most cases we may get requirement to schedule the multiple reports with custom
definitions.

Here is the example to schedule a report from database using APEX utility.
 
 

 1. Create a stored procedure as below.

create or replace procedure Employee
as
l_body_html CLOB;
l_body CLOB;
BEGIN
l_body:= 'Employee Report';
l_body_html := l_body_html || '<font color="green"><center><h3>Employee
Report</h3><br><h3>Employee Report</h3></center></font><table border="1"
width="100%" ><tr bgcolor="#CEE3F6"><td align="center">Empno</td><td
align="center">Employee Name</td><td align="center">Job</td><td
align="center">Salary</td></tr>';
for c1 in(Select empno,ename,job from emp)
loop
l_body_html :=l_body_html || '<tr><td>' || c1.empno || '</td>' || '<td>' || c1.ename
|| '</td>' || '<td>' || c1.Job || '</td></tr>';
end loop;
l_body_html :=l_body_html || '</table>';
apex_mail.send(
p_to => 'to@test.com
',
p_from => 'from@test.com
',
p_body => l_body,
p_body_html => l_body_html,
p_subj => 'Employee Report',
p_bcc => 'bcc users@test.com
');
END Employee;
 

 2. Create a job to schedule the report. 

 
Schduler : 
BEGIN
 dbms_scheduler.create_schedule(  
schedule_name  => 'Employee_Schedule',  
  start_date         => trunc(sysdate),  
  repeat_interval => 'freq=Daily;Day='Mon',  
  comments        => 'Runtime: Every Monday ');
END;

Program : 
begin  
-- Call a procedure  
dbms_scheduler.create_program  
(program_name=> 'Employee_Program',  
 program_type=> 'STORED_PROCEDURE',  
 program_action=> ?Employee? ,  
 enabled=>true,  
 comments=>'Procedure to collect session information'  
 );  
end;


Job :
begin  
-- Connect both dbms_scheduler parts by creating the final job  
dbms_scheduler.create_job  
 (job_name => 'Employee_Job',  
  program_name=> 'Employee_Program',  
  schedule_name=>'Employee_Schedule',  
  enabled=>true,  
  auto_drop=>false,  
  comments=>'Job to collect data about session values every 5 minutes');  
end;
 

 Below is the screenshot for report : 

 
 

Monday, 26 August 2013


ORA-24247: network access denied by access control list (ACL) tips

Assume that you have successfully installed or upgrade your APEX, but when you tried to send an email, it's not working and you are able to see the above error in APEX_MAIL_QUEUE log.

Reason : The database user don't have a necessary permissions.

Below are some steps you need follow/check :

1. Run the below procedure as SYS user where APEX installed.

   
DECLARE
ACL_PATH VARCHAR2(4000);
BEGIN
-- Look for the ACL currently assigned to '*' and give APEX_040200
-- the "connect" privilege if APEX_040200 does not have the privilege yet.
SELECT ACL INTO ACL_PATH FROM DBA_NETWORK_ACLS
WHERE HOST = '*' AND LOWER_PORT IS NULL AND UPPER_PORT IS NULL;
IF DBMS_NETWORK_ACL_ADMIN.CHECK_PRIVILEGE(ACL_PATH, 'APEX_040200',
'connect') IS NULL THEN
DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE(ACL_PATH,
'APEX_040200', TRUE, 'connect');
END IF;
EXCEPTION
-- When no ACL has been assigned to '*'.
WHEN NO_DATA_FOUND THEN
DBMS_NETWORK_ACL_ADMIN.CREATE_ACL('power_users.xml',
'ACL that lets power users to connect to everywhere',
'APEX_040200', TRUE, 'connect');
DBMS_NETWORK_ACL_ADMIN.ASSIGN_ACL('power_users.xml','*');
END;
/
COMMIT;


Above procedure will check the ACL's list and it will give the necessary permissions to the database user.

NOTE : Need to change the database user according to your APEX version.

2. Assign ACL to your SMTP host address

begin
  DBMS_NETWORK_ACL_ADMIN.ASSIGN_ACL(
  ACL  => 'power_users.xml',
  host => 'localhost'
  );
  commit;
end;


Introduction

Oracle Application Express (Oracle APEX), formerly called HTML DB, is a fully supported "no-cost" option of the Oracle Database. Oracle Application Express is certified against all editions of the Oracle Database 10.2.0.3 and above, including Oracle Database 10g Express Edition (Oracle XE).
Oracle Application Express installs as part of the seed database installation with Oracle Database 11g. The latest version of Oracle Application Express can be downloaded for free from the Oracle Technology Network (OTN) [http://otn.oracle.com/apex]