You are on page 1of 16

Setup For Concurrent Request output sending as Email Notification

Objective
The purpose of the white paper is to send the output of a concurrent request as an email notification
which not available in 11.5.8 version normally. Here we want to send a mail notification which contains
collective informations from various modules of the past week. Through which business users will have a
gist of information about all the necessary data.
The white paper will be useful for the starters to get an idea about the steps to follow to map the
concurrent request output to the email notification.
Here we want to know collective details of total sales, total payables, and total receipts of the past
week. So that for the reporting purpose and for collection purpose the next week tasks will be easy.
Step 1) Defining the E-mail id for the notified users
In order to send the attachment to the notified users, first we need to define the e-mail id of the users. This is
to be done in Inventory Responsibility as shown in the below mentioned screen shot.
Responsibility: SKG India Local Inventory ==>
Setup ==>

Lookups ==>

Query on Type SONA THROUGHPUT EMAIL USERS

Code
Meaning
Description
Tag

==>
==>
==>
==>

User Name
Email Address
Department
CC / TO / BCC (Upper or Lower)
Page 1 of 16

Created by: Kannan Mahalingam,


Oracle Apps Technical Consultant

Chain-sys India Pvt. Ltd.

Setup For Concurrent Request output sending as Email Notification


Step 2) Define Printer
Here we are to copy the concurrent request output file from report directory to \usr\tmp
Directory. So we would create a printer named COPY and printer type as EPSON.

Here we have to create a printer driver named COPYTEST

And the argument is cp $PROFILES$.FILENAME /usr/tmp


Page 2 of 16

Created by: Kannan Mahalingam,


Oracle Apps Technical Consultant

Chain-sys India Pvt. Ltd.

Setup For Concurrent Request output sending as Email Notification

Here we are adding the paper size with COPYTEST driver.

Page 3 of 16

Created by: Kannan Mahalingam,


Oracle Apps Technical Consultant

Chain-sys India Pvt. Ltd.

Setup For Concurrent Request output sending as Email Notification


In the following picture extract the report RDF we add the following script in after report trigger

In the following we are calling the procedure sona_utilities.throughput_email_concurrent


FUNCTION afterreport
RETURN BOOLEAN
IS
l_copies
NUMBER;
l_printer
VARCHAR2 (30);
BEGIN
SELECT number_of_copies, printer
INTO l_copies, l_printer
FROM fnd_concurrent_requests
WHERE request_id = :p_conc_request_id;
IF l_copies = 1 AND l_printer = 'COPY'
THEN
BEGIN
sona_utilities.throughput_email_concurrent (:p_conc_request_id,
:p_from_date,
:p_to_date,
:p_segment2
);
SRW.MESSAGE ('1', 'Email Concurrent Success');
EXCEPTION
WHEN OTHERS
THEN
SRW.MESSAGE ('1', 'Email Concurrent Failed');
END;
ELSE
SRW.MESSAGE
('1','Please select Printer is "COPY" and give number of copies = 1');
END IF;
RETURN (TRUE);
END;
Page 4 of 16

Created by: Kannan Mahalingam,


Oracle Apps Technical Consultant

Chain-sys India Pvt. Ltd.

Setup For Concurrent Request output sending as Email Notification


sona_utilities.throughput_email_concurrent
The following is script of the procedure sona_utilities.throughput_email_concurrent

PROCEDURE THROUGHPUT_EMAIL_CONCURRENT (
p_request_id
IN
VARCHAR2,
p_from_date
IN
DATE,
p_to_date
IN
DATE,
p_company
IN
VARCHAR2
)
IS
v_request_id
NUMBER;
BEGIN
fnd_global.apps_initialize (6871, 50095, 401);
v_request_id :=
fnd_request.submit_request
(application
=>
program
=>
description
=>
start_time
=>
hh24:mi:ss'),
sub_request
=>
argument1
=>
argument2
=>
argument3
=>
argument4
=>
argument5
=>
);
COMMIT;

