Tuesday 15 May 2012

Create User in Oracle Apps

In a business entity using Oracle Applications as and when new users want to access the system, we need to create individual accounts for the users.

One of the options is to create the user manually from the System Administrator Responsibility, but in most business scenarios the business will have the user details stored in the database which can be picked up by a script , which will subsequently call the API to create multiple users in a single program run.

The generic API provided by Oracle to achieve it is : fnd_user_pkg.createuser , fnd_user_pkg is the Package and create user is the procedure which performs the intended operation.

Given below is a sample anonymous block which can be used to create a user in the system.

DECLARE

  v_session_id INTEGER := userenv('sessionid');
  v_user_name  VARCHAR2(30) := upper('Ashwini');

BEGIN
  --Note, can be executed only when you have apps password.
  -- Call the procedure to Creaet FND User
fnd_user_pkg.createuser(x_user_name                  => v_user_name
                                    ,x_owner                      => 'CUST'
                                    ,x_unencrypted_password       => '123456'
                                    ,x_session_number             => null
                                    ,x_start_date                 => SYSDATE - 10
                                    ,x_end_date                   => null
                                    ,x_last_logon_date            => null
                                    ,x_description                => 'proracleapps.blogspot.com'
                                    ,x_password_date              => null
                                    ,x_password_accesses_left     => null
                                    ,x_password_lifespan_accesses => null
                                    ,x_password_lifespan_days     => null
                                    ,x_employee_id                => null
                                    ,x_email_address => NULL
                                    ,x_fax           => ''
                                    ,x_customer_id   => ''
                                    ,x_supplier_id   => '');
  EXCEPTION
  WHEN OTHERS
  THEN
     dbms_output.put_line('Exception Occurred in Processing ');
     dbms_output.put_line('Oracle Error '||SQLERRM);
END;

The above script create a user with username  'ASHWINI' and password '123456' in the system. In case the username is already in user the API will throw an error.
If no user exists with the username a new user is created with this user name and password.
When the user tries to login with the username he is prompted to change the password and set his new password.

Depending on the business requirements other parameter values can also be passed in.

1 comment: