Search This Blog

Saturday, January 26, 2008

API to Create User

The code below is very useful if you want to create a user without logging into application and avoid entering same information again and again. Also if the instances are refresed frequently and the user does not exist in production the script can be very handy.
The script below will prompt for user name and employee name. A commit is required at the end to have affect in the application.

v_session_id INTEGER := userenv('sessionid');
v_user_name VARCHAR2(30) := upper('&User_Name');
v_employee_name per_all_people_f.full_name%TYPE := '&employee_name';
v_employee_id NUMBER;
v_email_address per_all_people_f.email_address%TYPE;
SELECT person_id, email_address
INTO v_employee_id
, v_email_address
FROM per_all_people_f
WHERE upper(full_name) LIKE Upper('%v_employee_name%')
GROUP BY person_id
dbms_output.put_line('Employee '||v_employee_name
||' does not exist');
dbms_output.put_line('Unexpected Error '||SQLERRM);
dbms_output.put_line('while selected person_id');
fnd_user_pkg.createuser(x_user_name => v_user_name
,x_owner => ''
,x_unencrypted_password => 'welcome1'
,x_session_number => v_session_id
,x_start_date => SYSDATE - 10
,x_end_date => SYSDATE + 100
,x_last_logon_date => SYSDATE - 10
,x_description => v_user_name||' Created using API'
,x_password_date => SYSDATE - 10
,x_password_accesses_left => 10000
,x_password_lifespan_accesses => 10000
,x_password_lifespan_days => 10000
,x_employee_id => v_employee_id
,x_email_address => v_email_address
,x_fax => ''
,x_customer_id => ''
,x_supplier_id => '');
fnd_user_pkg.addresp(username => v_user_name
,resp_app => 'SYSADMIN'
,security_group => 'STANDARD'
,description => 'System Administrator'
,start_date => SYSDATE - 10
,end_date => SYSDATE + 1000);
-- Created by Suresh Vaishya


Dave said...

Great Idea - as a developer, I'm never added to a clients Production instance and then I have to wait until I'm reset as a user in a cloned instance...

Couple of notes:
line 4
"v_employee_name per_all_people_f.full_name%full_name := &employee_name;"
should it be:
"v_employee_name per_all_people_f.full_name%TYPE := '&employee_name';"
- Note %TYPE and quotes around employee_name PROMPT.
"WHERE upper(full_name) LIKE '%' || upper(v_emp_name) || '%'"
v_emp_name needs to be: v_employee_name per declaration

Thanks again!

Anonymous said...

Hi Suresh,

Wat r the parameters do we need to pass to the API (PO_ACTIONS.CLOSE_PO) to close the PO from back-end.
Plz give me the details with an example. I am confuse for 'p_return_code'.

Appreciate the help.

Thx N Regs,

M. M. Khan

Suresh Vaishya said...

p_return_code is the out parameter that returns the status of your call to the API.
If p_return_code = 'S' then the call was successful.


Anonymous said...

Hi Suresh,

Can you plz tell me where I am wrong with a clear example.....
close_po is a function which returns a boolean value.

l_return_status Boolean;
l_return_status1 Boolean;
FND_GLOBAL.apps_initialize('111','222','333'); -- ( user_id, Resp_id, Appli_id )
--call the Close API
l_return_status := po_actions.close_po(1205813,-- p_docid
'PO',-- p_doctyp
'STANDARD',-- p_docsubtyp
null,-- p_lineid
null,-- p_shipid
'CLOSE',-- p_action
'TEST',-- p_reason
'PO',-- p_calling_mode
'N',-- p_conc_flag
l_return_status1,-- p_return_code
'Y',-- p_auto_close
SYSDATE,-- p_action_date
null); -- p_origin_doc_id
-- Get any messages returned by the Cancel API
DBMS_OUTPUT.put_line('l_return_status :'||l_return_status);

This is very urgent, Appreciate ur help,

Thx N Regs,

ved said...
This comment has been removed by the author.
ved said...

Hi Suresh,
I am new in Oracle Apps.can you send me important documents of WIP,BOM and email is

Ved Prakash

rajeshbalakrishnan said...

Hi Suresh
You are doing grt work by sharing your knowledge with us.hats off to you.
I have requirement frm my client to create to create new pricebreak for the existing item in pricelist and also needs to update the existing pricebreak data based on the user changes like change in unit price,quantity etc.Could you pls let me know if have any idea on this subject.Also it will be very grateful if you are having readymade code with you for this requirement.

Please let me know if you have any questions.your valuable inputs will be highly appreciated.Thanks once again.



Suresh Vaishya said...

I think you can achieve this using modifiers.

Anonymous said...

Hi Suresh,
Since am new bee to oracle apps ,can you pls elaborate the concept of modifiers and how can i proceed with my requirement using modifiers.

Abdul Bijur V.A. said...

Isn't the sales order import code a part of the standard oracle distribution as examples? If so, this is copyrighted material and should NOT be published without permissions/copyrights.


Unknown said...
This comment has been removed by a blog administrator.

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