Friday, May 6, 2016

Reassign Tasks for end dated rep to new rep

set serveroutput on size 320000

--owner id is the resource_id
/*
select *
from JTF_RS_RESOURCE_DTLS_VL
where resource_name like
*/

declare

l_OBJECT_VER_NUM             JTF_TASKS_V.OBJECT_VERSION_NUMBER%TYPE :=2;
l_TASK_STATUS_ID             JTF_TASKS_V.TASK_STATUS_ID%TYPE := 9;
l_TASK_STATUS_NAME           JTF_TASKS_V.TASK_STATUS%TYPE;
l_TASK_ID                    JTF_TASKS_V.TASK_ID%TYPE :=12341;
l_TASK_NUMBER                JTF_TASKS_V.TASK_NUMBER%TYPE;

l_return_status VARCHAR2(1);
l_msg_count NUMBER;
l_msg_data VARCHAR2(1000);

cursor task_cur is
select t.task_id task_id,
t.object_version_number object_version_number
from jtf_tasks_b t,
hz_party_sites ps,
hz_locations l
where t.open_flag = 'Y'
and t.owner_id != 100002064
and t.address_id = ps.party_site_id
and ps.location_id = l.location_id
and l.country = 'US'
and t.owner_id in (&OLD_ID);

begin

for task_rec in task_cur loop
    jtf_tasks_pub.update_task(
                            p_api_version => 1.0 ,
                            p_init_msg_list => fnd_api.g_true,
                            p_commit => fnd_api.g_false,
                            p_object_version_number => task_rec.object_version_number,
                            p_task_id => task_rec.task_id,
                            p_owner_id => &NEW_ID

,
                            x_return_status => l_return_status,
                            x_msg_count => l_msg_count,
                            x_msg_data => l_msg_data
                            );
end loop;

IF l_return_status <> fnd_api.g_ret_sts_success
  THEN
     IF l_msg_count > 0 THEN
        l_msg_data := NULL;
        FOR i IN 1..l_msg_count
           LOOP
             l_msg_data := l_msg_data ||' '||fnd_msg_pub.get(1, 'F');
           END LOOP;
        fnd_message.set_encoded(l_msg_data);
        dbms_output.put_line(substr(l_msg_data,1.1,200));
     END IF;

     ROLLBACK;
ELSE

     COMMIT;
END IF;
end;
/

No comments: