SET SERVEROUTPUT ON SIZE 1000000;
DECLARE
CURSOR emp_resp_det
IS
SELECT
usr.user_id,
usr.user_name,
papf.employee_number,
papf.full_name,
resp.responsibility_name,
resp.responsibility_id,
resp.application_id,
furg.security_group_id,
furg.start_date,
furg.end_date,
trunc(sysdate) responsibility_end_date
FROM
per_all_people_f papf,
fnd_responsibility_tl resp,
fnd_user usr,
fnd_user_resp_groups_all furg
WHERE
1 = 1
AND trunc(sysdate) BETWEEN trunc(furg.start_date) AND trunc(nvl(furg.end_date,sysdate))
AND furg.responsibility_id = resp.responsibility_id
AND usr.user_id = furg.user_id
AND papf.person_id = usr.employee_id
AND trunc(sysdate) BETWEEN trunc(papf.effective_start_date) AND trunc(papf.effective_end_date)
AND resp.responsibility_name <> 'NUAN Access Request System'
--AND papf.employee_number = 1111111
ORDER BY usr.user_id;
l_flag VARCHAR2(2) := NULL;
l_count NUMBER := 0;
BEGIN
dbms_output.put_line('Script To End Date Responsibilities For Given User');
dbms_output.put_line('--------------------------------------------------------------------------------');
dbms_output.put_line('USER_ID,' || 'USER_NAME,' || 'RESPONSIBILITY_NAME,' || 'L_FLAG');
l_count := 0;
FOR rec_emp_resp_det IN emp_resp_det
LOOP
BEGIN
l_flag := NULL;
fnd_user_resp_groups_api.update_assignment(
user_id => rec_emp_resp_det.user_id,
responsibility_id => rec_emp_resp_det.responsibility_id,
responsibility_application_id => rec_emp_resp_det.application_id,
security_group_id => rec_emp_resp_det.security_group_id,
start_date => rec_emp_resp_det.start_date,
end_date => rec_emp_resp_det.responsibility_end_date,
description => NULL,
update_who_columns => 'Y'
);
l_flag := 'S';
EXCEPTION
WHEN OTHERS
THEN
dbms_output.put_line('Error Updating End date for employee ' || rec_emp_resp_det.employee_number || ': ' || sqlerrm);
l_flag := 'E';
END;
dbms_output.put_line(rec_emp_resp_det.user_id || ',' || rec_emp_resp_det.user_name|| ',' ||rec_emp_resp_det.responsibility_name || ',' || l_flag);
l_count := l_count + 1;
END LOOP;
dbms_output.put_line('--------------------------------------------------------------------------------');
dbms_output.put_line('Total Records Processed = ' ||l_count);
dbms_output.put_line('--------------------------------------------------------------------------------');
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
dbms_output.put_line('Error :' || sqlerrm);
END;
/
DECLARE
CURSOR emp_resp_det
IS
SELECT
usr.user_id,
usr.user_name,
papf.employee_number,
papf.full_name,
resp.responsibility_name,
resp.responsibility_id,
resp.application_id,
furg.security_group_id,
furg.start_date,
furg.end_date,
trunc(sysdate) responsibility_end_date
FROM
per_all_people_f papf,
fnd_responsibility_tl resp,
fnd_user usr,
fnd_user_resp_groups_all furg
WHERE
1 = 1
AND trunc(sysdate) BETWEEN trunc(furg.start_date) AND trunc(nvl(furg.end_date,sysdate))
AND furg.responsibility_id = resp.responsibility_id
AND usr.user_id = furg.user_id
AND papf.person_id = usr.employee_id
AND trunc(sysdate) BETWEEN trunc(papf.effective_start_date) AND trunc(papf.effective_end_date)
AND resp.responsibility_name <> 'NUAN Access Request System'
--AND papf.employee_number = 1111111
ORDER BY usr.user_id;
l_flag VARCHAR2(2) := NULL;
l_count NUMBER := 0;
BEGIN
dbms_output.put_line('Script To End Date Responsibilities For Given User');
dbms_output.put_line('--------------------------------------------------------------------------------');
dbms_output.put_line('USER_ID,' || 'USER_NAME,' || 'RESPONSIBILITY_NAME,' || 'L_FLAG');
l_count := 0;
FOR rec_emp_resp_det IN emp_resp_det
LOOP
BEGIN
l_flag := NULL;
fnd_user_resp_groups_api.update_assignment(
user_id => rec_emp_resp_det.user_id,
responsibility_id => rec_emp_resp_det.responsibility_id,
responsibility_application_id => rec_emp_resp_det.application_id,
security_group_id => rec_emp_resp_det.security_group_id,
start_date => rec_emp_resp_det.start_date,
end_date => rec_emp_resp_det.responsibility_end_date,
description => NULL,
update_who_columns => 'Y'
);
l_flag := 'S';
EXCEPTION
WHEN OTHERS
THEN
dbms_output.put_line('Error Updating End date for employee ' || rec_emp_resp_det.employee_number || ': ' || sqlerrm);
l_flag := 'E';
END;
dbms_output.put_line(rec_emp_resp_det.user_id || ',' || rec_emp_resp_det.user_name|| ',' ||rec_emp_resp_det.responsibility_name || ',' || l_flag);
l_count := l_count + 1;
END LOOP;
dbms_output.put_line('--------------------------------------------------------------------------------');
dbms_output.put_line('Total Records Processed = ' ||l_count);
dbms_output.put_line('--------------------------------------------------------------------------------');
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
dbms_output.put_line('Error :' || sqlerrm);
END;
/
Exercise caution with the blog post from 2023 that provides an API script to end-date responsibilities in Oracle applications. Always verify the code and instructions with official Oracle documentation and consult with relevant experts to ensure accuracy and compatibility with your specific Oracle environment.
ReplyDeleteweb development service