DBA Data[Home] [Help]

PACKAGE BODY: APPS.CS_UWQ_DISTRIBUTE_ITEMS

Source


1 PACKAGE BODY CS_UWQ_DISTRIBUTE_ITEMS AS
2 /* $Header: csvsrwdb.pls 120.7 2006/08/22 00:01:43 nveerara noship $ */
3 
4 /*****************************************
5 --  This procdeure is going to be called by UWQ's distribute_function()
6 --  to update owner of Service Request in CS when the WI is assigned
7 --  to an individual owner
8 --  Modification History:
9 --
10 --  Date        Name        Desc
11 --  --------    ----------  --------------------------------------
12 --  05/25/2004  RMANABAT    Fix for bug 3612904. Passed resp_id and
13 --                          rep_appL_id to update_servicerequest() api
14 --                          for security validation.
15 *******************************************/
16 
17   PROCEDURE Distribute_ServiceRequests
18 		(P_RESOURCE_ID		IN NUMBER,
19 		P_LANGUAGE		IN VARCHAR2,
20 		P_SOURCE_LANG		IN VARCHAR2,
21 		P_NUM_OF_ITEMS		IN NUMBER,
22 		P_DIST_BUS_RULES	IN SYSTEM.DIST_BUS_RULES_NST,
23 		P_WS_INPUT_DATA		IN OUT NOCOPY SYSTEM.WR_ITEM_DATA_NST,
24 		X_MSG_COUNT		OUT NOCOPY NUMBER,
25 		X_MSG_DATA		OUT NOCOPY VARCHAR2,
26 		X_RETURN_STATUS		OUT NOCOPY VARCHAR2) IS
27 
28 
29     l_distributed_from varchar2(100);
30     l_distributed_to varchar2(100);
31     l_grp_owner varchar2(100);
32     l_individual_owner varchar2(100);
33 
34     l_notes			CS_SERVICEREQUEST_PVT.notes_table;
35     l_contacts			CS_SERVICEREQUEST_PVT.contacts_table;
36     out_interaction_id		NUMBER;
37     out_wf_process_id		NUMBER;
38     l_return_status		VARCHAR2(1);
39     l_msg_count			NUMBER;
40     l_msg_data			VARCHAR2(2000);
41 
42     l_incident_number		VARCHAR2(64);
43     l_object_version_number	NUMBER;
44     l_incident_owner_id		NUMBER;
45     l_assignee_id		NUMBER;
46     l_resource_type		VARCHAR2(33);
47 
48     CURSOR sel_servereq_csr(l_request_id IN NUMBER) IS
49       SELECT incident_number,
50 	     object_version_number,
51 	     incident_owner_id
52       FROM cs_incidents_all_b
53       WHERE incident_id = l_request_id;
54 
55     CURSOR sel_resource_type_csr IS
56       SELECT 'RS_' || category
57       FROM jtf_rs_resource_extns
58       WHERE RESOURCE_ID = P_RESOURCE_ID;
59 
60     CURSOR sel_wi_owner_csr(l_request_id IN NUMBER) IS
61       SELECT assignee_id
62       FROM ieu_uwqm_items
63       WHERE workitem_obj_code = 'SR'
64 	AND workitem_pk_id = l_request_id;
65 
66     l_msg_index_OUT       NUMBER;
67 
68 
69     BEGIN
70 
71 
72       -- Establish savepoint
73       SAVEPOINT Distribute_SR;
74       --dbms_output.put_line('Starting Distribute SR ');
75 
76       --insert into rm_tmp values(null,null,'start of SR distribute func',rm_tmp_seq.nextval);
77       --commit;
78 
79       -- Loop thru the Business rules per Work Source
80       For i in P_DIST_BUS_RULES.first .. P_DIST_BUS_RULES.last
81       Loop
82 
83         l_distributed_from :=  P_DIST_BUS_RULES(i).DISTRIBUTE_FROM;
84         l_distributed_to :=  P_DIST_BUS_RULES(i).DISTRIBUTE_TO;
85 
86         -- For each Work Source,Get the Details of the Work Item to be distributed and the
87         -- Distribution Rules. Try to Distribute the Work Item.
88         IF (P_DIST_BUS_RULES(i).work_source = 'SR') THEN
89 
90 	  --dbms_output.put_line('Distribute SR, P_DIST_BUS_RULES.work_source=SR ');
91 
92 	  -- Loop thru Work Item Details
93           For j in P_WS_INPUT_DATA.first .. P_WS_INPUT_DATA.last
94           LOOP
95 
96 	    IF (P_WS_INPUT_DATA(j).Work_source= 'SR' AND
97 		l_distributed_from = 'GROUP_OWNED') THEN
98 		-- Commented out since we don't have any special logic regarding
99 		--  distribute_to
100 		-- l_distributed_to = 'INDIVIDUAL_ASSIGNED') THEN
101 
102 		--dbms_output.put_line('Distribute SR, P_WS_INPUT_DATA.work_source=SR ');
103 
104 
105 	      -- Obtain Resource Type of the resource
106 	      OPEN sel_resource_type_csr;
107 	      FETCH sel_resource_type_csr INTO l_resource_type;
108 	      CLOSE sel_resource_type_csr;
109 
110 
111 	      OPEN sel_servereq_csr(P_WS_INPUT_DATA(j).WORKITEM_PK_ID);
112 	      FETCH sel_servereq_csr
113 	      INTO l_incident_number, l_object_version_number,l_incident_owner_id;
114 	      CLOSE sel_servereq_csr;
115 
116 	      --dbms_output.put_line('Distribute SR, Calling Update SR_UWQ ');
117 
118 
119 	      CS_ServiceRequest_PVT.Update_Owner(
120 			p_api_version		=> 2.0,
121 			p_init_msg_list		=> fnd_api.g_false,
122 			p_commit		=> fnd_api.g_false,
123 			p_validation_level	=> fnd_api.g_valid_level_full,
124 			x_return_status		=> l_return_status,
125 			x_msg_count		=> l_msg_count,
126 			x_msg_data		=> l_msg_data,
127 			p_request_id		=> P_WS_INPUT_DATA(j).WORKITEM_PK_ID,
128 			p_object_version_number	=> l_object_version_number,
129 			--p_resp_id		=> NULL,
130 			--p_resp_appl_id	=> P_WS_INPUT_DATA(j).APPLICATION_ID,
131 			p_resp_id		=> fnd_global.resp_id,
132 			p_resp_appl_id		=> fnd_global.resp_appl_id,
133 			p_owner_id		=> P_RESOURCE_ID,
134 			p_owner_group_id	=> P_WS_INPUT_DATA(j).OWNER_ID,
135 			p_resource_type		=> l_resource_type,
136 			p_last_updated_by	=> FND_GLOBAL.USER_ID,
137 			p_last_update_login	=> NULL,
138 			p_last_update_date	=> sysdate,
139 			p_audit_comments	=> NULL,
140 			p_called_by_workflow	=> fnd_api.g_false,
141 			p_workflow_process_id	=> NULL,
142 			p_comments		=> NULL,
143 			p_public_comment_flag	=> fnd_api.g_false,
144 			p_parent_interaction_id	=> NULL,
145 			x_interaction_id	=> out_interaction_id);
146 
147 	      IF (l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
148 
149 		-- An error return status from Update_WorkItem() API
150 		-- is ignored by Update_Owner(), so we have to test that
151 		-- the owner update was successful for the SR and the
152 		-- Work Item.
153 
154 		OPEN sel_servereq_csr(P_WS_INPUT_DATA(j).WORKITEM_PK_ID);
155 		FETCH sel_servereq_csr
156 		INTO l_incident_number, l_object_version_number,l_incident_owner_id;
157 		CLOSE sel_servereq_csr;
158 
159 		OPEN sel_wi_owner_csr(P_WS_INPUT_DATA(j).WORKITEM_PK_ID);
160 		FETCH sel_wi_owner_csr INTO l_assignee_id;
161 		CLOSE sel_wi_owner_csr;
162 
163 		IF (l_incident_owner_id = P_RESOURCE_ID AND
164 		    l_assignee_id = P_RESOURCE_ID) THEN
165 
166 		  P_WS_INPUT_DATA(j).DISTRIBUTED := 'TRUE';
167 		  P_WS_INPUT_DATA(j).ASSIGNEE_ID := P_RESOURCE_ID;
168 		  P_WS_INPUT_DATA(j).ASSIGNEE_TYPE := 'RS_INDIVIDUAL';
169 		  P_WS_INPUT_DATA(j).ITEM_INCLUDED_BY_APP := 'FALSE';
170 
171 		  COMMIT;
172 
173 		ELSE
174 
175 		  ROLLBACK TO Distribute_SR;
176 		  P_WS_INPUT_DATA(j).DISTRIBUTED := 'FALSE';
177 
178 		END IF;
179 
180 	      ELSE
181 
182 		-- Rollback to savepoint
183 		ROLLBACK TO Distribute_SR;
184 
185 		P_WS_INPUT_DATA(j).DISTRIBUTED := 'FALSE';
186 
187 	      END IF;
188 
189 	    END IF;
190 
191 	  END LOOP;
192 
193 	END IF;
194 
195       END LOOP;
196 
197       X_RETURN_STATUS := FND_API.G_RET_STS_SUCCESS;
198 
199   END Distribute_ServiceRequests;
200 
201 
202   PROCEDURE SYNC_SR_TASKS(
203         P_TASKS_DATA    IN              SYSTEM.WR_TASKS_DATA_NST,
204         P_DEF_WR_DATA   IN              SYSTEM.DEF_WR_DATA_NST,
205         X_MSG_COUNT     OUT NOCOPY      NUMBER,
206         X_MSG_DATA      OUT NOCOPY      VARCHAR2,
207         X_RETURN_STATUS OUT NOCOPY      VARCHAR2) AS
208 
209     l_work_item_id      NUMBER;
210     l_msg_count         NUMBER;
211     l_assignee_id       NUMBER := NULL;
212     l_owner_id          NUMBER := NULL;
213     l_orig_grpowner     NUMBER := NULL;
214     l_task_status_id    NUMBER := NULL;
215     l_group_member_id   NUMBER;
216     l_msg_data          VARCHAR2(2000);
217     l_return_status     VARCHAR2(1);
218     l_assignee_type     VARCHAR2(30) := NULL;
219     l_owner_type        VARCHAR2(30) := NULL;
220     l_priority_code     VARCHAR2(30) := 'LOW';
221     l_task_status       VARCHAR2(30);
222     l_wi_flag           VARCHAR2(1);
223     l_due_date          DATE;
224 
225   BEGIN
226 
227     --dbms_output.put_line('In SYNC SR Tasks, BEGIN ');
228     l_return_status := FND_API.G_RET_STS_SUCCESS;
229     --dbms_output.put_line('In SYNC SR Tasks, BEGIN, X_RETURN_STATUS='|| X_RETURN_STATUS );
230 
231     -- Get the Priority Code, WorkItem Status and Due Date
232     FOR i in P_DEF_WR_DATA.FIRST..P_DEF_WR_DATA.LAST
233     LOOP --LP1
234       l_due_date      := p_def_wr_data(i).due_date;
235       l_task_status   := p_def_wr_data(i).work_item_status;
236       l_priority_code := p_def_wr_data(i).priority_code;
237       l_orig_grpowner := p_def_wr_data(i).original_grp_owner;
238     END LOOP; --LP1
239 
240     -- Loop thru Task Details
241     FOR j in P_TASKS_DATA.first.. P_TASKS_DATA.last
242     LOOP --LP2
243       -- Work Items should be synched up only during Create/Update/Delete task
244       -- Assignee Id and type are not considered here
245       --dbms_output.put_line('In SYNC SR Tasks, proc_type ='||p_tasks_data(j).proc_type);
246 
247       IF (p_tasks_data(j).proc_type = 'CREATE_TASK') OR --IF1
248          (p_tasks_data(j).proc_type = 'UPDATE_TASK') OR
249          (p_tasks_data(j).proc_type = 'DELETE_TASK') THEN
250         --dbms_output.put_line('In SYNC SR Tasks, task_id ='||p_tasks_data(j).task_id);
251 
252         IF (p_tasks_data(j).owner_type_code = 'RS_GROUP') THEN --IF2
253            l_owner_id := p_tasks_data(j).owner_id;
254            l_owner_type := p_tasks_data(j).owner_type_code;
255         ELSIF ( (p_tasks_data(j).owner_type_code <> 'RS_GROUP') AND --IF2
256               (p_tasks_data(j).owner_type_code <> 'RS_TEAM') ) THEN
257           l_assignee_id := p_tasks_data(j).owner_id;
258           l_assignee_type := p_tasks_data(j).owner_type_code;
259           -- If the Tasks Owner is an individual,
260 	  -- Select the previous Group Owner
261           -- Check if this Individual is a member of the Previous Group
262           -- Set the UWQ Owner, assignee based on the these validation
263           IF l_orig_grpowner IS NOT NULL THEN
264              l_owner_id   := l_orig_grpowner;
265        	     l_owner_type := 'RS_GROUP';
266           END IF;
267 
268         END IF; --IF2
269 
270         -- Query for work item if it already exists for this Task
271         BEGIN
272           SELECT 'Y'
273           INTO   l_wi_flag
274           FROM   ieu_uwqm_items
275           WHERE  workitem_obj_code = 'TASK'
276           AND    workitem_pk_id = p_tasks_data(j).task_id;
277         EXCEPTION
278           WHEN NO_DATA_FOUND THEN
279             l_wi_flag := 'N';
280         END;
281 
282         IF (l_wi_flag = 'N') THEN --IF3
283           --dbms_output.put_line('Creating Work Item for Task '||p_tasks_data(j).task_number);
284           IEU_WR_PUB.CREATE_WR_ITEM(
285                 p_api_version             => 1.0,
286                 p_init_msg_list           => FND_API.G_TRUE,
287                 p_commit                  => FND_API.G_FALSE,
288                 p_workitem_obj_code       => 'TASK',
289                 p_workitem_pk_id          => p_tasks_data(j).task_id,
290                 p_work_item_number        => p_tasks_data(j).task_number,
291                 p_title                   => p_tasks_data(j).task_name,
292                 p_party_id                => p_tasks_data(j).customer_id,
293                 p_priority_code           => l_priority_code,
294                 p_due_date                => l_due_date,
295                 p_owner_id                => l_owner_id,
296 	        p_owner_type              => l_owner_type,
297                 p_assignee_id             => l_assignee_id,
298                 p_assignee_type           => l_assignee_type,
299                 p_source_object_id        => p_tasks_data(j).source_object_id,
300                 p_source_object_type_code => p_tasks_data(j).source_object_type_code,
301                 p_application_id          => 170,
302                 p_ieu_enum_type_uuid      => 'TASKS',    -- 'IEU_MY_TASKS_OWN',
303                 p_work_item_status        => l_task_status,
304                 p_user_id                 => FND_GLOBAL.USER_ID,
305                 p_login_id                => FND_GLOBAL.LOGIN_ID,
306                 x_work_item_id            => l_work_item_id,
307                 x_msg_count               => l_msg_count,
308                 x_msg_data                => l_msg_data,
309                 x_return_status           => l_return_status);
310 	ELSE --IF3
311           --dbms_output.put_line('Updating Work Item for Task '||p_tasks_data(j).task_number);
312           IEU_WR_PUB.UPDATE_WR_ITEM(
313                 p_api_version             => 1.0,
314                 p_init_msg_list           => FND_API.G_TRUE,
315                 p_commit                  => FND_API.G_FALSE,
316                 p_workitem_obj_code       => 'TASK',
317                 p_workitem_pk_id          => p_tasks_data(j).task_id,
318                 p_title                   => p_tasks_data(j).task_name,
319                 p_party_id                => p_tasks_data(j).customer_id,
320                 p_priority_code           => l_priority_code,
321                 p_due_date                => l_due_date,
322                 p_owner_id                => l_owner_id,
323                 p_owner_type              => l_owner_type,
324                 p_assignee_id             => l_assignee_id,
325                 p_assignee_type           => l_assignee_type,
326                 p_source_object_id        => p_tasks_data(j).source_object_id,
327                 p_source_object_type_code => p_tasks_data(j).source_object_type_code,
328                 p_application_id          => 170,
329                 p_work_item_status        => l_task_status,
330                 p_user_id                 => FND_GLOBAL.USER_ID,
331                 p_login_id                => FND_GLOBAL.LOGIN_ID,
332                 x_msg_count               => l_msg_count,
333                 x_msg_data                => l_msg_data,
334                 x_return_status           => l_return_status);
335           --dbms_output.put_line('Update l_return_status='||l_return_status);
336         END IF; --IF3
337       END IF; --IF1
338     END LOOP; --LP2
339 
340     x_return_status := l_return_status;
341     --dbms_output.put_line('SYNC_SR_TASKS  x_return_status='||x_return_status);
342 
343   END SYNC_SR_TASKS;
344 
345 
346   PROCEDURE SYNC_SR_TASKS(
347         P_PROCESSING_SET_ID IN              NUMBER DEFAULT NULL,
348         X_MSG_COUNT         OUT NOCOPY      NUMBER,
349         X_MSG_DATA          OUT NOCOPY      VARCHAR2,
350         X_RETURN_STATUS     OUT NOCOPY      VARCHAR2) AS
351 
352 
353     l_msg_count NUMBER;
354     l_msg_data VARCHAR2(4000);
355     l_return_status VARCHAR2(1);
356 
357   BEGIN
358 --dbms_output.put_line('In SYNC SR Tasks, BEGIN ');
359 
360         l_return_status := FND_API.G_RET_STS_SUCCESS;
361 --dbms_output.put_line('In SYNC SR Tasks, BEGIN, X_RETURN_STATUS='|| l_RETURN_STATUS );
362 
363 
364         BEGIN
365          UPDATE IEU_UWQM_ITEMS_GTT A
366          SET   A.APPLICATION_ID = 170
367          WHERE A.PROCESSING_SET_ID = P_PROCESSING_SET_ID;
368 --        EXCEPTION
369 --         WHEN others THEN null;
370         END;
371 
372 
373         -- Set the Owner/Assignee in UWQ based on the Owner Type Code
374         -- Required Group Validation can be done here
375 
376           -- If the Tasks Owner is an individual,
377           -- Select the previous Group Owner
378           -- Check if this Individual is a member of the Previous Group
379           -- Set the UWQ Owner, assignee based on the these validation
380 
381           -- IF individual owner is NOT member of group (to be obtained from UWQ
382           -- owner info with owner type ='GROUP') , nullify group owner info in UWQ
383           -- and set assignee to the individual task owner .
387         BEGIN
384           -- Else if individual IS  member of group, just set assignee to the
385           -- individual task owner
386 
388          UPDATE IEU_UWQM_ITEMS_GTT A
389          SET   A.ASSIGNEE_ID = A.OWNER_ID
390              , A.ASSIGNEE_TYPE_ACTUAL = A.OWNER_TYPE_ACTUAL
391          WHERE PROCESSING_SET_ID = P_PROCESSING_SET_ID
392          AND A.OWNER_TYPE_ACTUAL NOT IN ('RS_GROUP', 'RS_TEAM');
393 
394          UPDATE IEU_UWQM_ITEMS_GTT A
395          SET   A.OWNER_ID = ''
396              , A.OWNER_TYPE_ACTUAL = ''
397          WHERE PROCESSING_SET_ID = P_PROCESSING_SET_ID
398          AND A.OWNER_TYPE_ACTUAL NOT IN ('RS_GROUP', 'RS_TEAM')
399          AND NOT EXISTS
400              ( SELECT 1
401                FROM   JTF_RS_GROUP_MEMBERS B
402                     , IEU_UWQM_ITEMS C
403                WHERE B.RESOURCE_ID = A.OWNER_ID
404                AND B.GROUP_ID = C.OWNER_ID
405                AND A.WORKITEM_OBJ_CODE = 'TASK'
406                AND C.WORKITEM_PK_ID = A.WORKITEM_PK_ID
407                AND C.WORKITEM_OBJ_CODE = A.WORKITEM_OBJ_CODE
408                AND C.OWNER_TYPE = 'RS_GROUP'
409                AND C.OWNER_ID IS NOT NULL);
410 
411 --        EXCEPTION
412 --         WHEN others THEN null;
413         END;
414 
415         IEU_WR_PUB.SYNC_WR_ITEMS  (
416               p_api_version  => 1.0,
417               p_init_msg_list => FND_API.G_TRUE,
418               p_commit => FND_API.G_FALSE,
419               p_processing_set_id => P_PROCESSING_SET_ID,
420               p_user_id  => FND_GLOBAL.USER_ID,
421               p_login_id => FND_GLOBAL.LOGIN_ID,
422               x_msg_count => l_msg_count,
423               x_msg_data => l_msg_data,
424               x_return_status => l_return_status);
425 
426 
427         x_return_status := l_return_status;
428 --dbms_output.put_line('In SYNC SR Tasks, end, X_RETURN_STATUS='|| X_RETURN_STATUS );
429 
430 
431   END SYNC_SR_TASKS;
432 
433 
434 
435 
436   PROCEDURE DISTRIBUTE_SRTASKS
437   (P_RESOURCE_ID		IN NUMBER,
438    P_LANGUAGE            	IN VARCHAR2,
439    P_SOURCE_LANG      	IN VARCHAR2,
440    P_NUM_OF_ITEMS     	IN NUMBER,
441    P_DIST_BUS_RULES  	IN SYSTEM.DIST_BUS_RULES_NST,
442    P_WS_INPUT_DATA   	IN OUT NOCOPY SYSTEM.WR_ITEM_DATA_NST,
443    X_MSG_COUNT		OUT NOCOPY NUMBER,
444    X_MSG_DATA		OUT NOCOPY VARCHAR2,
445    X_RETURN_STATUS	OUT NOCOPY VARCHAR2) IS
446 
447      l_distributed_from varchar2(100);
448      l_distributed_to varchar2(100);
449      l_dist_st_based_on_parent_flag varchar2(1);
450 
451      l_grp_owner number;
452      l_group_id   varchar2(1);
453      l_task_distributed_to  number;
454 
455      l_source_object_id number;
456      l_source_object_code varchar2(30);
457      l_distribution_status number;
458 
459      l_msg_count number;
460      l_msg_data varchar2(2000);
461      l_return_status varchar2(1);
462      l_task_assignment_id  number;
463      l_assignment_id       number;
464      l_object_version_number number;
465      l_status_id	NUMBER;
466 
467      CURSOR sel_tasks_csr(p_task_id IN NUMBER) IS
468         SELECT task_id,
469                 object_version_number,
470                 task_priority_id
471         FROM    jtf_tasks_b
472         WHERE   task_id = p_task_id;
473 
474       sel_tasks_rec     sel_tasks_csr%ROWTYPE;
475 
476      CURSOR sel_jtf_category_csr(p_resource_id IN NUMBER) IS
477        SELECT 'RS_' || CATEGORY
478        FROM jtf_rs_resource_extns
479        WHERE RESOURCE_ID = p_resource_id;
480 
481      l_category		VARCHAR2(35);
482 
483   BEGIN
484 
485 --insert into rm_tmp values (null,null,'start of DISTRIBUTE_SRTASKS ',rm_tmp_seq.nextval);
486 --commit;
487 
488     -- initialize to success first
489     x_return_status := 'I';
490 
491     if p_dist_bus_rules.count <= 0 then
492        x_return_status := 'E';
493     end if;
494     if p_ws_input_data.count <= 0 then
495        x_return_status := 'E';
496     end if;
497 
498     -- Loop thru the Business rules per Work Source
499 
500     For i  in P_DIST_BUS_RULES.first.. P_DIST_BUS_RULES.last
501     Loop
502 
503 --insert into rm_tmp values (null,null,'DISTRIBUTE_SRTASKS: Looping P_DIST_BUS_RULES ',rm_tmp_seq.nextval);
504 --commit;
505       --insert into temp_f values('in the first loop');commit;
506 
507       l_distributed_from :=  P_DIST_BUS_RULES(i).DISTRIBUTE_FROM;
508       l_distributed_to :=  P_DIST_BUS_RULES(i).DISTRIBUTE_TO;
509       l_dist_st_based_on_parent_flag := P_DIST_BUS_RULES(i).DIST_ST_BASED_ON_PARENT_FLAG;
510 
511       -- For each Work Source, Get the Details of the Work Item to be distributed and the
512       --   Distribution Rules. Try to Distribute the Work Item.
513 
514       if (P_DIST_BUS_RULES(i).work_source = 'SR_TASKS')
515       then
516 
517         -- Loop thru Work Item Details
518         For j in p_WS_INPUT_DATA .first.. p_WS_INPUT_DATA.last
519         loop
520 
521 --insert into rm_tmp values (null,null,'DISTRIBUTE_SRTASKS: Looping p_WS_INPUT_DATA ',rm_tmp_seq.nextval);
522 --commit;
523           IF (p_WS_INPUT_DATA(j).Work_source = 'SR_TASKS') THEN
524 
525             if (l_distributed_from = 'GROUP_OWNED') THEN
526 	      l_grp_owner := p_WS_INPUT_DATA(j).OWNER_ID;
527 	    else
528 	      l_grp_owner := p_WS_INPUT_DATA(j).ASSIGNEE_ID;
529             end if;
530 
531             l_task_distributed_to := p_resource_id;
532 
533             begin
534               select 'X' into l_group_id
535               from jtf_rs_group_members
536               where resource_id = p_resource_id
537                 and group_id = l_grp_owner
538                 and nvl(delete_flag, 'N') = 'N'
539                 and rownum < 2;
540             exception when no_data_found then
541 	      x_return_status := 'E';
542             end;
543 
544 --insert into rm_tmp values (null,null,'DISTRIBUTE_SRTASKS: After jtf_rs_group_members,x_return_status='||x_return_status,rm_tmp_seq.nextval);
545 --commit;
546             if l_group_id = 'X' then
547 
548               if l_dist_st_based_on_parent_flag = 'Y' then
549 
550               -- Code changes required. This will be required only for 'Association' work
551 	      -- source like SR-TASK. The object code should be selected from
552 	      -- ieu_uwqm_work_sources_b for parent work source
553 
554                 -- if p_ws_input_data(j).source_object_type_code = 'SR'  then
555                 l_source_object_code := p_ws_input_data(j).source_object_type_code;
556                 l_source_object_id := p_ws_input_data(j).source_object_id;
557 
558 --insert into rm_tmp values (null,null,'DISTRIBUTE_SRTASKS: source_object_type_code=SR,l_source_object_id'||l_source_object_id||',l_source_object_code='||l_source_object_code,rm_tmp_seq.nextval);
559 --commit;
560                 begin
561                   select distribution_status_id, status_id
562 		  into l_distribution_status, l_status_id
563                   from ieu_uwqm_items
564                   where workitem_pk_id = l_source_object_id
565                     and workitem_obj_code = l_source_object_code;
566                 exception when no_data_found then
567 		  l_distribution_status := 0;
568                 end;
569                 -- end if;
570 
571               end if;
572 
573 	      -- distribution_status 3 is Distributed, Status id 3 is Close.
574               if ( ((l_distribution_status = 3 OR l_status_id = 3)
575 		     and l_dist_st_based_on_parent_flag = 'Y')
576                   OR (l_dist_st_based_on_parent_flag is null) ) then
577 
578 --insert into rm_tmp values (null,null,'DISTRIBUTE_SRTASKS: l_distribution_status=3',rm_tmp_seq.nextval);
579 --commit;
580 
581             	-- Update the SR Task Owner
582 		-- The update to the SR Task work item will be handled by
583 		-- rule function for the work source.
584 
585 	        OPEN sel_tasks_csr(p_ws_input_data(j).workitem_pk_id);
586 		FETCH sel_tasks_csr INTO sel_tasks_rec;
587 
588 		IF sel_tasks_csr%NOTFOUND THEN
589 		  x_return_status := 'E';
590 		ELSE
591 
592 		  -- obtain the owner_type_code by concatenating 'RS_' and the category
593 		  -- from jtf_rs_resource_extns
594 		  OPEN sel_jtf_category_csr(P_RESOURCE_ID);
595 		  FETCH sel_jtf_category_csr INTO l_category;
596 		  IF (sel_jtf_category_csr%NOTFOUND) THEN
597 		    l_category := 'RS_EMPLOYEE';
598 		  END IF;
599 		  CLOSE sel_jtf_category_csr;
600 
601 
602 		  JTF_TASKS_PVT.UPDATE_TASK(
603                         p_api_version           => 1.0,
604                 	p_commit		=> FND_API.G_TRUE,
605                         p_object_version_number => sel_tasks_rec.object_version_number,
606                         p_task_id               => sel_tasks_rec.task_id,
607 			--p_owner_type_code	=> 'RS_INDIVIDUAL',
608 			p_owner_type_code	=> l_category,
609 			p_owner_id		=> P_RESOURCE_ID,
610                         x_return_status         => l_return_status,
611                         x_msg_count             => l_msg_count,
612                         x_msg_data              => l_msg_data);
613 
614 
615                   x_return_status := l_return_status;
616 		END IF;
617 		CLOSE sel_tasks_csr;
618 
619 
620               end if;	-- if (l_distribution_status = 3 and l_dist_st_based_on_parent_flag = 'Y')
621 
622             end if;	-- if l_group_id = 'X'
623 
624           end if;	-- IF (p_WS_INPUT_DATA(j).Work_source = 'SR_TASKS')
625 
626           If x_return_status = 'S' THEN
627               P_WS_INPUT_DATA(j).DISTRIBUTED := 'TRUE';
628               P_WS_INPUT_DATA(j).ASSIGNEE_ID := p_resource_id;
629               P_WS_INPUT_DATA(j).ASSIGNEE_TYPE := 'RS_INDIVIDUAL';
630               P_WS_INPUT_DATA(j).ITEM_INCLUDED_BY_APP := 'FALSE';
631           Else
632               P_WS_INPUT_DATA(j).DISTRIBUTED := 'FALSE';
633           End if;
634 
635         End loop;	-- For j in p_WS_INPUT_DATA .first.. p_WS_INPUT_DATA.last
636 
637       End if;		-- if (P_DIST_BUS_RULES(i).work_source = 'SR_TASKS')
638 
639     End loop;	-- For i  in P_DIST_BUS_RULES.first.. P_DIST_BUS_RULES.last
640 
641 
642  END DISTRIBUTE_SRTASKS;
643 
644 
645 END CS_UWQ_DISTRIBUTE_ITEMS;