DBA Data[Home] [Help]

PACKAGE BODY: APPS.CS_WORKFLOW_PKG

Source


1 PACKAGE BODY CS_Workflow_PKG as
2 /* $Header: cswkflwb.pls 120.1 2008/01/14 12:15:43 vpremach ship $ */
3 
4 
5 
6 -- -------------------------------------------------------------------
7 -- Pre_Validate_FS_Action
8 -- -------------------------------------------------------------------
9 
10 PROCEDURE	Pre_Validate_FS_Action
11 (
12 	fs_request_id		NUMBER,
13 	fs_action_num		NUMBER,
14 	x_return_status	OUT NOCOPY VARCHAR2
15 )
16 IS
17 	CURSOR l_action_csr IS
18 	SELECT
19 		it.business_process_id,
20 		sr.customer_id,
21 		sr.record_is_valid_flag record_valid,
22 --		act.action_effective_date effective_date,
23 --		act.expected_resolution_date resolution_date,
24 --		act.action_assignee_id assignee_id,
25 --		act.dispatcher_orig_syst_id employee_id,
26 --		act.dispatcher_orig_syst dis_orig_syst,
27 		it.workflow wf_name,
28 		(
29 		hl.address1 || hl.address2 || hl.address3
30 		) install_address
31   	FROM
32 		CS_INCIDENTS_V sr,
33 --		CS_INCIDENT_ACTIONS_V act,
34   		CS_INCIDENT_TYPES_VL it,
35                 HZ_PARTY_SITES hps,
36                 HZ_LOCATIONS hl
37   	WHERE   it.incident_type_id = sr.incident_type_id
38   		AND   sr.incident_id = fs_request_id
39 --  		AND   act.incident_id = fs_request_id
40 --  		AND   act.action_num = fs_action_num
41                 AND   sr.customer_id = hps.party_id
42                 AND   hps.party_site_id = hl.location_id;
43 
44        l_action_rec	l_Action_Csr%ROWTYPE;
45 BEGIN
46 	x_return_status := 'S';
47 	OPEN l_Action_Csr;
48 	FETCH l_Action_Csr INTO
49 					l_action_rec.business_process_id,
50 					l_action_rec.customer_id,
51 					l_action_rec.record_valid,
52 --					l_action_rec.effective_date,
53 --					l_action_rec.resolution_date,
54 --					l_action_rec.assignee_id,
55 --					l_action_rec.employee_id,
56 --  					l_action_rec.dis_orig_syst,
57 					l_action_rec.wf_name,
58 					l_action_rec.install_address;
59 --	IF l_action_rec.wf_name = 'FIELD_SERVICE_DISPATCH' AND
60 --			l_action_rec.dis_orig_syst <> 'PER' THEN
61 --		x_return_status := 'E';
62 
63 	IF l_action_rec.wf_name = 'FIELD_SERVICE_DISPATCH' THEN
64 		x_return_status := 'E';
65 	ELSIF l_action_rec.wf_name = 'FIELD_SERVICE_DISPATCH' AND
66 		(
67 			l_action_rec.business_process_id is null or
68 			l_action_rec.customer_id is null or
69 			l_action_rec.record_valid is null or
70 --			l_action_rec.effective_date is null or
71 --			l_action_rec.resolution_date is null or
72 --			l_action_rec.assignee_id is null or
73 --			l_action_rec.employee_id is null or
74 			l_action_rec.install_address is null ) THEN
75 		x_return_status := 'A';
76 	END IF;
77 	CLOSE l_action_Csr;
78 EXCEPTION
79 	WHEN OTHERS THEN
80 		x_return_status := 'E';
81 		if l_Action_Csr%ISOPEN THEN
82 			CLOSE l_Action_Csr;
83 		end if;
84 END Pre_Validate_FS_Action;
85 
86 -- -------------------------------------------------------------------
87 -- Is_Servereq_Item_Active
88 -- -------------------------------------------------------------------
89 
90   FUNCTION Is_Servereq_Item_Active (
91 		p_request_number	  IN VARCHAR2,
92 		p_wf_process_id 	  IN NUMBER ) RETURN VARCHAR2 IS
93 
94     l_itemkey	VARCHAR2(240);
95     l_dummy	VARCHAR2(1);
96     l_end_date	DATE;
97     l_result	VARCHAR2(1);
98     l_item_type VARCHAR2(10);
99 
100     CURSOR l_itemtype_csr IS --Bug 6449697
101       Select item_type
102       from cs_incidents_all_b inc, cs_incident_types types, wf_activities wf
103       where inc.incident_number= p_request_number
104       and types.incident_type_id=inc.incident_type_id
105       and wf.name=types.workflow;
106 
107     CURSOR l_servereq_csr IS
108       SELECT end_date
109       FROM   wf_items
110 --      WHERE  item_type = 'SERVEREQ'  --Commented for Bug 6449697
111       WHERE  item_type = l_item_type
112       AND    item_key  = l_itemkey;
113 
114   BEGIN
115     --
116     -- First construct the item key
117     -- If we ever change the format of the itemkey, the following code
118     -- must be updated
119     --
120     l_itemkey := p_request_number||'-'||to_char(p_wf_process_id);
121     --Bug 6449697
122     OPEN  l_itemtype_csr;
123     FETCH l_itemtype_csr into l_item_type;
124     CLOSE l_itemtype_csr;
125     --
126     -- An item is considered active if its end_date is NULL
127     --
128     OPEN l_servereq_csr;
129     FETCH l_servereq_csr INTO l_end_date;
130     IF ((l_servereq_csr%NOTFOUND) OR (l_end_date IS NOT NULL)) THEN
131       l_result := 'N';
132     ELSE
133       l_result := 'Y';
134     END IF;
135     CLOSE l_servereq_csr;
136 
137     return l_result;
138 
139   END Is_Servereq_Item_Active;
140 
141 
142 -- -------------------------------------------------------------------
143 -- Get_Workflow_Display_Name
144 -- -------------------------------------------------------------------
145 
146   FUNCTION Get_Workflow_Disp_Name (
147 		p_item_type		IN VARCHAR2,
148 		p_process_name		IN VARCHAR2,
149 		p_raise_error		IN BOOLEAN    )
150   RETURN VARCHAR2 IS
151 
152     l_display_name  VARCHAR2(80);
153 
154   BEGIN
155     IF (p_process_name IS NULL) OR
156        (p_item_type IS NULL)    THEN
157       RETURN NULL;
158     END IF;
159 
160     SELECT display_name INTO l_display_name
161       FROM WF_RUNNABLE_PROCESSES_V
162      WHERE item_type = p_item_type
163        AND process_name = p_process_name;
164 
165     return l_display_name;
166 
167 
168   EXCEPTION
169     WHEN NO_DATA_FOUND THEN
170       IF (p_raise_error = TRUE) THEN
171 	raise;
172       ELSE
173 	return NULL;
174       END IF;
175   END Get_Workflow_Disp_Name;
176 
177 
178 -- -------------------------------------------------------------------
179 -- Start_Servereq_Workflow
180 --   Launch a service request workflow process.
181 -- -------------------------------------------------------------------
182 
183   PROCEDURE Start_Servereq_Workflow (
184 		p_request_number	  IN VARCHAR2,
185 		p_wf_process_name	  IN VARCHAR2,
186 		p_initiator_user_id	  IN NUMBER,
187 		p_initiator_resp_id	  IN NUMBER   := NULL,
188 		p_initiator_resp_appl_id  IN NUMBER   := NULL,
189 		p_workflow_process_id	 OUT NOCOPY NUMBER ) IS
190 
191     l_itemkey		VARCHAR2(240);
192     l_return_status	VARCHAR2(1);
193     l_msg_count		NUMBER;
194     l_msg_data		VARCHAR2(2000);
195     l_pos		NUMBER;
196     l_API_ERROR		EXCEPTION;
197 
198   BEGIN
199     -- establish savepoint
200     SAVEPOINT start_workflow;
201 
202     -- Call the API.  Notice that we are doing a quiet commit by setting
203     -- the commit flag
204     CS_Workflow_PUB.Launch_Servereq_Workflow (
205 		p_api_version		=> 1.0,
206 		p_init_msg_list		=> FND_API.G_TRUE,
207 		p_commit		=> FND_API.G_TRUE,
208 		p_return_status		=> l_return_status,
209 		p_msg_count		=> l_msg_count,
210 		p_msg_data		=> l_msg_data,
211 		p_request_number	=> p_request_number,
212 		p_initiator_user_id	=> p_initiator_user_id,
213 		p_initiator_resp_id	=> p_initiator_resp_id,
214 		p_initiator_resp_appl_id=> p_initiator_resp_appl_id,
215 		p_itemkey	  	=> l_itemkey,
216                 p_nowait                => FND_API.G_TRUE );
217 
218     -- Check for possible errors returned by the API
219     IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
220       raise l_API_ERROR;
221     END IF;
222 
223     l_pos := INSTR(l_itemkey, '-');
224     p_workflow_process_id := SUBSTR(l_itemkey, l_pos+1);
225 
226   EXCEPTION
227     WHEN l_API_ERROR THEN
228       ROLLBACK TO start_workflow;
229       FND_MESSAGE.Set_Name('CS', 'CS_SR_WORKFLOW_API_ERROR');
230       FND_MESSAGE.Set_Token('ERROR_MSG', l_msg_data);
231       -- rmanabat 11/20/01 Fix for bug# 2102121.
232       --APP_EXCEPTION.Raise_Exception;
233 
234   END Start_Servereq_Workflow;
235 
236 
237 -- -------------------------------------------------------------------
238 -- Abort_Servereq_Workflow
239 --   Abort a service request workflow process
240 -- -------------------------------------------------------------------
241 
242   PROCEDURE Abort_Servereq_Workflow (
243 		p_request_number	  IN VARCHAR2,
244 		p_wf_process_id		  IN NUMBER,
245 		p_user_id	  	  IN NUMBER ) IS
246 
247     l_return_status	VARCHAR2(1);
248     l_msg_count		NUMBER;
249     l_msg_data		VARCHAR2(2000);
250     l_API_ERROR		EXCEPTION;
251 
252   BEGIN
253     SAVEPOINT abort_workflow;
254 
255     -- Call the API.  Notice that we are doing a quiet commit by setting
256     -- the commit flag
257     CS_Workflow_PUB.Cancel_Servereq_Workflow (
258 		p_api_version		=> 1.0,
259 		p_init_msg_list		=> FND_API.G_TRUE,
260 		p_commit		=> FND_API.G_TRUE,
261 		p_return_status		=> l_return_status,
262 		p_msg_count		=> l_msg_count,
263 		p_msg_data		=> l_msg_data,
264 		p_request_number	=> p_request_number,
265 		p_wf_process_id	  	=> p_wf_process_id,
266 		p_user_id               => p_user_id );
267 
268     -- Check for possible errors returned by the API
269     IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
270       raise l_API_ERROR;
271     END IF;
272 
273   EXCEPTION
274     WHEN l_API_ERROR THEN
275       ROLLBACK TO abort_workflow;
276       FND_MESSAGE.Set_Name('CS', 'CS_SR_WORKFLOW_API_ERROR');
277       FND_MESSAGE.Set_Token('ERROR_MSG', l_msg_data);
278       --APP_EXCEPTION.Raise_Exception;
279 
280   END Abort_Servereq_Workflow;
281 
282 
283 
284 -- -------------------------------------------------------------------
285 -- Abort_Servereq_Workflow
286 --   Abort a service request workflow process
287 --   Overloaded procedure to return messages to the calling library CSSRISR.pld
288 --   rmanabat 05/08/02
289 -- -------------------------------------------------------------------
290 
291   PROCEDURE Abort_Servereq_Workflow (
292 		p_request_number	  IN VARCHAR2,
293 		p_wf_process_id		  IN NUMBER,
294 		p_user_id	  	  IN NUMBER,
295                 x_msg_count               OUT NOCOPY NUMBER,
296                 x_msg_data                OUT NOCOPY VARCHAR2 ) IS
297 
298     l_return_status	VARCHAR2(1);
299     l_msg_count		NUMBER;
300     l_msg_data		VARCHAR2(2000);
301     l_API_ERROR		EXCEPTION;
302 
303   BEGIN
304     SAVEPOINT abort_workflow;
305 
306     -- Call the API.  Notice that we are doing a quiet commit by setting
307     -- the commit flag
308     CS_Workflow_PUB.Cancel_Servereq_Workflow (
309 		p_api_version		=> 1.0,
310 		p_init_msg_list		=> FND_API.G_TRUE,
311 		p_commit		=> FND_API.G_TRUE,
312 		p_return_status		=> l_return_status,
313 		p_msg_count		=> x_msg_count,
314 		p_msg_data		=> x_msg_data,
315 		p_request_number	=> p_request_number,
316 		p_wf_process_id	  	=> p_wf_process_id,
317 		p_user_id               => p_user_id );
318 
319     -- Check for possible errors returned by the API
320     IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
321       raise l_API_ERROR;
322     END IF;
323 
324   EXCEPTION
325     WHEN l_API_ERROR THEN
326       ROLLBACK TO abort_workflow;
327       FND_MESSAGE.Set_Name('CS', 'CS_SR_WORKFLOW_API_ERROR');
328       --FND_MESSAGE.Set_Token('ERROR_MSG', l_msg_data);
329       FND_MESSAGE.Set_Token('ERROR_MSG', x_msg_data);
330       --APP_EXCEPTION.Raise_Exception;
331 
332   END Abort_Servereq_Workflow;
333 
334 ----------------------------------------------------------------------
335 -- Is_Action_Item_Active
336 ----------------------------------------------------------------------
337 
338 FUNCTION Is_Action_Item_Active
339 ( p_request_id		IN NUMBER,
340   p_action_number	IN NUMBER,
341   p_wf_process_id	IN NUMBER
342 )
343 RETURN VARCHAR2
344 IS
345   l_itemkey	VARCHAR2(240);
346   l_dummy	VARCHAR2(1);
347   l_end_date	DATE;
348   l_result	VARCHAR2(1);
349 
350   CURSOR l_sraction_csr IS
351     SELECT end_date
352     FROM   wf_items
353     WHERE  item_type = 'SRACTION'
354     AND    item_key  = l_itemkey;
355 
356 BEGIN
357   --
358   -- First construct the item key
359   -- If we ever change the format of the itemkey, the following code
360   -- must be updated
361   --
362   l_itemkey := p_request_id || '-' || p_action_number || '-' || p_wf_process_id;
363 
364   --
365   -- An item is considered active if its end_date is NULL
366   --
367   OPEN l_sraction_csr;
368   FETCH l_sraction_csr INTO l_end_date;
369   IF ((l_sraction_csr%NOTFOUND) OR (l_end_date IS NOT NULL)) THEN
370     l_result := 'N';
371   ELSE
372     l_result := 'Y';
373   END IF;
374   CLOSE l_sraction_csr;
375 
376   RETURN l_result;
377 
378 END Is_Action_Item_Active;
379 
380 
381 ----------------------------------------------------------------------
382 -- Start_Action_Workflow
383 --   Launch a service request action workflow process.
384 ----------------------------------------------------------------------
385 
386 PROCEDURE Start_Action_Workflow
387 ( p_request_id			IN	NUMBER,
388   p_action_number		IN	NUMBER,
389   p_initiator_user_id		IN	NUMBER,
390   p_initiator_resp_id		IN	NUMBER   := NULL,
391   p_initiator_resp_appl_id	IN	NUMBER   := NULL,
392   p_launched_by_dispatch	IN	VARCHAR2 := 'N',
393   p_workflow_process_id		OUT	NOCOPY NUMBER
394 )
395 IS
396   l_itemkey			VARCHAR2(240);
397   l_return_status		VARCHAR2(1);
398   l_msg_count			NUMBER;
399   l_msg_data			VARCHAR2(2000);
400   l_launched_by_dispatch	VARCHAR2(1);
401   l_pos				NUMBER;
402   l_exc_api_error		EXCEPTION;
403   EMPLOYEE_NOT_FOUND	EXCEPTION;
404   ACTION_NOT_VALID		EXCEPTION;
405 
406 BEGIN
407   -- Establish savepoint
408   SAVEPOINT Start_Action_Workflow;
409 
410   -- Determine whether this call is made from the Dispatch window
411   IF (p_launched_by_dispatch = 'Y') THEN
412     l_launched_by_dispatch := FND_API.G_TRUE;
413   ELSE
414     l_launched_by_dispatch := FND_API.G_FALSE;
415   END IF;
416   -- Call the API. Notice that we are doing a quiet commit by setting
417   -- the commit flag
418 
419 	Pre_Validate_FS_Action
420 	(
421 		fs_request_id		=> p_request_id,
422 		fs_action_num		=> p_action_number,
423 		x_return_status	=> l_return_status
424 	);
425 	if l_return_status = 'E' then
426 		RAISE EMPLOYEE_NOT_FOUND;
427 	elsif l_return_status = 'A' then
428 		RAISE ACTION_NOT_VALID;
429 	end if;
430 
431   /*CS_Workflow_PUB.launch_Action_Workflow
432     (
433 	p_api_version		=> 1.0,
434       p_init_msg_list		=> FND_API.G_TRUE,
435       p_commit			=> FND_API.G_TRUE,
436       p_return_status		=> l_return_status,
437       p_msg_count		=> l_msg_count,
438       p_msg_data		=> l_msg_data,
439       p_request_id		=> p_request_id,
440       p_action_number		=> p_action_number,
441       p_initiator_user_id	=> p_initiator_user_id,
442       p_initiator_resp_id	=> p_initiator_resp_id,
443       p_initiator_resp_appl_id	=> p_initiator_resp_appl_id,
444       p_launched_by_dispatch	=> l_launched_by_dispatch,
445       p_itemkey		  	=> l_itemkey,
446       p_nowait	                => FND_API.G_TRUE
447     );*/
448 
449   -- Check for possible errors returned by the API
450   IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
451     RAISE l_exc_api_error;
452   END IF;
453 
454   l_pos := INSTR(l_itemkey, '-');
455   l_pos := INSTR(l_itemkey, '-', l_pos+1);
456   p_workflow_process_id := SUBSTR(l_itemkey, l_pos+1);
457 
458 EXCEPTION
459   WHEN l_exc_api_error THEN
460     ROLLBACK TO Start_Action_Workflow;
461     FND_MESSAGE.Set_Name('CS', 'CS_SR_WORKFLOW_API_ERROR');
462     FND_MESSAGE.Set_Token('ERROR_MSG', l_msg_data);
463     APP_EXCEPTION.Raise_Exception;
464   WHEN EMPLOYEE_NOT_FOUND THEN
465     ROLLBACK TO Start_Action_Workflow;
466     FND_MESSAGE.SET_NAME('CS', 'CS_CHG_EMP_NOT_FOUND');
467     APP_EXCEPTION.Raise_Exception;
468   WHEN ACTION_NOT_VALID THEN
469     ROLLBACK TO Start_Action_Workflow;
470     FND_MESSAGE.SET_NAME('CS', 'CS_CHG_ACT_NOT_VALID');
471     APP_EXCEPTION.Raise_Exception;
472 
473 END Start_Action_Workflow;
474 
475 
476 ----------------------------------------------------------------------
477 -- Abort_Action_Workflow
478 --   Abort a service request action workflow process
479 ----------------------------------------------------------------------
480 
481 PROCEDURE Abort_Action_Workflow
482 ( p_request_id			IN	NUMBER,
483   p_action_number		IN	NUMBER,
484   p_wf_process_id		IN	NUMBER,
485   p_abort_user_id		IN	NUMBER,
486   p_launched_by_dispatch	OUT	NOCOPY VARCHAR2
487 )
488 IS
489   l_return_status		VARCHAR2(1);
490   l_msg_count			NUMBER;
491   l_msg_data			VARCHAR2(2000);
492   l_launched_by_dispatch	VARCHAR2(1);
493   l_exc_api_error		EXCEPTION;
494 BEGIN
495   SAVEPOINT Abort_Action_Workflow;
496 
497   -- Call the API. Notice that we are doing a quiet commit by setting
498   -- the commit flag
499   CS_Workflow_PUB.Cancel_Action_Workflow
500     ( p_api_version		=> 1.0,
501       p_init_msg_list		=> FND_API.G_TRUE,
502       p_commit			=> FND_API.G_TRUE,
503       p_return_status		=> l_return_status,
504       p_msg_count		=> l_msg_count,
505       p_msg_data		=> l_msg_data,
506       p_request_id		=> p_request_id,
507       p_action_number		=> p_action_number,
508       p_wf_process_id		=> p_wf_process_id,
509       p_abort_user_id		=> p_abort_user_id,
510       p_launched_by_dispatch	=> l_launched_by_dispatch
511     );
512 
513   -- Check for possible errors returned by the API
514   IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
515     RAISE l_exc_api_error;
516   END IF;
517 
518   IF FND_API.To_Boolean(l_launched_by_dispatch) THEN
519     p_launched_by_dispatch := 'Y';
520   ELSE
521     p_launched_by_dispatch := 'N';
522   END IF;
523 
524 EXCEPTION
525   WHEN l_exc_api_error THEN
526     ROLLBACK TO Abort_Action_Workflow;
527     FND_MESSAGE.Set_Name('CS', 'CS_SR_WORKFLOW_API_ERROR');
528     FND_MESSAGE.Set_Token('ERROR_MSG', l_msg_data);
529     APP_EXCEPTION.Raise_Exception;
530 
531 END Abort_Action_Workflow;
532 
533 
534 
535 
536 
537 
538 /********************************************************************
539 -- Start_Servereq_Workflow
540 --   Launch a service request workflow process.
541 --   Overloaded procedure to return any messages back to the calling library
542 --   CSSRISR.pld  . rmanabat 05/08/02
543 --
544 --   11.5.9 . rmanabat . 03/13/03.
545 --   This manually launches the workflow from the UI by raising the event.
546 --   if the workflow was not launched via the workflow event, we will try
547 --   to launch the workflow using the old workflow API calls.
548 ********************************************************************/
549 
550   PROCEDURE Start_Servereq_Workflow (
551                 p_request_number          IN VARCHAR2,
552                 p_wf_process_name         IN VARCHAR2,
553                 p_initiator_user_id       IN NUMBER,
554                 p_initiator_resp_id       IN NUMBER   := NULL,
555                 p_initiator_resp_appl_id  IN NUMBER   := NULL,
556                 p_workflow_process_id    OUT NOCOPY NUMBER,
557                 x_msg_count              OUT NOCOPY NUMBER,
558                 x_msg_data               OUT NOCOPY VARCHAR2 ) IS
559 
560     l_itemkey           VARCHAR2(240);
561     l_return_status     VARCHAR2(1);
562     l_msg_count         NUMBER;
563     l_msg_data          VARCHAR2(2000);
564     l_pos               NUMBER;
565     l_API_ERROR         EXCEPTION;
566 
567     l_workflow_process_id	NUMBER;
568 
569     l_event_id	NUMBER;
570     l_event_key VARCHAR2(60);
571     l_param_list                wf_parameter_list_t;
572     l_initiator_role	VARCHAR2(100);
573     l_dummy                     VARCHAR2(240);
574     l_administrator             VARCHAR2(100);
575     x_wf_process_id NUMBER;
576 
577 
578     CURSOR l_sel_request_csr IS
579         SELECT nvl(status.close_flag,'N') close_flag,
580                 inc.workflow_process_id,
581                 cit.AUTOLAUNCH_WORKFLOW_FLAG,
582                 cit.WORKFLOW,
583                 inc.resource_type,
584                 inc.incident_owner_id,
585                 inc.incident_id,
586                 inc.object_version_number
587         FROM   cs_incident_statuses status,
588                 cs_incidents_all_b inc,
589                 cs_incident_types cit
590         WHERE  inc.incident_number = p_request_number
591                AND inc.incident_status_id = status.incident_status_id
592                and cit.incident_type_id = inc.incident_type_id;
593 
594     l_sel_request_rec   l_sel_request_csr%ROWTYPE;
595 
596 
597   BEGIN
598     -- establish savepoint
599     SAVEPOINT start_workflow;
600 
601     --INSERT INTO rm_tmp values (p_request_number, 'In 2nd overloaded Start_Servereq_Workflow,p_wf_manual_launch =Y',rm_tmp_seq.nextval);
602 
603     --  Derive Role from User ID
604     IF (p_initiator_user_id IS NOT NULL) THEN
605       CS_WF_AUTO_NTFY_UPDATE_PKG.get_fnd_user_role
606            ( p_fnd_user_id        => p_initiator_user_id,
607              x_role_name          => l_initiator_role,
608              x_role_display_name  => l_dummy );
609     END IF;
610 
611 
612     wf_event.AddParameterToList(p_name => 'REQUEST_NUMBER',
613                               p_value => p_request_number,
614                               p_parameterlist => l_param_list);
615 
616     wf_event.AddParameterToList(p_name => 'USER_ID',
617                               p_value => p_initiator_user_id,
618                               p_parameterlist => l_param_list);
619 
620     wf_event.AddParameterToList(p_name => 'RESP_ID',
621                               p_value => p_initiator_resp_id,
622                               p_parameterlist => l_param_list);
623 
624     wf_event.AddParameterToList(p_name => 'RESP_APPL_ID',
625                               p_value => p_initiator_resp_appl_id,
626                               p_parameterlist => l_param_list);
627 
628     wf_event.AddParameterToList(p_name => 'INITIATOR_ROLE',
629                               p_value => l_initiator_role,
630                               p_parameterlist => l_param_list);
631 
632     wf_event.AddParameterToList(p_name => 'MANUAL_LAUNCH',
633                               p_value => 'Y',
634                               p_parameterlist => l_param_list);
635 
636 
637 
638     BEGIN
639       l_administrator := FND_PROFILE.VALUE('CS_WF_ADMINISTRATOR');
640 
641       wf_event.AddParameterToList(p_name => 'WF_ADMINISTRATOR',
642                                 p_value => l_administrator,
643                                 p_parameterlist => l_param_list);
644     EXCEPTION
645       WHEN NO_DATA_FOUND THEN
646         null;
647     END;
648 
649 
650 
651     SELECT cs_wf_process_id_s.nextval
652     INTO l_event_id
653     FROM dual;
654 
655     -- Construct the unique event key
656     l_event_key := p_request_number ||'-'||to_char(l_event_id) || '-EVT';
657 
658  --INSERT INTO rm_tmp values (p_request_number, 'Raising Update event from start_servereq ',rm_tmp_seq.nextval);
659  --INSERT INTO rm_tmp values (p_request_number, 'oracle.apps.cs.sr.ServiceRequest.updated'||' l_event_key= '|| l_event_key ,rm_tmp_seq.nextval);
660 
661     -- Raise Workflow Business Event based on the event code.
662     wf_event.raise(p_event_name => 'oracle.apps.cs.sr.ServiceRequest.updated',
663                    p_event_key  => l_event_key,
664                    p_parameters => l_param_list);
665 
666 
667 
668     IF (CS_Workflow_PKG.Is_Servereq_Item_Active
669                          (p_request_number  => p_request_number,
670                           p_wf_process_id   => l_event_id)  = 'Y') THEN
671 
672 
673 
674  --INSERT INTO rm_tmp values (p_request_number, 'Event successfully raised from start_servereq ',rm_tmp_seq.nextval);
675 
676 
677       UPDATE CS_INCIDENTS_ALL_B set WORKFLOW_PROCESS_ID = l_event_id
678       WHERE INCIDENT_ID = l_sel_request_rec.incident_id;
679 
680       COMMIT WORK;
681       --commit;
682 
683       p_workflow_process_id := l_event_id;
684 
685 
686     /*******************************
687      Workflow was not launched via call to the raise event (BES).
688      Will try to launch the workflow using the old API calls.
689     ********************************/
690 
691     ELSIF (p_wf_process_name IS NOT NULL) THEN
692 
693  --INSERT INTO rm_tmp values (p_request_number, 'Event UNsuccessfull, attempting to Start WF from start_servereq ',rm_tmp_seq.nextval);
694 
695       OPEN l_sel_request_csr;
696       FETCH l_sel_request_csr INTO l_sel_request_rec;
697 
698 
699       IF (l_sel_request_csr%FOUND AND
700           l_sel_request_rec.resource_type = 'RS_EMPLOYEE' AND
701           l_sel_request_rec.incident_owner_id IS NOT NULL AND
702           l_sel_request_rec.close_flag <> 'Y' ) THEN
703 
704         /*************
705         CS_Workflow_PKG.Start_Servereq_Workflow(
706                                 p_request_number        => p_request_number,
707                                 p_wf_process_name       => p_wf_process_name,
708                                 p_initiator_user_id     => p_initiator_user_id,
709                                 p_initiator_resp_id     => p_initiator_resp_id,
710                                 p_initiator_resp_appl_id=> p_initiator_resp_appl_id,
711                                 --
712                                 -- This flag should be set to 'N' when called from the
713                                 -- Update/Create SR api, or any other API. This is only
714                                 -- set to 'Y' when called from the tools menu of the SR UI.
715                                 --
716                                 p_wf_manual_launch      => 'N',
717                                 p_workflow_process_id   => x_wf_process_id,
718                                 x_msg_count             => x_msg_count,
719                                 x_msg_data              => x_msg_data);
720 
721         p_workflow_process_id := x_wf_process_id;
722         *********/
723 
724 
725         CS_Workflow_PUB.Launch_Servereq_Workflow (
726                   p_api_version           => 1.0,
727                   p_init_msg_list         => FND_API.G_TRUE,
728                   p_commit                => FND_API.G_TRUE,
729                   p_return_status         => l_return_status,
730                   p_msg_count             => x_msg_count,
731                   p_msg_data              => x_msg_data,
732                   p_request_number        => p_request_number,
733                   p_initiator_user_id     => p_initiator_user_id,
734                   p_initiator_resp_id     => p_initiator_resp_id,
735                   p_initiator_resp_appl_id=> p_initiator_resp_appl_id,
736                   p_itemkey               => l_itemkey,
737                   p_nowait                => FND_API.G_TRUE );
738 
739         -- Check for possible errors returned by the API
740         IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
741           raise l_API_ERROR;
742         END IF;
743 
744         l_pos := INSTR(l_itemkey, '-');
745         p_workflow_process_id := SUBSTR(l_itemkey, l_pos+1);
746 
747 
748       END IF;
749 
750       CLOSE l_sel_request_csr;
751 
752     END IF;
753 
754 
755   EXCEPTION
756     WHEN l_API_ERROR THEN
757       ROLLBACK TO start_workflow;
758       FND_MESSAGE.Set_Name('CS', 'CS_SR_WORKFLOW_API_ERROR');
759       FND_MESSAGE.Set_Token('ERROR_MSG', x_msg_data);
760       --FND_MESSAGE.Set_Token('ERROR_MSG', l_msg_data);
761       -- rmanabat 11/20/01 Fix for bug# 2102121.
762       --APP_EXCEPTION.Raise_Exception;
763 
764   END Start_Servereq_Workflow;
765 
766 
767 END CS_Workflow_PKG;