'INV',
--Application Name
'SONATPEMAIL', --Short Name
NULL,
--Description
TO_CHAR(SYSDATE + 2 / 1440,'dd-mon-yy
FALSE,
p_request_id,
--Argument
'erp.support@sonagroup.com',
p_from_date,
p_to_date,
p_company

IF NVL (v_request_id, 0) = 0
THEN
fnd_file.put_line (fnd_file.LOG, 'Email Concurrent Failed.');
ELSE
fnd_file.put_line (fnd_file.LOG,
'Email concurrent running successfully, Req. ID:'
|| p_request_id
);
END IF;
END;

This procedure launches the following concurrent.

Page 5 of 16

Created by: Kannan Mahalingam,


Oracle Apps Technical Consultant

Chain-sys India Pvt. Ltd.

Setup For Concurrent Request output sending as Email Notification

Create Parameters (100 Characters)


Concurrent Request Id
From Address
From Date
To Date
Company
Page 6 of 16

Created by: Kannan Mahalingam,


Oracle Apps Technical Consultant

Chain-sys India Pvt. Ltd.

Setup For Concurrent Request output sending as Email Notification

In the concurrent request we are attaching an executable file. So that it will call the procedure. The following
is the procedure which will create the email notification with attachment
sona_utilities.sona_throughput_report_email
PROCEDURE SONA_THROUGHPUT_REPORT_EMAIL (
errbuf
OUT
VARCHAR2,
retcode
OUT
VARCHAR2,
p_request_id
IN
VARCHAR2,
p_from
IN
VARCHAR2 DEFAULT 'erp.support@sonagroup.com',
p_from_date
IN
DATE,
p_to_date
IN
DATE,
p_company
IN
VARCHAR2
)
IS
ls_email_body
v_from
v_recipients
v_cc
v_bcc
v_subject
v_mail_host
v_mail_conn
crlf
ll_count
filename1
v_directory_name
v_file_name
v_line
mesg
v_slash_pos
v_file_handle
invalid_path

LONG
:=
VARCHAR2 (80)
:=
LONG
:=
LONG
:=
LONG
:=
VARCHAR2 (200)
:=
VARCHAR2 (30)
:=
UTL_SMTP.connection;
VARCHAR2 (2)
:=
NUMBER;
VARCHAR2 (300);
VARCHAR2 (100);
VARCHAR2 (300);
VARCHAR2 (1000);
VARCHAR2 (32767);
NUMBER;
UTL_FILE.file_type;
EXCEPTION;

NULL;
NULL;
NULL;
NULL;
NULL;
NULL;
'10.1.4.35';
CHR (13) || CHR (10);

CURSOR c1
IS
SELECT

lookup_code, meaning, description, tag, start_date_active,


end_date_active, enabled_flag, lookup_type
FROM fnd_lookup_values_vl
Page 7 of 16

Created by: Kannan Mahalingam,


Oracle Apps Technical Consultant

Chain-sys India Pvt. Ltd.

Setup For Concurrent Request output sending as Email Notification


WHERE (
NVL ('', territory_code) = territory_code
OR territory_code IS NULL
)
AND (lookup_type = 'SONA THROUGHPUT EMAIL USERS')
AND (view_application_id = 700)
AND (security_group_id = 0)
AND (end_date_active > SYSDATE OR end_date_active IS NULL)
ORDER BY lookup_code;
BEGIN
v_from := p_from;
v_subject :=
p_company
|| ' - Sona Throughput Report - All Org for the period from '
|| TO_CHAR (p_from_date, 'DD-MON-YYYY')
|| ' to '
|| TO_CHAR (p_to_date, 'DD-MON-YYYY');
fnd_global.apps_initialize (6871, 50095, 401);
SELECT
INTO
FROM
WHERE

outfile_name
filename1
fnd_concurrent_requests
request_id = p_request_id;

v_mail_conn := UTL_SMTP.open_connection (v_mail_host, 26);


UTL_SMTP.helo (v_mail_conn, v_mail_host);
UTL_SMTP.mail (v_mail_conn, v_from);
FOR email_user IN c1
LOOP
IF UPPER (email_user.tag) = 'TO'
THEN
UTL_SMTP.rcpt (v_mail_conn, email_user.meaning);
IF (v_recipients IS NULL)
THEN
v_recipients := 'To: ' || email_user.meaning;
ELSE
v_recipients := v_recipients || ', ' || email_user.meaning;
END IF;
ELSIF UPPER (email_user.tag) = 'CC'
THEN
UTL_SMTP.rcpt (v_mail_conn, email_user.meaning);
IF (v_cc IS NULL)
THEN
v_cc := 'Cc: ' || email_user.meaning;
ELSE
v_cc := v_cc || ', ' || email_user.meaning;
END IF;
ELSIF UPPER (email_user.tag) = 'BCC'
THEN
UTL_SMTP.rcpt (v_mail_conn, email_user.meaning);
IF (v_bcc IS NULL)
THEN
v_bcc := 'Bcc: ' || email_user.meaning;
ELSE
v_bcc := v_bcc || ', ' || email_user.meaning;
END IF;
END IF;
Page 8 of 16

Created by: Kannan Mahalingam,


Oracle Apps Technical Consultant

Chain-sys India Pvt. Ltd.

Setup For Concurrent Request output sending as Email Notification


END LOOP;
UTL_SMTP.open_data (v_mail_conn);
mesg :=
'Date: '
|| TO_CHAR (SYSDATE, 'Dy, DD Mon YYYY hh24:mi:ss')
|| crlf
|| 'From: '
|| v_from
|| crlf
|| 'Subject: '
|| v_subject
|| crlf
|| 'To: '
|| v_recipients
|| crlf
|| 'Cc: '
|| v_cc
|| crlf
|| 'Mime-Version: 1.0'
|| crlf
|| 'Content-Type: multipart/mixed; boundary="DMW.Boundary.605592468"'
|| crlf
|| ''
|| crlf
|| '--DMW.Boundary.605592468'
|| crlf
|| 'Content-Type: text/plain; name="message.txt"; charset=US-ASCII'
|| crlf
|| 'Content-Disposition: inline; filename="message.txt"'
|| crlf
|| 'Content-Transfer-Encoding: 7bit'
|| crlf
|| crlf
|| 'Dear All,'
|| crlf
|| crlf
|| 'Please find attached "'
|| p_company
|| ' - Sona Throughput Report - All Org" for the period from '
|| TO_CHAR (p_from_date, 'DD-MON-YYYY')
|| ' to '
|| TO_CHAR (p_to_date, 'DD-MON-YYYY')
|| '.'
|| crlf
|| 'This is an automatically generated mail.'
|| crlf
|| 'For any clarifications, please send a mail to erp.support@sonagroup.com'
|| crlf
|| crlf
|| 'Regards,'
|| crlf
|| 'Erp.Support'
|| crlf
|| crlf
|| crlf;
UTL_SMTP.write_data (v_mail_conn, mesg);
IF filename1 IS NOT NULL
THEN
Page 9 of 16

Created by: Kannan Mahalingam,


Oracle Apps Technical Consultant

Chain-sys India Pvt. Ltd.

Setup For Concurrent Request output sending as Email Notification


BEGIN
v_slash_pos := INSTR (filename1, '/', -1);
IF v_slash_pos = 0
THEN
v_slash_pos := INSTR (filename1, '\', -1);
END IF;
v_directory_name := '/usr/tmp';
v_file_name := SUBSTR (filename1, v_slash_pos + 1);
v_file_handle := UTL_FILE.fopen (v_directory_name, v_file_name, 'r');
-- generate the MIME boundary line ...
mesg :=
crlf
|| '--DMW.Boundary.605592468'
|| crlf
|| 'Content-Type: application/octet-stream; name="'
|| v_file_name
|| '"'
|| crlf
|| 'Content-Disposition: attachment; filename="'
|| v_file_name
|| '"'
|| crlf
|| 'Content-Transfer-Encoding: 7bit'
|| crlf
|| crlf;
UTL_SMTP.write_data (v_mail_conn, mesg);
LOOP
UTL_FILE.get_line (v_file_handle, v_line);
mesg := v_line;
UTL_SMTP.write_data (v_mail_conn, mesg);
END LOOP;
EXCEPTION
WHEN UTL_FILE.invalid_path
THEN
DBMS_OUTPUT.put_line ('ERROR: INVALID_PATH
' || SQLERRM);
UTL_FILE.fclose_all;
WHEN UTL_FILE.invalid_mode
THEN
DBMS_OUTPUT.put_line ('ERROR: INVALID_MODE
' || SQLERRM);
UTL_FILE.fclose_all;
WHEN UTL_FILE.invalid_filehandle
THEN
DBMS_OUTPUT.put_line ('ERROR: INVALID_FILEHANDLE
' || SQLERRM);
UTL_FILE.fclose_all;
WHEN UTL_FILE.invalid_operation
THEN
DBMS_OUTPUT.put_line ('ERROR: INVALID_OPERATION
' || SQLERRM);
UTL_FILE.fclose_all;
WHEN UTL_FILE.read_error
THEN
DBMS_OUTPUT.put_line ('ERROR: READ_ERROR
' || SQLERRM);
UTL_FILE.fclose_all;
WHEN UTL_FILE.write_error
THEN
DBMS_OUTPUT.put_line ('ERROR: WRITE_ERROR
' || SQLERRM);
UTL_FILE.fclose_all;
WHEN UTL_FILE.internal_error
Page 10 of 16

Created by: Kannan Mahalingam,


Oracle Apps Technical Consultant

Chain-sys India Pvt. Ltd.

Setup For Concurrent Request output sending as Email Notification


THEN
DBMS_OUTPUT.put_line ('ERROR: INTERNAL_ERROR
' || SQLERRM);
UTL_FILE.fclose_all;
WHEN UTL_FILE.invalid_maxlinesize
THEN
DBMS_OUTPUT.put_line ('ERROR: INVALID_MAXLINESIZE
' || SQLERRM);
UTL_FILE.fclose_all;
WHEN NO_DATA_FOUND
THEN
DBMS_OUTPUT.put_line ('ERROR: NO_DATA_FOUND
' || SQLERRM);
UTL_FILE.fclose_all;
WHEN VALUE_ERROR
THEN
DBMS_OUTPUT.put_line ('ERROR: VALUE_ERROR ' || SQLERRM);
UTL_FILE.fclose_all;
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('ERROR: OTHERS
' || SQLERRM);
UTL_FILE.fclose_all;
END;
END IF;
mesg := crlf || '--DMW.Boundary.605592468--' || crlf;
UTL_SMTP.close_data (v_mail_conn);
UTL_SMTP.quit (v_mail_conn);
END;

Page 11 of 16

Created by: Kannan Mahalingam,


Oracle Apps Technical Consultant

Chain-sys India Pvt. Ltd.

Setup For Concurrent Request output sending as Email Notification

Step 3.(a) Run Concurrent Request Sona Throughput Report - All Org
The concurrent request Sona Throughput Report All Org is to be run from Inventory responsibility

Here user has to select


the printer which is
mandatory.

Page 12 of 16

Created by: Kannan Mahalingam,


Oracle Apps Technical Consultant

Chain-sys India Pvt. Ltd.

Setup For Concurrent Request output sending as Email Notification

Step 2. (b) Next, mandatory, click Options Button and select Printer COPY from the LOV and input the
number of copy to 1 as shown in the screen shot below. This will enable the output file to be copied from
REPORT_DIR to UTL_FILE_DIR.
This step is required if email notification to users is to be sent. Incase email notification is not required, then
selection of printer is not necessary.

User has to select the


printer as COPY and the
copies as 1.

Page 13 of 16

Created by: Kannan Mahalingam,


Oracle Apps Technical Consultant

Chain-sys India Pvt. Ltd.

Setup For Concurrent Request output sending as Email Notification

Step3
Then we have to submit the concurrent request. Once Sona Throughput Report - All Org Concurrent is
completed normal, then automatically. Sona Throughput Report - All Org Email Notification concurrent
will run after 2 minutes. This is shown in the following screen shot.

Once the above


concurrent is completed
This concurrent will be
spawned

Once the above concurrent is completed, then mail would be sent to designated users with Sona
Throughput Report - All Org Report Output as an attachment as shown in the following screen shot.

Finally, the concurrent Sona Throughput Report Schedule Concurrent needs to be scheduled daily in
order to get the output of the reports as per the following table:
Page 14 of 16

Created by: Kannan Mahalingam,


Oracle Apps Technical Consultant

Chain-sys India Pvt. Ltd.

Setup For Concurrent Request output sending as Email Notification

From Date
day of the month
th
08 day of the month
16th day of the month
24th day of the month
01st

To Date
day of the month
th
15 day of the month
23rd day of the month
Last day of the month
07th

Page 15 of 16

Created by: Kannan Mahalingam,


Oracle Apps Technical Consultant

Chain-sys India Pvt. Ltd.

Concurrent request fire date


09th day of every month
17th day of every month
25th day of every month
nd
02 day of the following month

Setup For Concurrent Request output sending as Email Notification


sona_utilities.throughput_schedule_concurrent
PROCEDURE THROUGHPUT_SCHEDULE_CONCURRENT (
errbuf
OUT
VARCHAR2,
retcode
OUT
VARCHAR2,
p_org_id
IN
VARCHAR2,
p_organization_id
IN
VARCHAR2,
p_company
IN
VARCHAR2,
p_set_of_books_id
IN
VARCHAR2
)
IS
v_request_id
NUMBER;
l_print_option
BOOLEAN;
l_from_date
VARCHAR2 (25);
l_to_date
VARCHAR2 (25);
l_day
VARCHAR2 (25);
BEGIN
SELECT TO_CHAR (SYSDATE, 'DAY'),
TO_CHAR ((TRUNC (SYSDATE) - 9), 'YYYY/MM/DD HH24:MI:SS'),
TO_CHAR ((TRUNC (SYSDATE) - 4), 'YYYY/MM/DD HH24:MI:SS')
INTO l_day,
l_from_date,
l_to_date
FROM DUAL;
IF l_day = 'WEDNESDAY'
THEN
fnd_global.apps_initialize (6871, 50095, 401);
l_print_option :=
fnd_request.set_print_options (printer
style
copies
save_output
print_together
);
IF l_print_option = TRUE
THEN
v_request_id :=
fnd_request.submit_request
(application
program
description
start_time
sub_request
argument1
argument2
argument3
argument4
argument5
argument6
);
COMMIT;

=>
=>
=>
=>
=>
=>
=>
=>
=>
=>
=>

=>
=>
=>
=>
=>

'COPY',
'BACS1',
1,
TRUE,
'N'

'INV',
--Application_Name
'SONATHRCSKG', --Short Name
NULL,
--Description
TO_CHAR(SYSDATE,'dd-mon-yy hh24:mi:ss'),
FALSE,
p_org_id,
--Argument
p_organization_id,
p_company,
p_set_of_books_id,
l_from_date,
l_to_date

IF NVL (v_request_id, 0) = 0 THEN


fnd_file.put_line(fnd_file.LOG, 'Schedule Concurrent Failed.');
ELSE
fnd_file.put_line(fnd_file.LOG,'Schedule Concurrent running successfully');
END IF;
ELSE
fnd_file.put_line (fnd_file.LOG, 'Concurrent Print Option Failed.');
END IF;
END IF;
END;
Page 16 of 16

Created by: Kannan Mahalingam,


Oracle Apps Technical Consultant

Chain-sys India Pvt. Ltd.

You might also like