0% found this document useful (0 votes)
263 views

Attaching Concurrent Program Output As Workflow Email Notification Attachment

This document discusses attaching a concurrent program's output as a file attachment to a workflow email notification. It provides steps to insert the output file into the FND_LOBS table as a BLOB, including creating a document record and BLOB. It then shows a sample PL/SQL procedure to load the file into the BLOB. Finally, it mentions using a package to set the BLOB's file ID to attach it to a workflow notification.

Uploaded by

ucis scanner
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
263 views

Attaching Concurrent Program Output As Workflow Email Notification Attachment

This document discusses attaching a concurrent program's output as a file attachment to a workflow email notification. It provides steps to insert the output file into the FND_LOBS table as a BLOB, including creating a document record and BLOB. It then shows a sample PL/SQL procedure to load the file into the BLOB. Finally, it mentions using a package to set the BLOB's file ID to attach it to a workflow notification.

Uploaded by

ucis scanner
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Attaching Concurrent Program Output as Workflow Email

Notification Attachment
by Shailender ThallamMay 17, 2016

This article explains how to attach a concurrent program output as a Workflow email notification.

Prerequisites

1. DBA Directory should be created with Concurrent Program output path


2. A new document category should be created under “Application Developer –> Attachments –>
Document Categories”

Steps to Implement

1. Call API “FND_DOCUMENTS_PKG.INSERT_ROW” to detail the information of document to be


created
2. Insert a BLOB type of record into “FND_LOBS” table
3. Use “DBMS_LOB” API to read the output from Concurrent Program output path and point it to the
BLOB type of record created in step 2

Below is the sample PL/SQL procedure which takes Concurrent Request ID as input parameter and
returns the media_id of the BLOB document created

1 PROCEDURE load_inv_pdf_p (

2 p_conc_req_id IN apps.fnd_concurrent_requests.request_id%TYPE,
3 p_project_number IN apps.pa_projects_all.segment1%TYPE,

4 p_draft_invoice_num IN apps.pa_draft_invoices_all.draft_invoice_num%TYPE,

5 p_file_id OUT apps.fnd_lobs.file_id%TYPE

6 )

7 -- +===================================================================+

8 -- | Name : load_inv_pdf_p |

9 -- | Description : Loads a file to FND_LOBS as a BLOB and returns |

10 -- | BLOB file_id |

11 -- | Parameters : |

12 -- | |

13 -- | p_conc_req_id --> Concurrent Request ID |

14 -- | p_project_number --> Project Number |

15 -- | p_draft_invoice_num--> Draft Invoice Number |

16 -- | p_file_id --> File ID from fnd_lobs |

17 -- | |

18 -- +===================================================================+

19 IS

20 lr_row_id ROWID;

21 ln_document_id NUMBER;

22 ln_media_id NUMBER;

23 lb blob data BLOB;


23 lb_blob_data BLOB;

24 ln_category_id NUMBER;

25 lb_blob BLOB;

26 lb_bfile BFILE;

27 lc_actual_file_name VARCHAR2 (200);

28 lc_display_file_name VARCHAR2 (200);

29 lc_description VARCHAR2 (400);

30 lb_go BOOLEAN := TRUE;

31 ln_count NUMBER;

32 lc_cp_short_name apps.fnd_concurrent_programs.concurrent_program_name%TYPE;

33 --

34 BEGIN

35 --

36 --Finding CP Short name based on request ID

37 --

38 SELECT program_short_name

39 INTO lc_cp_short_name

40 FROM apps.fnd_conc_req_summary_v

41 WHERE 1 = 1 AND request_id = p_conc_req_id;

42  

43 lc_actual_file_name := lc_cp_short_name || '_' || p_conc_req_id || '_1.PDF';


44 lc_display_file_name :=

45 'Project#'

46 || p_project_number

47 || '_DraftInvoice#'

48 || p_draft_invoice_num

49 || '.pdf';

50 lc_description :=

51 'Draft Invoice#'

52 || p_draft_invoice_num

53 || ' for Project#'

54 || p_project_number;

55 --

56 DBMS_OUTPUT.put_line ( 'lc_actual_file_name: ' || lc_actual_file_name);

57 DBMS_OUTPUT.put_line ( 'lc_display_file_name: ' || lc_display_file_name);

58  

59 --

60 BEGIN

61 SELECT category_id

62 INTO ln_category_id

63 FROM apps.fnd_document_categories_tl

64 WHERE user_name = 'XX Project Draft Invoice PDF'

65 AND LANGUAGE = USERENV ('lang');

66 EXCEPTION

67 WHEN OTHERS

68 THEN

69 --

70 lb_go := FALSE;

71 p_file_id := -1;

72 DBMS_OUTPUT.put_line (

73 'Error While Deriving Document Category ' || SQLERRM

74 );

75 --

76 END;

77  

78 --

79 --Create a FND DOCUMENT

80 --

81 BEGIN

82 DBMS_OUTPUT.put_line ( 'FND_DOCUMENTS_PKG.INSERT_ROW Call');

83 apps.fnd documents pkg.insert row

