Tuesday, September 25, 2012

Assigning responsibility

Assigning a user's responsibilities to another user can be time consuming, here is a useful code:

--Working in R12, not tested in R11
declare
cursor c1 is select fr.APPLICATION_ID, fr.RESPONSIBILITY_ID,
frt.RESPONSIBILITY_NAME, fur.end_date
FROM apps.fnd_user fu
,apps.FND_RESPONSIBILITY fr
,apps. FND_USER_RESP_GROUPS_DIRECT fur
, apps.FND_RESPONSIBILITY_tl frt
where fur.RESPONSIBILITY_ID=fr.RESPONSIBILITY_ID
and fur.USER_ID=fu.USER_ID
and frt.RESPONSIBILITY_ID=fr.RESPONSIBILITY_ID
and frt.LANGUAGE='TR'
and (fu.END_DATE is null or sysdate between fu.start_date and fu.end_date)
and fur.END_DATE is null
and fu.user_name = 'RHOSHANLI'; -- misal kullanýcý

cursor c2 is select fu.USER_id
FROM apps.fnd_user fu
where (fu.END_DATE is null or sysdate between fu.start_date and fu.end_date)
and fu.user_name in ('TESTUSER'); --sorumluluk verilecek kullanici

l_count number;

begin

for r1 in c1 loop

for r2 in c2 loop


select count(*) into l_count
FROM apps.fnd_user fu
,apps.FND_RESPONSIBILITY fr
,apps. FND_USER_RESP_GROUPS_DIRECT fur
, apps.FND_RESPONSIBILITY_tl frt
where fur.RESPONSIBILITY_ID=fr.RESPONSIBILITY_ID
and fur.USER_ID=fu.USER_ID
and frt.RESPONSIBILITY_ID=fr.RESPONSIBILITY_ID
and frt.LANGUAGE='TR'
and (fu.END_DATE is null or sysdate between fu.start_date and fu.end_date)
and fur.END_DATE is null
AND FRT.RESPONSIBILITY_ID=r1.responsibility_id
and fu.user_id = r2.user_id; -- sorumluluk verilecek kullanýcý

if (l_count = 0 ) then

apps.fnd_user_resp_groups_api.Insert_Assignment( user_id =>r2.user_id
,responsibility_id => r1.responsibility_id
,security_group_id => NULL
,responsibility_application_id => r1.application_id
,start_date =>sysdate
,end_date => NULL
,description => r1.responsibility_name);
else

apps.fnd_user_resp_groups_api.Update_Assignment( user_id => r2.user_id
,responsibility_id => r1.responsibility_id
,security_group_id => NULL
,responsibility_application_id => r1.application_id
,start_date =>sysdate
,end_date => r1.end_date
,description => r1.responsibility_name);
end if;

end loop;

end loop;

commit;

end;

No comments:

Post a Comment