|
原帖由 orapeasant 于 2007-12-25 10:08 发表 ![]()
做得绝一点, 把system administrator的responsiblity分配给自己就完了. 在11.5.8里测试过. 11.5.10里可能还要加个wf的role同步的API, 不是很清楚.
--******************************************************************
--* Assign responsibility to user
--******************************************************************
SET ECHO OFF
SET FEEDBACK OFF
SET SERVEROUTPUT ON SIZE 100000
DECLARE
l_user_name VARCHAR2(100) := 'TEST_USER';
l_user_id NUMBER ;
l_resp_name VARCHAR2(1000);
l_responsibility_name VARCHAR2(1000) := 'System Administrator';
l_resp_id NUMBER;
l_resp_appl_id NUMBER;
l_msg VARCHAR2(1000);
l_excp EXCEPTION;
BEGIN
BEGIN
SELECT user_id INTO l_user_id FROM fnd_user WHERE user_name LIKE l_user_name;
EXCEPTION WHEN OTHERS THEN
l_msg := 'Invalid user name.';
RAISE l_excp;
END ;
FOR c IN (SELECT application_id , responsibility_id,responsibility_name
FROM fnd_responsibility_vl
WHERE upper(responsibility_name) like upper(l_responsibility_name))
LOOP
l_resp_name := c.responsibility_name ;
l_resp_id := c.responsibility_id;
l_resp_appl_id := c.application_id;
BEGIN
FND_USER_RESP_GROUPS_API.Insert_Assignment(
user_id => l_user_id
,responsibility_id => l_resp_id
,responsibility_application_id => l_resp_appl_id
,security_group_id => 0
,start_date => sysdate
,end_date => null
,description => NULL);
EXCEPTION
WHEN OTHERS THEN
IF INSTR(sqlerrm,'unique constraint') > 0 THEN
NULL;
ELSE
RAISE l_excp;
END IF;
END ;
dbms_output.put_line( ''''||l_resp_name||''' added to user '''||l_user_name ||''' successfully.');
END LOOP;
IF l_resp_id IS NULL THEN
dbms_output.put_line( 'No responsibility added to user '||l_user_name ||'.');
ROLLBACK;
ELSE
COMMIT;
END IF;
EXCEPTION
WHEN l_excp THEN
dbms_output.put_line(l_msg);
ROLLBACK;
WHEN OTHERS THEN
dbms_output.put_line('Error:'||SQLCODE||CHR(10)||SQLERRM);
ROLLBACK;
END;
-- TEST Successfully。
Attached doc is from metalink, May it is useful to you.
Subject: How to assign and revoke role/responsibility to a user using standard API?
Doc ID: Note:373369.1 Type: HOWTO
Last Revision Date: 06-MAR-2007 Status: PUBLISHED
In this Document
Goal
Solution
--------------------------------------------------------------------------------
Applies to:
Oracle User Management - Version: 11.5.10.2
Information in this document applies to any platform.
Goal
Q1: How to assign role to a user using APIs?
Q2: How to add a responsibility to a user using APIs?
Q3: How to revoke a responsibility assignment to a user using APIs?
Q4: How to revoke an indirect responsiblity (roles assigned using UMX) assignment to a user using APIs?
Solution
A1: Use the following API wf_local_synch.PropagateUserRole
Example:
Begin
wf_local_synch.PropagateUserRole(
p_user_name => '&USER_NAME',
p_role_name => '&ROLE_KEY');
commit;
end;
A2: Use the following API fnd_user_resp_groups_api.Insert_Assignment
begin
fnd_user_resp_groups_api.Insert_Assignment (
user_id =>&USER_ID ,
responsibility_id => &RESP_ID,
responsibility_application_id =>$APPL_ID ,
start_date => &START_DATE,
end_date => &END_DATE,
description =>'Sample
example' );
commit;
end;
This shall raise an error if the responsibility is assigned to user. But if you need to update responsibility assignment in case of responsibility existence, you can use the following API:
begin
fnd_user_pkg.addresp(
'&User_Name',
'&Responsablity_Application_Short_Name',
'&Responsibility_Key',
'&Security_Group',
'&Description',
'&Start_Date',
'&End_Date' );
commit;
end;
A3: Use the following API fnd_user_pkg.delresp
Example:
Begin
fnd_user_pkg.delresp(
'&User_Name',
'&Responsibility_application_short_name',
'&Responsibility_Key',
'&Security_Group');
commit;
End;
This simply end date the responsibility assignment to a user by the current system date.
A4: Use the following API Wf_local_synch.PropagateUserRole
Begin
Wf_local_synch.PropagateUserRole(
p_user_name => '&USER_NAME',
p_role_name => '&ROLE_KEY',
p_start_date=>'&Start_Date',
p_expiration_date=>'&End_Date');
commit;
End;
You need to end date the parent Role and it shall end date the rest Roles. |
|