Friday, 4 July 2014

How To Query Supervisor Chain Of Command For A User

How to query for supervisors hierarchy above an approver user when using employee supervisor chain of command?

Solution
Substitute the username in place of DCROCKETT in the following query.  This is useful when troubleshooting approval
list issues with employee supervisor relationships for requisitions and purchasing documents

/* Formatted on 7/4/2014 11:28:25 AM (QP5 v5.115.810.9015) */
SELECT fndu.user_name, pecx.full_name
FROM fnd_user fndu,
     per_employees_current_x pecx,
     (SELECT pera.supervisor_id             --, fndu.user_name, pecx.full_name
      FROM per_assignments_f pera
      WHERE EXISTS
               (SELECT '1'
                FROM per_people_f perf, per_assignments_f pera1
                WHERE TRUNC (SYSDATE) BETWEEN perf.effective_start_date
                                          AND  perf.effective_end_date
                      AND perf.person_id = pera.supervisor_id
                      AND pera1.person_id = perf.person_id
                      AND TRUNC (SYSDATE) BETWEEN pera1.effective_start_date
                                              AND  pera1.effective_end_date
                      AND pera1.primary_flag = 'Y'
                      AND pera1.assignment_type = 'E'
                      AND EXISTS
                            (SELECT '1'
                             FROM per_person_types ppt
                             WHERE ppt.system_person_type IN ('EMP', 'EMP_APL')
                                   AND ppt.person_type_id = perf.person_type_id))
      START WITH pera.person_id = (SELECT employee_id
                                   FROM fnd_user
                                   WHERE user_name = 'DCROCKETT') -- ** Replace DCROCKETT with your username
                 AND TRUNC (SYSDATE) BETWEEN pera.effective_start_date
                                         AND  pera.effective_end_date
                 AND pera.primary_flag = 'Y'
                 AND pera.assignment_type = 'E'
      CONNECT BY PRIOR pera.supervisor_id = pera.person_id
                 AND TRUNC (SYSDATE) BETWEEN pera.effective_start_date
                                         AND  pera.effective_end_date
                 AND pera.primary_flag = 'Y'
                 AND pera.assignment_type = 'E') c
WHERE fndu.employee_id = c.supervisor_id
      AND pecx.employee_id = c.supervisor_id

No comments:

Post a Comment