1 PACKAGE BODY OE_STANDARD_WF AS
2 /* $Header: OEXWSTDB.pls 120.4.12020000.2 2013/01/10 08:51:42 spothula ship $ */
3
4 -- This procedure sets the global g_upgrade_mode to TRUE
5 Procedure UPGRADE_MODE_ON
6 IS
7 --
8 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
9 --
10 Begin
11 OE_STANDARD_WF.G_UPGRADE_MODE := TRUE;
12 End UPGRADE_MODE_ON;
13
14 -- This procedure sets the global g_save_messages to TRUE
15 Procedure SAVE_MESSAGES_ON
16 IS
17 --
18 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
19 --
20 Begin
21 OE_STANDARD_WF.G_SAVE_MESSAGES := TRUE;
22 End SAVE_MESSAGES_ON;
23
24 -- This procedure sets the global g_save_messages to FALSE
25 Procedure SAVE_MESSAGES_OFF
26 IS
27 --
28 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
29 --
30 Begin
31 OE_STANDARD_WF.G_SAVE_MESSAGES := FALSE;
32 End SAVE_MESSAGES_OFF;
33
34 -- This procedure sets the global G_RESET_APPS_CONTEXT to TRUE
35 Procedure RESET_APPS_CONTEXT_ON
36 IS
37 --
38 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
39 --
40 Begin
41 OE_STANDARD_WF.G_RESET_APPS_CONTEXT := TRUE;
42 End RESET_APPS_CONTEXT_ON;
43
44 -- This procedure sets the global G_RESET_APPS_CONTEXT to FALSE
45 Procedure RESET_APPS_CONTEXT_OFF
46 IS
47 --
48 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
49 --
50 Begin
51 OE_STANDARD_WF.G_RESET_APPS_CONTEXT := FALSE;
52 End RESET_APPS_CONTEXT_OFF;
53
54 -- Callers should pass in the instance_id. This is used to set Workflow
55 -- context for messages.
56 PROCEDURE SET_MSG_CONTEXT(P_PROCESS_ACTIVITY IN NUMBER DEFAULT NULL)
57 IS
58 --
59 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
60 --
61 BEGIN
62 OE_MSG_PUB.Set_Process_Activity(p_process_activity);
63 END;
64
65 -- This procedures clears the workflow context from the context area.
66 PROCEDURE CLEAR_MSG_CONTEXT
67 IS
68 --
69 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
70 --
71 BEGIN
72 OE_MSG_PUB.Set_Process_Activity(NULL);
73 END;
74
75 PROCEDURE SAVE_MESSAGES(
76 p_instance_id IN NUMBER DEFAULT NULL
77 )
78 is
79 --
80 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
81 --
82 begin
83 IF l_debug_level > 0 THEN
84 oe_debug_pub.add('In WF save messages', 5);
85 END IF;
86
87 -- we will save the message regardless of the global
88 -- since the save_api_messages will have the intelligence
89 -- not to save duplicate messages
90
91 -- not passing the p_instance_id as it is not used for WF
92 OE_MSG_PUB.Save_API_Messages(p_request_id => NULL, p_message_source_code => 'W');
93
94
95 exception
96 when others then
97 Wf_Core.Context('OE_STANDARD_WF', 'SAVE_MESSAGES');
98 raise;
99 end SAVE_MESSAGES;
100
101
102
103 /*--------------------------------------------------------------------
104 New BLOCK activity defined so that the activity cannot be
105 completed by the end-user through 'Progress Order'. This
106 block function should be used instead of the wf_engine standard
107 block function if the activity should be blocked for completion
108 from the Progress Order form
109 ----------------------------------------------------------------------*/
110 procedure STANDARD_BLOCK(itemtype in varchar2,
111 itemkey in varchar2,
112 actid in number,
113 funcmode in varchar2,
114 resultout in out nocopy varchar2 /* file.sql.39 change */
115 )
116 is
117 --
118 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
119 --
120 begin
121 -- start data fix project
122 OE_STANDARD_WF.Set_Msg_Context(actid);
123 -- end data fix project
124
125 -- Do nothing in cancel or timeout mode
126 if (funcmode <> wf_engine.eng_run) then
127 resultout := wf_engine.eng_null;
128 return;
129 end if;
130
131 resultout := wf_engine.eng_notified||':'||wf_engine.eng_null||
132 ':'||wf_engine.eng_null;
133 exception
134 when others then
135 Wf_Core.Context('OE_STANDARD_WF', 'STANDARD_BLOCK', itemtype,
136 itemkey, to_char(actid), funcmode);
137 -- start data fix project
138 OE_STANDARD_WF.Add_Error_Activity_Msg(p_actid => actid,
139 p_itemtype => itemtype,
140 p_itemkey => itemkey);
141 OE_STANDARD_WF.Save_Messages;
142 OE_STANDARD_WF.Clear_Msg_Context;
143 -- end data fix project
144 raise;
145 end STANDARD_BLOCK;
146
147 /* --------------------------------------------------------
148 This procedure is used to set the database session context
149 correctly before executing a function activity. The selector
150 function will be run by the workflow engine in the SET_CTX
151 mode before executing the activity.
152 ----------------------------------------------------------- */
153
154 PROCEDURE OEOH_SELECTOR
155 ( p_itemtype in varchar2
156 , p_itemkey in varchar2
157 , p_actid in number
158 , p_funcmode in varchar2
159 , p_result in out nocopy varchar2 /* file.sql.39 change */
160 )
161 IS
162 l_user_id NUMBER;
163 l_resp_id NUMBER;
164 l_resp_appl_id NUMBER;
165 l_header_id NUMBER;
166 l_org_id NUMBER;
167 l_current_org_id NUMBER;
168 l_client_org_id NUMBER;
169
170 --
171 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
172 --
173 BEGIN
174
175 -- p_result := FND_API.G_MISS_CHAR;
176
177 -- Workflow engine calls the SET_CTX to set the context for the
178 -- activity before the execution.
179 --Bug 6884804
180 IF l_debug_level > 0 THEN
181 oe_debug_pub.add( 'THE WORKFLOW FUNCTION MODE IS: FUNCMODE='||P_FUNCMODE
182 ||' ITEMTYPE = '||P_ITEMTYPE||' ITEMKEY = '||P_ITEMKEY,1);
183 END IF;
184 --End Bug 6884804
185
186
187 l_header_id := to_number(p_itemkey);
188 IF l_debug_level > 0 THEN
189 oe_debug_pub.add( 'HEADER ID IS ' || L_HEADER_ID ) ;
190 END IF;
191
192 -- Currently this mode is not being used
193 -- we are using the OE_ORDER_WF_UTIL pkg functions
194 -- to find out the flow that a header needs to follow
195 -- and passing that in the createprocess call within
196 -- Process Order.
197
198 IF (p_funcmode = 'RUN') THEN
199 p_result := 'COMPLETE';
200
201 -- Engine calls SET_CTX just before activity execution
202
203 ELSIF(p_funcmode = 'SET_CTX') THEN
204
205
206 -- Any caller that calls the WF_ENGINE can set this to FALSE in which case
207 -- we will not reset apps context to that of the user who created the line
208 -- wf item.
209
210 IF G_RESET_APPS_CONTEXT THEN
211
212 SELECT org_id
213 INTO l_org_id
214 FROM oe_order_headers_all
215 WHERE header_id = to_number (p_itemkey);
216 IF l_debug_level > 0 THEN
217 oe_debug_pub.add('ORG ID IS ' || l_org_id ) ;
218 END IF;
219
220 MO_GLOBAL.set_policy_context ('S', l_org_id);
221
222 END IF;
223
224 p_result := 'COMPLETE';
225
226 -- Notification Viewer form calls the TEST_CTX just before launching the form
227 -- WF Engine calls TEST_CTX, if this returns FALSE then flow is deferred.
228 ELSIF (p_funcmode = 'TEST_CTX') THEN
229
230 --initialize global so each tested flow must set explicitly
231 OE_GLOBALS.G_FLOW_RESTARTED := FALSE;
232
233 IF G_UPGRADE_MODE THEN -- During Upgrade Mode we always return TRUE;
234
235 p_result := 'TRUE';
236
237 ELSE -- Normal Mode
238
239 IF G_RESET_APPS_CONTEXT THEN
240
241 -- Setting a global varaible to indicate that the process is being run
242 -- as a result of the flow being restarted
243 OE_GLOBALS.G_FLOW_RESTARTED := TRUE;
244
245 SELECT org_id
246 INTO l_org_id
247 FROM oe_order_headers_all
248 WHERE header_id = to_number (p_itemkey);
249
250 IF NVL(MO_GLOBAL.get_current_org_id, -99) <> l_org_id
251 THEN
252 p_result := 'FALSE';
253 ELSE
254 p_result := 'TRUE';
255 END IF;
256
257 ELSE -- G_RESET_APPS_CONTEXT is FALSE
258 p_result := 'TRUE';
259 END IF;
260
261 END IF; -- End If Upgrade Mode
262
263 END IF; -- End if TEST_CTX
264
265 --Bug 6884804
266 IF l_debug_level > 0 THEN
267 oe_debug_pub.add( ' Exiting OEOH_SELECTOR , RESULT = '||P_RESULT
268 ||' ITEMTYPE = '||P_ITEMTYPE||' ITEMKEY = '||P_ITEMKEY,1);
269 END IF;
270 --End Bug 6884804
271 EXCEPTION
272 WHEN OTHERS THEN NULL;
273 WF_CORE.Context('OE_STANDARD_WF', 'OEOH_SELECTOR',
274 p_itemtype, p_itemkey, p_actid, p_funcmode);
275 RAISE;
276
277
278 END OEOH_SELECTOR;
279
280 /* --------------------------------------------------------
281 This procedure is used to set the database session context
282 correctly before executing a function activity. The selector
283 function will be run by the workflow engine in the SET_CTX
284 mode before executing the activity.
285 ----------------------------------------------------------- */
286 PROCEDURE OEOL_SELECTOR
287 ( p_itemtype in varchar2
288 , p_itemkey in varchar2
289 , p_actid in number
290 , p_funcmode in varchar2
291 , p_result in out nocopy varchar2 /* file.sql.39 change */
292 )
293 IS
294 l_user_id NUMBER;
295 l_resp_id NUMBER;
296 l_resp_appl_id NUMBER;
297 l_org_id NUMBER;
298 l_current_org_id NUMBER;
299 l_client_org_id NUMBER;
300
301 --
302 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
303 --
304 BEGIN
305
306 -- Currently this mode is not being used
307 -- we are using the OE_ORDER_WF_UTIL pkg functions
308 -- to find out the flow that a line needs to follow
309 -- and passing that in the createprocess call within
310 -- Process Order.
311 --Bug 6884804
312 IF l_debug_level > 0 THEN
313 oe_debug_pub.add( 'IN OEOL_SELECTOR , FUNCMODE:' || P_FUNCMODE || ' ' || P_ITEMTYPE || ' ' || P_ITEMKEY , 1 ) ;
314 END IF;
315 --End Bug 6884804
316 IF G_RESET_APPS_CONTEXT THEN
317 IF l_debug_level > 0 THEN
318 oe_debug_pub.add( 'G_RESET_APPS_CONTEXT IS TRUE' ) ;
319 END IF;
320 ELSE
321 IF l_debug_level > 0 THEN
322 oe_debug_pub.add( 'G_RESET_APPS_CONTEXT IS FALSE' ) ;
323 END IF;
324 END IF;
325
326 IF G_UPGRADE_MODE THEN
327 IF l_debug_level > 0 THEN
328 oe_debug_pub.add( 'G_UPGRADE_MODE IS TRUE' ) ;
329 END IF;
330 ELSE
331 IF l_debug_level > 0 THEN
332 oe_debug_pub.add( 'G_UPGRADE_MODE IS FALSE' ) ;
333 END IF;
334 END IF;
335
336 if (p_funcmode = 'RUN') THEN
337 p_result := 'COMPLETE';
338
339 -- Engine calls SET_CTX just before activity execution
340 -- The workflow engine calls the selector function
341 -- in the SET_CTX mode to set the database context
342 -- correctly for executing a function activity.
343 ELSIF(p_funcmode = 'SET_CTX') THEN
344 -- Any caller that calls the WF_ENGINE can set this to FALSE in which case
345 -- we will not reset apps context to that of the user who created the line
346 -- wf item.
347 IF G_RESET_APPS_CONTEXT THEN
348 SELECT org_id
349 INTO l_org_id
350 FROM oe_order_lines_all
351 WHERE line_id = to_number (p_itemkey);
352
353 MO_GLOBAL.set_policy_context ('S', l_org_id);
354
355 END IF;
356 p_result := 'COMPLETE';
357
358 -- Notification Viewer form calls the TEST_CTX just before launching the form
359 -- If test_ctx returns false, then flow is automatically deferred.
360 ELSIF (p_funcmode = 'TEST_CTX') THEN
361
362 --initialize global so each tested flow must set explicitly
363 OE_GLOBALS.G_FLOW_RESTARTED := FALSE;
364
365 IF G_UPGRADE_MODE THEN -- During Upgrade Mode we always return TRUE;
366 p_result := 'TRUE';
367 ELSE -- Normal Mode
368 IF G_RESET_APPS_CONTEXT THEN
369
370 -- Setting a global varaible to indicate that the process is
371 -- being run as a result of the flow being restarted
372 OE_GLOBALS.G_FLOW_RESTARTED := TRUE;
373
374 SELECT org_id
375 INTO l_org_id
376 FROM oe_order_lines_all
377 WHERE line_id = to_number (p_itemkey);
378 IF l_debug_level > 0 THEN
379 oe_debug_pub.add('ORG ID IS ' || l_org_id ) ;
380 END IF;
381
382 IF NVL(MO_GLOBAL.get_current_org_id, -99) <> l_org_id
383 THEN
384 p_result := 'FALSE';
385 ELSE
386 p_result := 'TRUE';
387 END IF;
388
389 ELSE -- G_RESET_APPS_CONTEXT is FALSE
390 p_result := 'TRUE';
391 END IF;
392
393 END IF; -- End Upgrade Mode.
394
395 END IF; -- End mode
396
397 --Bug 6884804
398 IF l_debug_level > 0 THEN
399 oe_debug_pub.add( ' Exiting OEOL_SELELECTOR , RESULT = '||P_RESULT
400 ||' ITEMTYPE = '||P_ITEMTYPE||' ITEMKEY = '||P_ITEMKEY,1);
401 END IF;
402 --End Bug 6884804
403 IF l_debug_level > 0 THEN
404 oe_debug_pub.add( 'P_RESULT:' || P_RESULT ) ;
405 END IF;
406
407 EXCEPTION
408 WHEN OTHERS THEN NULL;
409 WF_CORE.Context('OE_STANDARD_WF', 'OEOL_SELECTOR',
410 p_itemtype, p_itemkey, p_actid, p_funcmode);
411 RAISE;
412
413
414 END OEOL_SELECTOR;
415
416
417 /* --------------------------------------------------------
418 This procedure is used to set the database session context
419 correctly before executing a function activity. The selector
420 function will be run by the workflow engine in the SET_CTX
421 mode before executing the activity.
422 ----------------------------------------------------------- */
423
424 PROCEDURE OENH_SELECTOR
425 ( p_itemtype in varchar2
426 , p_itemkey in varchar2
427 , p_actid in number
428 , p_funcmode in varchar2
429 , p_result in out nocopy varchar2 /* file.sql.39 change */
430 )
431 IS
432 l_user_id NUMBER;
433 l_resp_id NUMBER;
434 l_resp_appl_id NUMBER;
435 l_header_id NUMBER;
436 l_org_id NUMBER;
437 l_current_org_id NUMBER;
438 l_client_org_id NUMBER;
439 l_sales_document_type_code VARCHAR2(1);
440 --
441 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
442 --
443 BEGIN
444
445 -- Workflow engine calls the SET_CTX to set the context for the
446 -- activity before the execution.
447 --Bug 6884804
448 IF l_debug_level > 0 THEN
449 oe_debug_pub.add( 'THE WORKFLOW FUNCTION MODE IS: FUNCMODE='||P_FUNCMODE
450 ||' ITEMTYPE = '||P_ITEMTYPE||' ITEMKEY = '||P_ITEMKEY,1);
451 END IF;
452 --End Bug 6884804
453
454 l_header_id := to_number(p_itemkey);
455 IF l_debug_level > 0 THEN
456 oe_debug_pub.add( 'OENH HEADER ID IS ' || L_HEADER_ID ) ;
457 END IF;
458
459 IF (p_funcmode = 'RUN') THEN
460 p_result := 'COMPLETE';
461
462 ELSIF(p_funcmode = 'SET_CTX') THEN
463
464 -- Any caller that calls the WF_ENGINE can set this to FALSE in which case
465 -- we will not reset apps context to that of the user who created the line
466 -- wf item.
467
468 IF G_RESET_APPS_CONTEXT THEN
469
470 l_sales_document_type_code := WF_ENGINE.GetItemAttrText(p_itemtype,
471 p_itemkey, 'SALES_DOCUMENT_TYPE_CODE');
472
473 IF l_sales_document_type_code = 'O' THEN
474 SELECT org_id
475 INTO l_org_id
476 FROM oe_order_headers_all
477 WHERE header_id = to_number (p_itemkey);
478 ELSIF l_sales_document_type_code = 'B' THEN
479 SELECT org_id
480 INTO l_org_id
481 FROM oe_blanket_headers_all
482 WHERE header_id = to_number (p_itemkey);
483 ELSE
484 -- Should never get here. In negotiation phase it should be O or B
485 oe_debug_pub.add('l_sales_document_type_code is NULL for:' || p_itemkey);
486 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
487 END IF;
488
489 MO_GLOBAL.set_policy_context ('S', l_org_id);
490
491 END IF;
492
493 p_result := 'COMPLETE';
494
495 -- Notification Viewer form calls the TEST_CTX just before launching the form
496 -- WF Engine calls TEST_CTX, if this returns FALSE then flow is deferred.
497 ELSIF (p_funcmode = 'TEST_CTX') THEN
498
499 --initialize global so each tested flow must set explicitly
500 OE_GLOBALS.G_FLOW_RESTARTED := FALSE;
501
502 IF G_UPGRADE_MODE THEN -- During Upgrade Mode we always return TRUE;
503
504 p_result := 'TRUE';
505
506 ELSE -- Normal Mode
507
508 IF G_RESET_APPS_CONTEXT THEN
509
510 -- Setting a global varaible to indicate that the process
511 -- is being run as a result of the flow being restarted
512 OE_GLOBALS.G_FLOW_RESTARTED := TRUE;
513
514 l_sales_document_type_code := WF_ENGINE.GetItemAttrText(p_itemtype,
515 p_itemkey, 'SALES_DOCUMENT_TYPE_CODE');
516
517 IF l_sales_document_type_code = 'O' THEN
518 SELECT org_id
519 INTO l_org_id
520 FROM oe_order_headers_all
521 WHERE header_id = to_number (p_itemkey);
522 ELSIF l_sales_document_type_code = 'B' THEN
523 SELECT org_id
524 INTO l_org_id
525 FROM oe_blanket_headers_all
526 WHERE header_id = to_number (p_itemkey);
527 ELSE
528 -- Should never get here. In negotiation phase it should be O or B
529 oe_debug_pub.add('l_sales_document_type_code is NULL for:' || p_itemkey);
530 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
531 END IF;
532
533 IF l_debug_level > 0 THEN
534 oe_debug_pub.add('ORG ID IS ' || l_org_id ) ;
535 END IF;
536
537 IF NVL(MO_GLOBAL.get_current_org_id, -99) <> l_org_id
538 THEN
539 p_result := 'FALSE';
540 ELSE
541 p_result := 'TRUE';
542 END IF;
543
544 ELSE -- G_RESET_APPS_CONTEXT is FALSE
545 p_result := 'TRUE';
546 END IF;
547
548 END IF; -- End If Upgrade Mode
549
550 END IF; -- End if TEST_CTX
551
552 --Bug 6884804
553 IF l_debug_level > 0 THEN
554 oe_debug_pub.add( ' Exiting OENH_SELECTOR , RESULT = '||P_RESULT
555 ||' ITEMTYPE = '||P_ITEMTYPE||' ITEMKEY = '||P_ITEMKEY,1);
556 END IF;
557 --End Bug 6884804
558 EXCEPTION
559 WHEN OTHERS THEN NULL;
560 WF_CORE.Context('OE_STANDARD_WF', 'OENH_SELECTOR',
561 p_itemtype, p_itemkey, p_actid, p_funcmode);
562 RAISE;
563
564
565 END OENH_SELECTOR;
566
567
568
569 /* --------------------------------------------------------
570 This procedure is used to set the database session context
571 correctly before executing a function activity. The selector
572 function will be run by the workflow engine in the SET_CTX
573 mode before executing the activity.
574 ----------------------------------------------------------- */
575
576 PROCEDURE OEBH_SELECTOR
577 ( p_itemtype in varchar2
578 , p_itemkey in varchar2
579 , p_actid in number
580 , p_funcmode in varchar2
581 , p_result in out nocopy varchar2 /* file.sql.39 change */
582 )
583 IS
584 l_user_id NUMBER;
585 l_resp_id NUMBER;
586 l_resp_appl_id NUMBER;
587 l_header_id NUMBER;
588 l_org_id NUMBER;
589 l_current_org_id NUMBER;
590 l_client_org_id NUMBER;
591
592 --
593 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
594 --
595 BEGIN
596
597 -- Workflow engine calls the SET_CTX to set the context for the
598 -- activity before the execution.
599 --Bug 6884804
600 IF l_debug_level > 0 THEN
601 oe_debug_pub.add( 'THE WORKFLOW FUNCTION MODE IS: FUNCMODE='||P_FUNCMODE
602 ||' ITEMTYPE = '||P_ITEMTYPE||' ITEMKEY = '||P_ITEMKEY,1);
603 END IF;
604 --End Bug 6884804
605
606 l_header_id := to_number(p_itemkey);
607 IF l_debug_level > 0 THEN
608 oe_debug_pub.add( 'OEBH HEADER ID IS ' || L_HEADER_ID ) ;
609 END IF;
610
611 IF (p_funcmode = 'RUN') THEN
612 p_result := 'COMPLETE';
613
614 ELSIF(p_funcmode = 'SET_CTX') THEN
615
616 -- Any caller that calls the WF_ENGINE can set this to FALSE in which case
617 -- we will not reset apps context to that of the user who created the line
618 -- wf item.
619
620 IF G_RESET_APPS_CONTEXT THEN
621 SELECT org_id
622 INTO l_org_id
623 FROM oe_blanket_headers_all
624 WHERE header_id = to_number (p_itemkey);
625
626 MO_GLOBAL.set_policy_context ('S', l_org_id);
627
628 END IF;
629
630 p_result := 'COMPLETE';
631
632 -- Notification Viewer form calls the TEST_CTX just before launching the form
633 -- WF Engine calls TEST_CTX, if this returns FALSE then flow is deferred.
634 ELSIF (p_funcmode = 'TEST_CTX') THEN
635
636 --initialize global so each tested flow must set explicitly
637 OE_GLOBALS.G_FLOW_RESTARTED := FALSE;
638
639
640 IF G_UPGRADE_MODE THEN -- During Upgrade Mode we always return TRUE;
641
642 p_result := 'TRUE';
643
644 ELSE -- Normal Mode
645
646 IF G_RESET_APPS_CONTEXT THEN
647
648 -- Setting a global varaible to indicate that the process is
649 -- being run as a result of the flow being restarted
650 OE_GLOBALS.G_FLOW_RESTARTED := TRUE;
651
652 SELECT org_id
653 INTO l_org_id
654 FROM oe_blanket_headers_all
655 WHERE header_id = to_number (p_itemkey);
656 IF l_debug_level > 0 THEN
657 oe_debug_pub.add('ORG ID IS ' || l_org_id ) ;
658 END IF;
659
660 IF NVL(MO_GLOBAL.get_current_org_id, -99) <> l_org_id
661 THEN
662 p_result := 'FALSE';
663 ELSE
664 p_result := 'TRUE';
665 END IF;
666
667 ELSE -- G_RESET_APPS_CONTEXT is FALSE
668 p_result := 'TRUE';
669 END IF;
670
671 END IF; -- End If Upgrade Mode
672
673 END IF; -- End if TEST_CTX
674
675 --Bug 6884804
676 IF l_debug_level > 0 THEN
677 oe_debug_pub.add( ' Exiting OEBH_SELECTOR , RESULT = '||P_RESULT
678 ||' ITEMTYPE = '||P_ITEMTYPE||' ITEMKEY = '||P_ITEMKEY,1);
679 END IF;
680 --End Bug 6884804
681 EXCEPTION
682 WHEN OTHERS THEN NULL;
683 WF_CORE.Context('OE_STANDARD_WF', 'OEBH_SELECTOR',
684 p_itemtype, p_itemkey, p_actid, p_funcmode);
685 RAISE;
686
687
688 END OEBH_SELECTOR;
689
690
691 /* --------------------------------------------------------
692 This procedure is used to Get the source_type of the line.
693 ----------------------------------------------------------- */
694 PROCEDURE Get_Supply_Source_Type
695 ( p_itemtype in varchar2
696 , p_itemkey in varchar2
697 , p_actid in number
698 , p_funcmode in varchar2
699 , p_result in out nocopy varchar2 /* file.sql.39 change */
700 )
701 IS
702 l_source_type VARCHAR2(30);
703 --
704 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
705 --
706 BEGIN
707 -- start data fix project
708 OE_STANDARD_WF.Set_Msg_Context(p_actid);
709 -- end data fix project
710
711 if (p_funcmode = 'RUN') THEN
712 SELECT source_type_code
713 INTO l_source_type
714 FROM oe_order_lines_all
715 WHERE line_id = to_number(p_itemkey);
716
717 IF l_source_type = OE_GLOBALS.G_SOURCE_EXTERNAL THEN
718 p_result := 'COMPLETE:EXTERNAL';
719 ELSE
720 p_result := 'COMPLETE:INTERNAL';
721 END IF;
722 end if;
723
724
725 EXCEPTION
726 WHEN OTHERS THEN NULL;
727 oe_msg_pub.set_msg_context ( p_entity_code => 'LINE'
728 ,p_line_id => p_itemkey);
729 WF_CORE.Context('OE_STANDARD_WF', 'Get_Supply_Source_Type',
730 p_itemtype, p_itemkey, p_actid, p_funcmode);
731 -- start data fix project
732 OE_STANDARD_WF.Add_Error_Activity_Msg(p_actid => p_actid,
733 p_itemtype => p_itemtype,
734 p_itemkey => p_itemkey);
735 OE_STANDARD_WF.Save_Messages;
736 OE_STANDARD_WF.Clear_Msg_Context;
737 -- end data fix project
738 RAISE;
739
740
741 END Get_Supply_Source_Type;
742
743
744 /* --------------------------------------------------------
745 This procedure is used to Get the Line Category.
746 ----------------------------------------------------------- */
747 PROCEDURE Get_Line_Category
748 ( p_itemtype in varchar2
749 , p_itemkey in varchar2
750 , p_actid in number
751 , p_funcmode in varchar2
752 , p_result in out nocopy varchar2 /* file.sql.39 change */
753 )
754 IS
755 l_category_code VARCHAR2(30);
756 --
757 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
758 --
759 BEGIN
760 -- start data fix project
761 OE_STANDARD_WF.Set_Msg_Context(p_actid);
762 -- end data fix project
763 IF (p_funcmode = 'RUN') THEN
764 IF p_itemtype = OE_GLOBALS.G_WFI_LIN THEN
765 l_category_code := wf_engine.GetItemAttrText(p_itemtype, p_itemkey, 'LINE_CATEGORY');
766 p_result := 'COMPLETE:'||l_category_code;
767 ELSE
768 RAISE FND_API.G_EXC_UNEXPECTED_ERROR; -- item type is not a line
769 END IF;
770
771 ELSE
772
773 p_result := 'COMPLETE:';
774
775 END IF;
776
777 EXCEPTION
778 WHEN OTHERS THEN NULL;
779 oe_msg_pub.set_msg_context ( p_entity_code => 'LINE'
780 ,p_line_id => p_itemkey);
781 WF_CORE.Context('OE_STANDARD_WF', 'Get_Line_Category',
782 p_itemtype, p_itemkey, p_actid, p_funcmode);
783 -- start data fix project
784 OE_STANDARD_WF.Add_Error_Activity_Msg(p_actid => p_actid,
785 p_itemtype => p_itemtype,
786 p_itemkey => p_itemkey);
787 OE_STANDARD_WF.Save_Messages;
788 OE_STANDARD_WF.Clear_Msg_Context;
789 -- end data fix project
790 RAISE;
791
792
793 END Get_Line_Category;
794
795
796
797 PROCEDURE Set_Exception_Message
798 IS
799 l_data VARCHAR2(500);
800 l_msg_index_out NUMBER;
801
802 --
803 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
804 --
805 BEGIN
806
807 OE_MSG_PUB.GET( p_msg_index => OE_MSG_PUB.G_LAST
808 ,p_encoded => FND_API.G_FALSE
809 ,p_data => l_data
810 ,p_msg_index_out => l_msg_index_out);
811 FND_MESSAGE.SET_NAME('ONT', 'OE_WF_EXCEPTION');
812 FND_MESSAGE.SET_TOKEN('EXCEPTION', l_data);
813
814 END Set_Exception_Message;
815
816 /* --------------------------------------------------------
817 This procedure is used to log a message with the
818 indicating the workflow activity that failed.
819 A different error message is used when the
820 message stack is empty as opposed to when
821 there are messages.
822 ----------------------------------------------------------- */
823
824 PROCEDURE Add_Error_Activity_Msg (p_actid IN NUMBER, p_itemkey IN VARCHAR2, p_itemtype IN VARCHAR2)
825 IS
826 l_msg_count NUMBER := 0;
827 l_activity_name VARCHAR2(80);
828 BEGIN
829 l_msg_count := OE_MSG_PUB.Count_Msg;
830
831 SELECT wfa.display_name
832 INTO l_activity_name
833 FROM wf_activities_vl wfa, wf_process_activities wpa
834 WHERE wpa.instance_id = p_actid
835 AND wpa.activity_item_type = p_itemtype
836 AND wfa.item_type = p_itemtype
837 AND wfa.name = wpa.activity_name
838 AND (wfa.end_date is null OR wfa.end_date >= sysdate)
839 AND rownum = 1;
840
841 IF l_msg_count > 0 THEN
842 FND_MESSAGE.SET_NAME ('ONT', 'OE_WF_ACTIVITY_ERROR');
843 FND_MESSAGE.SET_TOKEN ('ACTIVITY_NAME', l_activity_name);
844 OE_Msg_Pub.Add;
845 ELSE
846 FND_MESSAGE.SET_NAME ('ONT', 'OE_WF_ACTIVITY_UNEXP_ERROR');
847 FND_MESSAGE.SET_TOKEN ('ACTIVITY_NAME', l_activity_name);
848 OE_Msg_Pub.Add;
849 END IF;
850 EXCEPTION
851 WHEN OTHERS THEN NULL;
852 END Add_Error_Activity_Msg;
853
854 /*-----------------------------------------------------------
855 This procedure is called from the item type OEAME. OEAME flows
856 are alunched from OEOH and OENH flows, in case of AME approvals
857 ----------------------------------------------------------- */
858 -- ame ER 16084377
859 PROCEDURE oeame_selector (
860 p_itemtype IN VARCHAR2,
861 p_itemkey IN VARCHAR2,
862 p_actid IN NUMBER,
863 p_funcmode IN VARCHAR2,
864 p_result IN OUT NOCOPY VARCHAR2 /* file.sql.39 change */
865 )
866 IS
867 l_user_id NUMBER;
868 l_resp_id NUMBER;
869 l_resp_appl_id NUMBER;
870 l_header_id NUMBER;
871 l_org_id NUMBER;
872 l_current_org_id NUMBER;
873 l_client_org_id NUMBER;
874 l_sales_document_type_code VARCHAR2 (1);
875 --
876 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
877 l_parent_type VARCHAR2 (240);
878 --
879 BEGIN
880 -- Workflow engine calls the SET_CTX to set the context for the
881 -- activity before the execution.
882 --Bug 6884804
883 IF l_debug_level > 0
884 THEN
885 oe_debug_pub.ADD ( 'THE WORKFLOW FUNCTION MODE IS: FUNCMODE='
886 || p_funcmode
887 || ' ITEMTYPE = '
888 || p_itemtype
889 || ' ITEMKEY = '
890 || p_itemkey,
891 1
892 );
893 END IF;
894
895 --End Bug 6884804
896 IF p_itemtype = 'OEAME'
897 THEN
898 SELECT TO_NUMBER (parent_item_key), parent_item_type
899 INTO l_header_id, l_parent_type
900 FROM wf_items
901 WHERE item_type = p_itemtype AND item_key = p_itemkey;
902
903 IF l_debug_level > 0
904 THEN
905 oe_debug_pub.ADD ('parent_item_type:' || l_parent_type);
906 oe_debug_pub.ADD ('parent_item_key:' || l_header_id);
907 END IF;
908 ELSIF p_itemtype IN ('OEOH', 'OENH')
909 THEN
910 l_header_id := TO_NUMBER (p_itemkey);
911 END IF;
912
913 IF l_debug_level > 0
914 THEN
915 oe_debug_pub.ADD ('HEADER ID IS ' || l_header_id);
916 END IF;
917
918 IF (p_funcmode = 'RUN')
919 THEN
920 p_result := 'COMPLETE';
921 ELSIF (p_funcmode = 'SET_CTX')
922 THEN
923 IF NVL (l_parent_type, p_itemtype) = 'OENH'
924 THEN
925 -- Any caller that calls the WF_ENGINE can set this to FALSE in which case
926 -- we will not reset apps context to that of the user who created the line
927 -- wf item.
928 IF g_reset_apps_context
929 THEN
930 l_sales_document_type_code :=
931 wf_engine.getitemattrtext (p_itemtype,
932 p_itemkey,
933 'SALES_DOCUMENT_TYPE_CODE'
934 );
935
936 IF l_sales_document_type_code = 'O'
937 THEN
938 SELECT org_id
939 INTO l_org_id
940 FROM oe_order_headers_all
941 WHERE header_id = l_header_id;
942 ELSIF l_sales_document_type_code = 'B'
943 THEN
944 SELECT org_id
945 INTO l_org_id
946 FROM oe_blanket_headers_all
947 WHERE header_id = l_header_id;
948 ELSE
949 -- Should never get here. In negotiation phase it should be O or B
950 IF l_debug_level > 0
951 THEN
952 oe_debug_pub.ADD
953 ( 'l_sales_document_type_code is NULL for:'
954 || NVL (l_parent_type, p_itemtype)
955 );
956 END IF;
957
958 RAISE fnd_api.g_exc_unexpected_error;
959 END IF;
960
961 mo_global.set_policy_context ('S', l_org_id);
962 END IF;
963
964 p_result := 'COMPLETE';
965 -- Notification Viewer form calls the TEST_CTX just before launching the form
966 -- WF Engine calls TEST_CTX, if this returns FALSE then flow is deferred.
967 ELSIF NVL (l_parent_type, p_itemtype) = 'OEOH'
968 THEN
969 IF g_reset_apps_context
970 THEN
971 SELECT org_id
972 INTO l_org_id
973 FROM oe_order_headers_all
974 WHERE header_id = l_header_id;
975
976 IF l_debug_level > 0
977 THEN
978 oe_debug_pub.ADD ('l_org_id:' || l_org_id);
979 END IF;
980
981 mo_global.set_policy_context ('S', l_org_id);
982 END IF;
983
984 p_result := 'COMPLETE';
985 END IF;
986 ELSIF (p_funcmode = 'TEST_CTX')
987 THEN
988 IF NVL (l_parent_type, p_itemtype) = 'OENH'
989 THEN
990 --initialize global so each tested flow must set explicitly
991 oe_globals.g_flow_restarted := FALSE;
992
993 IF g_upgrade_mode
994 THEN -- During Upgrade Mode we always return TRUE;
995 p_result := 'TRUE';
996 ELSE -- Normal Mode
997 IF g_reset_apps_context
998 THEN
999 -- Setting a global varaible to indicate that the process
1000 -- is being run as a result of the flow being restarted
1001 oe_globals.g_flow_restarted := TRUE;
1002 l_sales_document_type_code :=
1003 wf_engine.getitemattrtext (p_itemtype,
1004 p_itemkey,
1005 'SALES_DOCUMENT_TYPE_CODE'
1006 );
1007
1008 IF l_sales_document_type_code = 'O'
1009 THEN
1010 SELECT org_id
1011 INTO l_org_id
1012 FROM oe_order_headers_all
1013 WHERE header_id = l_header_id;
1014 ELSIF l_sales_document_type_code = 'B'
1015 THEN
1016 SELECT org_id
1017 INTO l_org_id -- AME ER
1018 FROM oe_blanket_headers_all
1019 WHERE header_id = l_header_id;
1020 ELSE
1021 -- Should never get here. In negotiation phase it should be O or B
1022 IF l_debug_level > 0
1023 THEN
1024 oe_debug_pub.ADD
1025 ( 'l_sales_document_type_code is NULL for:'
1026 || p_itemkey
1027 );
1028 END IF;
1029
1030 RAISE fnd_api.g_exc_unexpected_error;
1031 END IF;
1032
1033 IF l_debug_level > 0
1034 THEN
1035 oe_debug_pub.ADD ('ORG ID IS ' || l_org_id);
1036 oe_debug_pub.ADD ( 'mo_global.get_current_org_id is:'
1037 || mo_global.get_current_org_id
1038 );
1039 END IF;
1040
1041 IF NVL (mo_global.get_current_org_id, -99) <> l_org_id
1042 THEN
1043 p_result := 'FALSE';
1044 ELSE
1045 p_result := 'TRUE';
1046 END IF;
1047 ELSE -- G_RESET_APPS_CONTEXT is FALSE
1048 p_result := 'TRUE';
1049 END IF;
1050 END IF; -- End If Upgrade Mode
1051 ELSIF NVL (l_parent_type, p_itemtype) = 'OEOH'
1052 THEN
1053 oe_globals.g_flow_restarted := FALSE;
1054
1055 IF g_upgrade_mode
1056 THEN -- During Upgrade Mode we always return TRUE;
1057 p_result := 'TRUE';
1058 ELSE -- Normal Mode
1059 IF g_reset_apps_context
1060 THEN
1061 -- Setting a global varaible to indicate that the process is being run
1062 -- as a result of the flow being restarted
1063 oe_globals.g_flow_restarted := TRUE;
1064
1065 SELECT org_id
1066 INTO l_org_id
1067 FROM oe_order_headers_all
1068 WHERE header_id = l_header_id;
1069
1070 IF l_debug_level > 0
1071 THEN
1072 oe_debug_pub.ADD ('l_org_id is:' || l_org_id);
1073 oe_debug_pub.ADD ( 'mo_global.get_current_org_id is:'
1074 || mo_global.get_current_org_id
1075 );
1076 END IF;
1077
1078 IF NVL (mo_global.get_current_org_id, -99) <> l_org_id
1079 THEN
1080 p_result := 'FALSE';
1081 ELSE
1082 p_result := 'TRUE';
1083 END IF;
1084 ELSE -- G_RESET_APPS_CONTEXT is FALSE
1085 p_result := 'TRUE';
1086 END IF;
1087 END IF;
1088 END IF;
1089 END IF; -- End if TEST_CTX
1090
1091 --Bug 6884804
1092 IF l_debug_level > 0
1093 THEN
1094 oe_debug_pub.ADD ( ' Exiting OEAME_SELECTOR , RESULT = '
1095 || p_result
1096 || ' ITEMTYPE = '
1097 || p_itemtype
1098 || ' ITEMKEY = '
1099 || p_itemkey,
1100 1
1101 );
1102 END IF;
1103 --End Bug 6884804
1104 EXCEPTION
1105 WHEN OTHERS
1106 THEN
1107 NULL;
1108 wf_core.CONTEXT ('OE_STANDARD_WF',
1109 'OEAME_SELECTOR',
1110 p_itemtype,
1111 p_itemkey,
1112 p_actid,
1113 p_funcmode
1114 );
1115 RAISE;
1116 END oeame_selector;
1117
1118 end OE_STANDARD_WF;