Recently I was asked by the customer to create 3custom responsibilities from currently existing one responsibility since they were splitting the single OU instance into 3 OU in R12.1.3
DECLARE
v_rowid VARCHAR2 (500);
v_web_host_name VARCHAR2 (500);
v_web_agent_name VARCHAR2 (500);
v_version VARCHAR2 (10) := '4';
v_responsibility_id NUMBER;
-- some variables
v_resp_name VARCHAR2 (100);
v_application VARCHAR2 (100);
v_resp_key VARCHAR2 (100);
v_menu_name VARCHAR2 (100);
v_data_group VARCHAR2 (100);
v_req_group VARCHAR2 (100);
-- ids and other **** used by the API
v_application_id NUMBER;
v_data_group_id NUMBER;
v_menu_id NUMBER;
v_request_group_id NUMBER;
lb_round2 BOOLEAN := TRUE;
lb_round1 BOOLEAN := TRUE;
new_resp1 VARCHAR2 (100);
BEGIN
FOR x IN (SELECT frt.responsibility_id, frt.application_id,
fr.goup_application_id, fr.responsibility_key,
frt.responsibility_name, fr.data_group_id, fr.menu_id,
fr.request_group_id
FROM fnd_responsibility_tl frt, fnd_responsibility fr
WHERE responsibility_name LIKE 'XXJP%'
AND frt.responsibility_id = fr.responsibility_id
UNION ALL
SELECT frt.responsibility_id, frt.application_id,
fr.responsibility_key, frt.responsibility_name,
fr.data_group_id, fr.menu_id, fr.request_group_id
FROM fnd_responsibility_tl frt, fnd_responsibility fr
WHERE responsibility_name LIKE 'XXJP%'
AND frt.responsibility_id = fr.responsibility_id
UNION ALL
SELECT frt.responsibility_id, frt.application_id,
fr.responsibility_key, frt.responsibility_name,
fr.data_group_id, fr.menu_id, fr.request_group_id
FROM fnd_responsibility_tl frt, fnd_responsibility fr
WHERE responsibility_name LIKE 'XXJP%'
AND frt.responsibility_id = fr.responsibility_id
ORDER BY 1 DESC)
LOOP
new_resp1 := NULL;
BEGIN
SELECT DISTINCT new_resp
INTO new_resp1
FROM xxresp
WHERE old_resp = x.responsibility_name;
-- get responsibility name
IF lb_round2 AND lb_round1
THEN
v_resp_name := 'XXJP_STI ' || new_resp1;
v_resp_key := 'XXJP_STII_' || new_resp1;
-- DBMS_OUTPUT.put_line ('INSIDE STI ' || x.responsibility_name);
IF LENGTH (v_resp_key) > 30
THEN
v_resp_key := SUBSTR (v_resp_key, 1, 30);
END IF;
lb_round2 := FALSE;
lb_round1 := TRUE;
ELSIF lb_round1 AND NOT lb_round2
THEN
v_resp_name := 'XXJP_LATAM ' || new_resp1;
v_resp_key := 'XXJP_LATAM_' || new_resp1;
IF LENGTH (v_resp_key) > 30
THEN
v_resp_key := SUBSTR (v_resp_key, 1, 30);
END IF;
lb_round2 := FALSE;
lb_round1 := FALSE;
ELSE
v_resp_name := 'XXJP US ' || new_resp1;
v_resp_key := 'XXJP_USS_' || new_resp1;
IF LENGTH (v_resp_key) > 30
THEN
v_resp_key := SUBSTR (v_resp_key, 1, 30);
END IF;
lb_round2 := TRUE;
lb_round1 := TRUE;
END IF;
-- get application_id
v_application_id := x.application_id;
-- get data group id
v_data_group_id := x.data_group_id;
-- get the menu_id
v_menu_id := x.menu_id;
v_request_group_id := x.request_group_id;
-- get current responsibility_id
SELECT fnd_responsibility_s.NEXTVAL
INTO v_responsibility_id
FROM DUAL;
BEGIN
-- run API
fnd_responsibility_pkg.insert_row
(-- out params
x_rowid => v_rowid,
-- in params
x_responsibility_id => v_responsibility_id,
x_application_id => v_application_id,
x_web_host_name => v_web_host_name,
x_web_agent_name => v_web_agent_name,
x_data_group_application_id => v_application_id,
x_data_group_id => v_data_group_id,
x_menu_id => v_menu_id,
x_start_date => TO_DATE
('01-JAN-1951'
),
x_end_date => NULL,
x_group_application_id => k.group_application_id,
x_request_group_id => v_request_group_id,
x_version => v_version,
x_responsibility_key => v_resp_key,
x_responsibility_name => v_resp_name,
x_description => '',
x_creation_date => SYSDATE,
x_created_by => -1,
x_last_update_date => SYSDATE,
x_last_updated_by => -1,
x_last_update_login => 0
);
INSERT INTO fnd_resp_functions
(application_id, responsibility_id, action_id,
rule_type, last_update_date, last_updated_by,
last_update_login, creation_date, created_by)
SELECT ff.application_id, v_responsibility_id, ff.action_id,
ff.rule_type, ff.last_update_date, ff.last_updated_by,
ff.last_update_login, ff.creation_date, ff.created_by
FROM fnd_resp_functions ff
WHERE responsibility_id = x.responsibility_id;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ( 'failed to add new resp'
|| x.responsibility_name
);
END;
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ( 'failed in creeating custom responsibility: '|| x.responsibility_name
);
END;
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('failed to create responsibility: ' || SQLERRM);
END;
DECLARE
v_rowid VARCHAR2 (500);
v_web_host_name VARCHAR2 (500);
v_web_agent_name VARCHAR2 (500);
v_version VARCHAR2 (10) := '4';
v_responsibility_id NUMBER;
-- some variables
v_resp_name VARCHAR2 (100);
v_application VARCHAR2 (100);
v_resp_key VARCHAR2 (100);
v_menu_name VARCHAR2 (100);
v_data_group VARCHAR2 (100);
v_req_group VARCHAR2 (100);
-- ids and other **** used by the API
v_application_id NUMBER;
v_data_group_id NUMBER;
v_menu_id NUMBER;
v_request_group_id NUMBER;
lb_round2 BOOLEAN := TRUE;
lb_round1 BOOLEAN := TRUE;
new_resp1 VARCHAR2 (100);
BEGIN
FOR x IN (SELECT frt.responsibility_id, frt.application_id,
fr.goup_application_id, fr.responsibility_key,
frt.responsibility_name, fr.data_group_id, fr.menu_id,
fr.request_group_id
FROM fnd_responsibility_tl frt, fnd_responsibility fr
WHERE responsibility_name LIKE 'XXJP%'
AND frt.responsibility_id = fr.responsibility_id
UNION ALL
SELECT frt.responsibility_id, frt.application_id,
fr.responsibility_key, frt.responsibility_name,
fr.data_group_id, fr.menu_id, fr.request_group_id
FROM fnd_responsibility_tl frt, fnd_responsibility fr
WHERE responsibility_name LIKE 'XXJP%'
AND frt.responsibility_id = fr.responsibility_id
UNION ALL
SELECT frt.responsibility_id, frt.application_id,
fr.responsibility_key, frt.responsibility_name,
fr.data_group_id, fr.menu_id, fr.request_group_id
FROM fnd_responsibility_tl frt, fnd_responsibility fr
WHERE responsibility_name LIKE 'XXJP%'
AND frt.responsibility_id = fr.responsibility_id
ORDER BY 1 DESC)
LOOP
new_resp1 := NULL;
BEGIN
SELECT DISTINCT new_resp
INTO new_resp1
FROM xxresp
WHERE old_resp = x.responsibility_name;
-- get responsibility name
IF lb_round2 AND lb_round1
THEN
v_resp_name := 'XXJP_STI ' || new_resp1;
v_resp_key := 'XXJP_STII_' || new_resp1;
-- DBMS_OUTPUT.put_line ('INSIDE STI ' || x.responsibility_name);
IF LENGTH (v_resp_key) > 30
THEN
v_resp_key := SUBSTR (v_resp_key, 1, 30);
END IF;
lb_round2 := FALSE;
lb_round1 := TRUE;
ELSIF lb_round1 AND NOT lb_round2
THEN
v_resp_name := 'XXJP_LATAM ' || new_resp1;
v_resp_key := 'XXJP_LATAM_' || new_resp1;
IF LENGTH (v_resp_key) > 30
THEN
v_resp_key := SUBSTR (v_resp_key, 1, 30);
END IF;
lb_round2 := FALSE;
lb_round1 := FALSE;
ELSE
v_resp_name := 'XXJP US ' || new_resp1;
v_resp_key := 'XXJP_USS_' || new_resp1;
IF LENGTH (v_resp_key) > 30
THEN
v_resp_key := SUBSTR (v_resp_key, 1, 30);
END IF;
lb_round2 := TRUE;
lb_round1 := TRUE;
END IF;
-- get application_id
v_application_id := x.application_id;
-- get data group id
v_data_group_id := x.data_group_id;
-- get the menu_id
v_menu_id := x.menu_id;
v_request_group_id := x.request_group_id;
-- get current responsibility_id
SELECT fnd_responsibility_s.NEXTVAL
INTO v_responsibility_id
FROM DUAL;
BEGIN
-- run API
fnd_responsibility_pkg.insert_row
(-- out params
x_rowid => v_rowid,
-- in params
x_responsibility_id => v_responsibility_id,
x_application_id => v_application_id,
x_web_host_name => v_web_host_name,
x_web_agent_name => v_web_agent_name,
x_data_group_application_id => v_application_id,
x_data_group_id => v_data_group_id,
x_menu_id => v_menu_id,
x_start_date => TO_DATE
('01-JAN-1951'
),
x_end_date => NULL,
x_group_application_id => k.group_application_id,
x_request_group_id => v_request_group_id,
x_version => v_version,
x_responsibility_key => v_resp_key,
x_responsibility_name => v_resp_name,
x_description => '',
x_creation_date => SYSDATE,
x_created_by => -1,
x_last_update_date => SYSDATE,
x_last_updated_by => -1,
x_last_update_login => 0
);
INSERT INTO fnd_resp_functions
(application_id, responsibility_id, action_id,
rule_type, last_update_date, last_updated_by,
last_update_login, creation_date, created_by)
SELECT ff.application_id, v_responsibility_id, ff.action_id,
ff.rule_type, ff.last_update_date, ff.last_updated_by,
ff.last_update_login, ff.creation_date, ff.created_by
FROM fnd_resp_functions ff
WHERE responsibility_id = x.responsibility_id;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ( 'failed to add new resp'
|| x.responsibility_name
);
END;
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ( 'failed in creeating custom responsibility: '|| x.responsibility_name
);
END;
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('failed to create responsibility: ' || SQLERRM);
END;