DBA Data[Home] [Help]

PACKAGE BODY: APPS.GMS_WORKFLOW_UTILS

Source


1 PACKAGE BODY gms_workflow_utils AS
2 /* $Header: gmsfutlb.pls 115.4 2002/11/19 20:08:24 jmuthuku ship $ */
3 
4 -- -------------------------------------------------------------------------------------
5 -- GLOBAL CONSTANTS
6 -- -------------------------------------------------------------------------------------
7 
8 G_USER_ID  	  	CONSTANT NUMBER := FND_GLOBAL.user_id;
9 G_LOGIN_ID	  	CONSTANT NUMBER := FND_GLOBAL.login_id;
10 G_API_VERSION_NUMBER 	CONSTANT NUMBER := 1.0;
11 
12 
13 -- -------------------------------------------------------------------------------------
14 --  PROCEDURES
15 -- -------------------------------------------------------------------------------------
16 
17 --Name: 		Insert_WF_Processes
18 --Type:               	Procedure
19 --Description:      	This procedure inserts rows into the gms_wf_processes
20 --			table for the start_approval procedures.
21 --
22 --
23 --Called subprograms:	none.
24 --
25 --
26 --
27 --History:
28 --
29 -- IN Parameters
30 -- p_wf_type_code		- Entity invoking workflow, i.e., 'BUDGET', 'PROJECT'.
31 -- p_item_type			- Workflow Name, i.e., 'GMSBUDWF'
32 -- p_item_key			- Workflow process indentifer
33 -- p_entity_key1		- Primary key of calling entity, i.e., project_id, award_id,
34 --				   budget_version_id, etc.
35 -- p_entity_key2		- Supplemental primary key for calling entity. Typically,
36 --				  used to store baselined budget_version_id.
37 --
38 -- OUT NOCOPY Parameters
39 --   p_err_code			-  Standard error code: 0, Success; x < 0, Unexpected Error;
40 --   				   x > 0, Business Rule Violated.
41 --   p_err_stage			-  Standard error message
42 --   p_err_stack			-   Not used
43 
44 PROCEDURE Insert_WF_Processes
45 (p_wf_type_code		IN	VARCHAR2
46 , p_item_type		IN	VARCHAR2
47 , p_item_key		IN	VARCHAR2
48 , p_entity_key1		IN	VARCHAR2
49 , p_entity_key2		IN	VARCHAR2 := GMS_BUDGET_PUB.G_PA_MISS_CHAR
50 , p_description		IN	VARCHAR2 := GMS_BUDGET_PUB.G_PA_MISS_CHAR
51 , p_err_code            IN OUT NOCOPY	NUMBER
52 , p_err_stage		IN OUT NOCOPY	VARCHAR2
53 , p_err_stack		IN OUT NOCOPY	VARCHAR2
54 )
55 
56 IS
57 --
58 
59 	l_entity_key2	gms_wf_processes.entity_key2%TYPE;
60 	l_description	gms_wf_processes.description%TYPE;
61 
62 BEGIN
63 
64 --  Standard Begin of API Savepoint
65 
66     SAVEPOINT Insert_WF_Processes_pvt;
67 
68 --  Set API Return Status to Success
69 
70  	p_err_code	:= 0;
71 
72 -- Value-Id Layer --------------------------------------------------------------
73 
74 IF (p_entity_key2 = GMS_BUDGET_PUB.G_PA_MISS_CHAR)
75 THEN
76 	l_entity_key2 := 0;
77 ELSE
78 	l_entity_key2 := p_entity_key2;
79 END IF;
80 
81 IF (p_description = GMS_BUDGET_PUB.G_PA_MISS_CHAR)
82 THEN
83 	l_description := NULL;
84 ELSE
85 	l_description := p_description;
86 END IF;
87 
88 -- ----------------------------------------------------------------------------------
89 
90 
91     INSERT INTO gms_wf_processes
92 		   	(wf_type_code
93 			, item_type
94 		 	, item_key
95 			, entity_key1
96 			, entity_key2
97 			, description
98 		   	, last_update_date
99 			, last_updated_by
100 			, creation_date
101 			, created_by
102 			, last_update_login
103 			 )
104 			VALUES
105 			(p_wf_type_code
106 			, p_item_type
107 		 	, p_item_key
108 			, p_entity_key1
109 			, l_entity_key2
110 			, l_description
111 			, sysdate
112 			, fnd_global.user_id
113 			, sysdate
114 			, fnd_global.user_id
115 			, fnd_global.login_id
116 		 	);
117 
118 EXCEPTION
119 
120 	WHEN OTHERS
121 	 THEN
122 		p_err_code 	:= SQLCODE;
123 		ROLLBACK TO Insert_WF_Processes_pvt;
124 		WF_CORE.CONTEXT('GMS_WORKFLOW_UTILS','INSERT_WF_PROCESSES', p_item_type, p_item_key );
125 		RAISE;
126 
127 END Insert_WF_Processes;
128 
129 -- ==================================================
130 
131 PROCEDURE Set_Global_Attr (p_item_type  IN VARCHAR2,
132                            p_item_key   IN VARCHAR2,
133                            p_err_code  OUT NOCOPY VARCHAR2) IS
134 
135 l_resp_id                 NUMBER := 0;
136 l_workflow_started_by_id  NUMBER := 0;
137 l_msg_count               NUMBER := 0;
138 l_msg_data                VARCHAR2(500) := 0;
139 l_data                    VARCHAR2(500) := 0;
140 l_return_status           VARCHAR2(1) ;
141 l_msg_index_out           NUMBER;
142 
143 BEGIN
144 
145 p_err_code := 0;
146 l_resp_id := wf_engine.GetItemAttrNumber
147             (itemtype  	=> p_item_type,
148 	     itemkey   	=> p_item_key,
149     	     aname  	=> 'RESPONSIBILITY_ID' );
150 
151 l_workflow_started_by_id := wf_engine.GetItemAttrNumber
152                (itemtype => p_item_type,
153                 itemkey  => p_item_key,
154                 aname    => 'WORKFLOW_STARTED_BY_ID' );
155 
156 -- Based on the Responsibility, Intialize the Application
157 FND_GLOBAL.Apps_Initialize
158 	(user_id         	=> l_workflow_started_by_id
159 	  , resp_id         	=> l_resp_id
160 	  , resp_appl_id	=> gms_workflow_utils.get_application_id(l_resp_id)
161 	);
162 
163 
164 EXCEPTION
165 
166 WHEN OTHERS
167    THEN
168 	 p_err_code := SQLCODE;
169 	WF_CORE.CONTEXT('GMS_WORKFLOW_UTILS','SET_GLOBAL_ATTR', p_item_type, p_item_key );
170 	RAISE;
171 
172 END Set_Global_Attr;
173 
174 -- ==================================================
175 
176 --Name: 		Set_Notification_Messages
177 --Type:               	Procedure
178 --Description:      This procedure populates ten error message
179 --		attributes in the calling WF.
180 --
181 --
182 --Called subprograms:	none.
183 --
184 --
185 --
186 --History:
187 --
188 -- IN Parameters
189 --   p_item_type		- WF item type
190 --   p_item_key		- WF item key.
191 --
192 --
193 
194 PROCEDURE Set_Notification_Messages
195 (p_item_type IN VARCHAR2
196  , p_item_key  IN VARCHAR2
197 )
198 --
199 IS
200 --
201 l_attr_name   VARCHAR2(30);
202 l_msg_count   NUMBER := 0;
203 l_msg_text    VARCHAR2(2000)		:= NULL;
204 l_encoded_mesg VARCHAR2(2000);
205 
206 BEGIN
207 
208 -- Get l_msg_count for Subsequent Processing
209      l_msg_count := FND_MSG_PUB.COUNT_MSG;
210 
211 -- Intialize First Ten WF Error Message Attributes
212 
213 FOR i IN 1..10 LOOP
214 	l_attr_name := 'RULE_NOTE_'||i;
215 	wf_engine.SetItemAttrText
216 	 (itemtype	=> p_item_type
217 	   , itemkey  	=> p_item_key
218 	   , aname 	=> l_attr_name
219 	   , avalue	=> l_msg_text
220 	   );
221 END LOOP;
222 
223 -- Populate WF Error Message Attributes with Messages, if any.
224 
225 IF l_msg_count > 0 THEN
226         FOR i IN 1..l_msg_count LOOP
227            IF i > 10 THEN
228               EXIT;
229            END IF;
230            l_encoded_mesg := fnd_msg_pub.get
231                             (p_msg_index => i,
232                              p_encoded   => FND_API.G_TRUE);
233            fnd_message.set_encoded (encoded_message => l_encoded_mesg);
234            l_msg_text := Fnd_Message.Get;
235            l_attr_name := 'RULE_NOTE_'||i;
236           wf_engine.SetItemAttrText (itemtype	=> p_item_type,
237 				      itemkey  	=> p_item_key,
238 				      aname 	=> l_attr_name,
239 				      avalue	=> l_msg_text );
240          END LOOP;
241      END IF;
242 
243 EXCEPTION
244 	 WHEN OTHERS
245 	  THEN
246 	WF_CORE.CONTEXT('GMS_WORKFLOW_UTILS','SET_NOTIFICATION_MESSAGES', p_item_type, p_item_key );
247 		RAISE;
248 
249 END Set_Notification_Messages;
250 -- ==================================================
251 
252 --
253 --  FUNCTION
254 --              get_application_id
255 --  PURPOSE
256 --              This function retrieves the application id of a responsibility.
257 --              If no application id is found, null is returned.
258 --              If Oracle error occurs, Oracle error number is returned.
259 --  HISTORY
260 --
261 function get_application_id (x_responsibility_id  IN number) return number
262 is
263    cursor c1 is
264    		 select application_id
265    		 from fnd_responsibility
266    		 where responsibility_id = x_responsibility_id;
267 
268     c1_rec c1%rowtype;
269 
270 begin
271    open c1;
272    fetch c1 into c1_rec;
273    if c1%notfound then
274            close c1;
275            return( null);
276    else
277            close c1;
278            return( c1_rec.application_id);
279    end if;
280 
281 exception
282    when others then
283    return(SQLCODE);
284 
285 end get_application_id;
286 
287 -- ==================================================
288 
289 END gms_workflow_utils;