pp _ _p g _
84 (x_rowid => lr_row_id,

85 x_document_id => ln_document_id,

86 x_creation_date => SYSDATE,


87 x_created_by => fnd_global.user_id,

88 x_last_update_date => SYSDATE,


89 x_last_updated_by => fnd_global.user_id,

90 x_last_update_login => fnd_global.user_id,

91 x_datatype_id => 6,

92 --Indicates BLOB type of data

93 x_category_id => ln_category_id,

94 x_security_type => 1,

95 x_publish_flag => 'Y',

96 x_usage_type => 'S',

97 x_start_date_active => SYSDATE,


98 x_request_id => fnd_global.conc_request_id,

99 x_program_application_id => fnd_global.prog_appl_id,

100 x_program_update_date => SYSDATE,


101 x_language => fnd_global.current_language,

102 x_description => lc_description,

103 x_file_name => lc_display_file_name,

104 x_media_id => ln_media_id

105 );

106 DBMS_OUTPUT.put_line ( 'file_id: ' || ln_media_id);

107 --Setting out parameter p_file_id

108 p_file_id := ln_media_id;

109 --

110 EXCEPTION

111 WHEN OTHERS

112 THEN

113 lb_go := FALSE;

114 p_file_id := -1;

115 DBMS_OUTPUT.put_line (

116 'Error during FND_DOCUMENTS_PKG.INSERT_ROW Call '

117 || SQLERRM

118 );

119 END;

120  

121 --

122 --Creating Empty BLOB with reference to the above ceated document

123 --

124 BEGIN

125 lb_blob_data := EMPTY_BLOB ();

126 DBMS_OUTPUT.put_line ( 'Inserting to FND LOBS');

127  

128 INSERT INTO apps.fnd_lobs

129 (file_id, file_name,

130 file_content_type, upload_date, expiration_date,

131 program_name, program_tag, file_data,


132 LANGUAGE, oracle_charset, file_format
133 )

134 VALUES (ln_media_id, lc_display_file_name,

135 'application/octet-stream', SYSDATE, NULL,

136 'FNDATTCH', NULL, lb_blob_data,

137 fnd_global.current_language, NULL, 'binary'

138 )

139 RETURNING file_data

140 INTO lb_blob;

141 EXCEPTION

142 WHEN OTHERS

143 THEN

144 lb go := FALSE;

_g ;
145 p_file_id := -1;

146 DBMS_OUTPUT.put_line (

147 'Error during Insert into FND_LOBS ' || SQLERRM

148 );

149 END;

150  

151 --

152 BEGIN

153 --

154 --Loading physical file to LOBS table as a BLOB

155 --

156 DBMS_OUTPUT.put_line ( 'Loading File to Lobs');

157 --

158 --Getting a pointer for Physical file

159 --

160 lb_bfile := BFILENAME ('XX_CP_OUTPUT_DIR', lc_actual_file_name);

161 --

162 --Open the file with the pointer returned above

163 --

164 DBMS_LOB.fileopen (lb_bfile);

165 --

166 --load the file from disk to the table directly using lb_blob created in previous
167 --

168 DBMS_LOB.loadfromfile (lb_blob, lb_bfile,

169 DBMS_LOB.getlength (lb_bfile));

170 --

171 --close the file after storing it in the table

172 --

173 DBMS_LOB.fileclose (lb_bfile);

174 --

175 EXCEPTION

176 WHEN OTHERS

177 THEN

178 DBMS_OUTPUT.put_line (

179 'There is no such File or Directory..File Name : '

180 || lc_actual_file_name

181 || ' Error : '

182 || SQLERRM

183 );

184 --

185 ROLLBACK;

186 END;

187  

188 --

189 COMMIT;

190 --

191 END load_inv_pdf_p;

Attaching the BLOB document to workflow Notification

Below is the package to set BLOB file file_id to workflow notification

1 SET serveroutput ON;

2  

3 CREATE OR REPLACE PACKAGE "BOLINF"."XX_TEST1_PKG" AUTHID CURRENT_USER

4 IS

5 PROCEDURE set_att_invoice_media_id (

6 p_item_key apps.wf_notifications.item_key%TYPE

7 );

8  

9 --

10 PROCEDURE notif_attach_procedure (

11 document_id IN VARCHAR2,

12 display_type IN VARCHAR2,

13 document IN OUT BLOB,

14 document_type IN OUT VARCHAR2

15 );

16 END xx_test1_pkg;

17 /

18  

19 --

20 --

21  

22 CREATE OR REPLACE PACKAGE BODY "BOLINF"."XX_TEST1_PKG"

23 AS

24 -- +===================================================================+

25 -- | Name : notif_attach_procedure |

26 -- | Description : Attach draft invoice to workflow notification |

27 -- | Parameters : |

28 -- | |

29 -- | document_id --> Unique String to identify document |

30 -- | display_type --> type used for notification presentation |

31 -- | document --> The outbound LOB locator pointing to where |

32 -- | the document text is stored |

33 -- | document_type --> The outbound text buffer where the document |

34 -- | content type is returned |

35 -- | |

36 -- | RETURNS : No Return |

