Saturday, March 12, 2011

API To Create Users And Assign Responsibilities To Users

Below is the code to create users and adding responsibilities to the users through API

DECLARE
  v_user_name := 'test_user';
  v_session_id := sid;
  /*Pass here sid from Below  query-
  SELECT username
  ,      sid
  ,      serial#
  ,      status
  FROM   v$session
  WHERE  username = 'APPS'; */
BEGIN
  FOR i IN 1..99
    LOOP
      fnd_user_pkg.createuser
        (x_user_name => v_user_name||i
        ,x_owner => ''
        ,x_unencrypted_password => 'welcome9'
        ,x_session_number => v_session_id
        ,x_start_date => SYSDATE - 9
        ,x_end_date => SYSDATE + 99
        ,x_last_logon_date => SYSDATE - 9
        ,x_description => 'API User Creation'
        ,x_password_date => SYSDATE - 99
        ,x_password_accesses_left => 9999
        ,x_password_lifespan_accesses => 9999
        ,x_password_lifespan_days => 9999
        ,x_email_address => 'testuser@gmail.com'
        ,x_fax => ''
        ,x_customer_id => ''
        ,x_supplier_id => '');

      fnd_user_pkg.addresp
        (username => v_user_name||i
        ,resp_app => 'SYSADMIN'
        ,resp_key => 'SYSTEM_ADMINISTRATOR'
        ,security_group => 'STANDARD'
        ,description => 'Auto Assignment'
        ,start_date => SYSDATE - 99
        ,end_date => SYSDATE + 9999);
    END LOOP;
END;

Query to Find Responsibilities for a Given Concurrent Programs

SELECT DISTINCT fcpl.user_concurrent_program_name
,          fcp.concurrent_program_name
,          fapp.application_name
,          frg.request_group_name
,          fnrtl.responsibility_name
FROM fnd_request_groups frg
,          fnd_application_tl fapp
,          fnd_request_group_units frgu
,          fnd_concurrent_programs fcp
,          fnd_concurrent_programs_tl fcpl
,          fnd_responsibility fnr
,          fnd_responsibility_tl fnrtl
WHERE frg.application_id =fapp.application_id
AND   frg.application_id = frgu.application_id
AND   frg.request_group_id = frgu.request_group_id
AND   frg.request_group_id = fnr.request_group_id
AND   frg.application_id = fnr.application_id
AND   fnr.responsibility_id = fnrtl.responsibility_id
AND   frgu.request_unit_id = fcp.concurrent_program_id
AND   frgu.unit_application_id = fcp.application_id
AND   fcp.concurrent_program_id = fcpl.concurrent_program_id
AND   fcpl.user_concurrent_program_name like 'Sales%Order%Ackn%'
AND   fnrtl.language = 'us'
AND   fapp.language = 'us'