Thursday, October 6, 2011

Script to assign a specific Responsibility to a User

SET SERVEROUTPUT ON;
DECLARE
   l_resp_name    VARCHAR2 (100) := '&enter_resp_name';
   l_appl_id      NUMBER;
   l_resp_id      NUMBER;
   l_user_name    VARCHAR2 (100) := '&enter_user_name';
   l_user_id      NUMBER;
   l_sec_grp_id   NUMBER;
   l_start_date   VARCHAR2 (11);
   l_desc         VARCHAR2 (255);
   l_count        NUMBER DEFAULT 0;
BEGIN
   BEGIN
      SELECT application_id, responsibility_id
        INTO l_appl_id, l_resp_id
        FROM fnd_responsibility_vl
       WHERE responsibility_name = l_resp_name;
   EXCEPTION
      WHEN OTHERS
      THEN
         RAISE;
   END;
   DBMS_OUTPUT.put_line ('l_appl_id= ' || l_appl_id);
   DBMS_OUTPUT.put_line ('l_resp_id= ' || l_resp_id);
   BEGIN
      SELECT user_id
        INTO l_user_id
        FROM fnd_user
       WHERE user_name = l_user_name;
   EXCEPTION
      WHEN OTHERS
      THEN
         RAISE;
   END;
   DBMS_OUTPUT.put_line ('l_user_id= ' || l_user_id);
   BEGIN
      SELECT COUNT (security_group_id)
        INTO l_count
        FROM fnd_user_resp_groups
       WHERE user_id = l_user_id AND responsibility_id = l_resp_id;
      DBMS_OUTPUT.put_line ('l_count= ' || l_count);
      IF l_count = 0
      THEN
         SELECT security_group_id, start_date, end_date
           INTO l_sec_grp_id, l_start_date, l_desc
           FROM fnd_user_resp_groups
          WHERE     user_id IS NOT NULL
                AND responsibility_id = l_resp_id
                AND ROWNUM = 1;
      ELSE
         SELECT security_group_id, start_date, end_date
           INTO l_sec_grp_id, l_start_date, l_desc
           FROM fnd_user_resp_groups
          WHERE user_id = l_user_id AND responsibility_id = l_resp_id;
      END IF;
      DBMS_OUTPUT.put_line ('l_sec_grp_id= ' || l_sec_grp_id);
      DBMS_OUTPUT.put_line ('l_start_date= ' || l_start_date);
   EXCEPTION
      WHEN OTHERS
      THEN
         RAISE;
   END;
   fnd_user_resp_groups_api.upload_assignment (
      user_id                         => l_user_id,               --in number,
      responsibility_id               => l_resp_id,               --in number,
      responsibility_application_id   => l_appl_id,               --in number,
      security_group_id               => l_sec_grp_id, --in number default null,
      start_date                      => TO_DATE (l_start_date, 'DD-MON-RRRR'), -- in date,
      end_date                        => NULL,                      --in date,
      description                     => NVL (l_desc, l_resp_name), --in varchar2,
      update_who_columns              => 'N'        --in varchar2 default null
                                            /* 'n' = leave old who vals.  'y' (default) = update who to current*/
      );
   DBMS_OUTPUT.put_line ('Successfully updated ');
   COMMIT;
EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.put_line ('Exception ' || SUBSTR (SQLERRM, 1, 300));
END;

4 comments:

  1. Good one and usefull...can we update who column as well using the same... Presently it is showing ANONYMOUS

    ReplyDelete
    Replies
    1. Oracle Ebs Pro(For Oracle Ebs Professionals): Script To Assign A Specific Responsibility To A User >>>>> Download Now

      >>>>> Download Full

      Oracle Ebs Pro(For Oracle Ebs Professionals): Script To Assign A Specific Responsibility To A User >>>>> Download LINK

      >>>>> Download Now

      Oracle Ebs Pro(For Oracle Ebs Professionals): Script To Assign A Specific Responsibility To A User >>>>> Download Full

      >>>>> Download LINK ZZ

      Delete
  2. Thanks and Regards. Oracle Apps R12 Training Videos at affordable cost. please check oracleappstechnical.com

    ReplyDelete
  3. Oracle Ebs Pro(For Oracle Ebs Professionals): Script To Assign A Specific Responsibility To A User >>>>> Download Now

    >>>>> Download Full

    Oracle Ebs Pro(For Oracle Ebs Professionals): Script To Assign A Specific Responsibility To A User >>>>> Download LINK

    >>>>> Download Now

    Oracle Ebs Pro(For Oracle Ebs Professionals): Script To Assign A Specific Responsibility To A User >>>>> Download Full

    >>>>> Download LINK eT

    ReplyDelete