37 -- +===================================================================+

38 PROCEDURE notif_attach_procedure (

39 document_id IN VARCHAR2,

40 display_type IN VARCHAR2,

41 document IN OUT BLOB,

42 document_type IN OUT VARCHAR2

43 )

44 IS

45 lob_id NUMBER;

46 bdoc BLOB;

47 content_type VARCHAR2 (100);

48 filename VARCHAR2 (300);

49 BEGIN

50 --

51 DBMS_OUTPUT.put_line ('XX In notif_attach_procedure');

52 --

53 --–set_debug_context('notif_attach_procedure');

54 lob_id := TO_NUMBER (document_id);

55 --

56 --Creating a temporary blob type of document

57 --

58 DBMS_LOB.createtemporary (bdoc, FALSE, DBMS_LOB.CALL);

59 --

60 DBMS_OUTPUT.put_line ('XX lob_id: ' || lob_id);

61  

62 --

63 -- Obtain the BLOB version of the document

64 --

65 SELECT file_name, file_content_type, file_data

66 INTO filename, content_type, bdoc

67 FROM apps fnd lobs


67 FROM apps.fnd_lobs

68 WHERE file_id = lob_id;

69  

70 --

71 document_type := content_type || ';name=' || filename;

72 --

73 --Copying the blob document 'document' to the temporary blob document 'bdoc'

74 --

75 DBMS_LOB.COPY (document, bdoc, DBMS_LOB.getlength (bdoc));

76 --

77 DBMS_OUTPUT.put_line ('XX End of notif_attach_procedure');

78 --

79 EXCEPTION

80 WHEN OTHERS

81 THEN

82 --

83 DBMS_OUTPUT.put_line ( 'XX Exception in notif_attach_procedure :'

84 || SQLERRM

85 );

86 --

87 END notif_attach_procedure;

88  

89 --

90 --

91 PROCEDURE set_att_invoice_media_id (

92 p_item_key apps.wf_notifications.item_key%TYPE

93 )

94 IS

95 -- +===================================================================+

96 -- | Name : set_att_invoice_media_id |

97 -- | Description : To trigger workflow |

98 -- | Parameters : |

99 -- | |

100 -- | p_item_key --> Unique String to identify workflow instance |

101 -- |
102 -- +===================================================================+

103 l_process VARCHAR2 (20) := 'XX_TEST_PROCESS';

104 l_itemtype VARCHAR2 (8) := 'XXTEST1';

105 l_itemkey apps.wf_notifications.item_key%TYPE := p_item_key;

106 l_user_key apps.wf_notifications.user_key%TYPE := 'XX-TEST-11-PDF';

107 l_doc_id VARCHAR2 (20) := '417633'; --media_id genera


108 --

109 BEGIN

110 --

111 DBMS_OUTPUT.put_line ('XX Begin set_att_invoice_media_id');

112 --

113 --

114 --Creating Workflow Process

115 --

116 apps.wf_engine.createprocess (itemtype => l_itemtype,

117 itemkey => l_itemkey,

118 process => l_process,

119 user_key => l_user_key,

120 owner_role => 'SYSADMIN'

121 );

122 --

123 DBMS_OUTPUT.put_line ('XX Setting Attribute');

124 --

125 apps.wf_engine.setitemattrtext

126 (itemtype => l_itemtype,

127 itemkey => l_itemkey,

128 aname > 'XX BLOB DOC ID'


128 aname => XX_BLOB_DOC_ID ,

129 avalue => TO_CHAR

130 (l_doc_id)

131 --doc_id must be in character format

132 );

133 --

134 --Start Process

135 --

136 apps.wf_engine.startprocess (itemtype => l_itemtype,

137 itemkey => l_itemkey

138 );

139 --

140 DBMS_OUTPUT.put_line ('XX End set_att_invoice_media_id');

141 --

142 EXCEPTION

143 WHEN OTHERS

144 THEN

145 --

146 DBMS_OUTPUT.put_line ( 'XX Exception in set_att_invoice_media_id :'

147 || SQLERRM

148 );

149 --

150 END set_att_invoice_media_id;

151 END xx_test1_pkg;

152 /

Create a workflow with two types of attributes, one is of type ‘Text’ (XX_BLOB_DOC_ID) and other is of
type ‘Document’ (XX_DRAFT_INV_FILE_ATTACH)

Workflow Structure:

Workflow Process
Document type attribute

Value: plsqlblob:XX_TEST1_PKG.notif_attach_procedure/&XX_BLOB_DOC_ID

Assigning Document type attribute to a message


file_id of blob document should be set to attribute XX_BLOB_DOC_ID and it should be passed as
parameter to Document type attribute XX_DRAFT_INV_FILE_ATTACH which in turn calls procedure
“XX_TEST1_PKG.notif_attach_procedure” which copies the original blob document in fnd_lobs to
workflow notification.

Below is the block of code to trigger the workflow

SET SERVEROUTPUT ON;

DECLARE

l_item_key NUMBER := 101;

BEGIN

xx_test1_pkg.set_att_invoice_media_id (l_item_key);

END;

You might also like