Search This Blog

Friday, March 22, 2019

User assigned to a responsibility

Below query can be helpful to find users assigned to a specific responsibility

SELECT * FROM (
SELECT   DISTINCT
         user_name
       , DECODE (
            GREATEST (u.start_date
                    , ur.start_date
                    , r.start_date
                    , TO_DATE ('01/01/1000', 'DD/MM/YYYY'))
          , TO_DATE ('01/01/1000', 'DD/MM/YYYY'), ''
          , TO_CHAR (GREATEST (u.start_date, ur.start_date, r.start_date))) resp_start_date
       , DECODE (
            LEAST (NVL (u.end_date, TO_DATE ('01/01/4712', 'DD/MM/YYYY'))
                 , NVL (ur.end_date, TO_DATE ('01/01/4712', 'DD/MM/YYYY'))
                 , NVL (r.end_date, TO_DATE ('01/01/4712', 'DD/MM/YYYY')))
          , TO_DATE ('01/01/4712', 'DD/MM/YYYY'), ''
          , TO_CHAR (
               LEAST (NVL (u.end_date, NVL (ur.end_date, r.end_date))
                    , NVL (ur.end_date, NVL (u.end_date, r.end_date))
                    , NVL (r.end_date, NVL (u.end_date, ur.end_date))))) resp_end_date
       , s.security_group_name
       , u.description
FROM     fnd_user u
       , fnd_user_resp_groups_all ur
       , fnd_responsibility r
       , fnd_security_groups_vl s
       , fnd_responsibility_tl frt
WHERE        1 = 1
         AND frt.responsibility_name = :resp_name
         AND ur.responsibility_application_id = r.application_id
         AND ur.responsibility_id = r.responsibility_id
         AND u.user_id = ur.user_id
         AND ur.security_group_id = s.security_group_id
         AND frt.responsibility_id = r.responsibility_id
         AND frt.language = userenv('lang')
) a
WHERE Nvl(resp_end_date,sysdate + 1) > sysdate         
ORDER BY USER_NAME, SECURITY_GROUP_NAME

Copyright (c) All rights reserved. Presented by Suresh Vaishya