Monday, February 20, 2017

Script to Add Responsibilities

SET serveroutput ON
DECLARE
  ln_user_id NUMBER;
  ln_resp_id NUMBER;
  ln_app_id  NUMBER;
  CURSOR c1
  IS
    SELECT responsibility_id,
      application_id,
      responsibility_name
    FROM fnd_responsibility_tl
    WHERE responsibility_name   IN ( 'Application Developer', 'Functional Administrator','System Administrator')
    AND responsibility_name NOT IN
      ( SELECT DISTINCT rtl.responsibility_name
      FROM apps.fnd_compiled_menu_functions cmf,
        apps.fnd_form_functions ff,
        apps.fnd_form_functions_tl ffl,
        apps.fnd_responsibility r,
        apps.fnd_responsibility_tl rtl,
        apps.fnd_user_resp_groups urg,
        apps.fnd_user u
      WHERE cmf.function_id     = ff.function_id
      AND r.menu_id             = cmf.menu_id
      AND urg.responsibility_id = r.responsibility_id
      AND rtl.responsibility_id = r.responsibility_id
      AND cmf.grant_flag        = 'Y'
      AND r.application_id      = urg.responsibility_application_id
      AND u.user_id             = urg.user_id
      AND u.user_name           = 'KAARTHIB'
      AND ff.function_id        = ffl.function_id
      );
BEGIN
  SELECT user_id INTO ln_user_id FROM fnd_user WHERE user_name = 'KAARTHIB';
  FOR i IN c1
  LOOP
    fnd_user_resp_groups_api.insert_assignment (ln_user_id, i.responsibility_id, i.application_id, NULL, SYSDATE, NULL, NULL );
  END LOOP;
  COMMIT;
END;
/

No comments: