|
/* |
|
ebs_def_setprof.sql |
|
Contact/blame: John Piwowar |
|
Purpose: Braindead wrapper for setting site and user-level profile options |
|
with fnd_profile.save. |
|
Notes: * Call as part of the declare section of an anon PL/SQL block. |
|
That's my sad attempt at reusability without creating stored procs |
|
* Assumes a great many things, including that you're running as |
|
a user with exec privileges on FND_PROFILE, and that you don't |
|
need fancy error reporting if things go wrong. ;-) |
|
* Only handles site/user-level settings, per protocol El-Ay-Zed-Why |
|
* Still somewhat primitive, could probably use more of API for |
|
success/failure messages, etc. |
|
*/ |
|
|
|
PROCEDURE set_ebs_profile ( |
|
prof_option APPLSYS.FND_PROFILE_OPTIONS.PROFILE_OPTION_NAME%TYPE |
|
, prof_value APPLSYS.FND_PROFILE_OPTION_VALUES.PROFILE_OPTION_VALUE%TYPE |
|
, override BOOLEAN DEFAULT FALSE -- controls behavior when already set |
|
, uname FND_USER.USER_NAME%TYPE DEFAULT NULL -- if no username passed, set at site level |
|
) |
|
IS |
|
uid FND_USER.USER_ID%TYPE := NULL; |
|
prof_level VARCHAR2(8) := 'SITE'; --Current longest val is 'SERVRESP' |
|
set_result BOOLEAN := FALSE; |
|
prev_val_defined BOOLEAN := TRUE; --assume yes until we learn otherwise |
|
prev_val FND_PROFILE_OPTION_VALUES.PROFILE_OPTION_VALUE%TYPE; |
|
BEGIN |
|
IF uname IS NOT NULL THEN |
|
dbms_output.put_line('Target user: ' || uname); |
|
prof_level := 'USER'; |
|
BEGIN --validate username |
|
SELECT user_id |
|
INTO uid |
|
FROM applsys.fnd_user |
|
WHERE user_name = upper(uname); --do as I think, not as I type |
|
EXCEPTION |
|
WHEN NO_DATA_FOUND THEN |
|
dbms_output.put_line('ERROR: No userid found for ' || uname || '.'); |
|
RETURN; --Whoops. Here's your bucket, bail away. |
|
END; --validate username |
|
END IF; |
|
|
|
--check for previously-set value |
|
|
|
fnd_profile.get_specific( name_z => prof_option |
|
, user_id_z => uid |
|
, val_z => prev_val |
|
, defined_z => prev_val_defined |
|
); |
|
IF NOT prev_val_defined THEN |
|
dbms_output.put_line(prof_option || ' not previously defined'); |
|
END IF; --NOT prev_val |
|
|
|
IF prev_val_defined THEN |
|
dbms_output.put_line('Previous value of ' || prof_option || ': ' || |
|
prev_val |
|
); |
|
END IF; --prev_val_defined |
|
|
|
IF (NOT override) AND prev_val_defined THEN --do nothing |
|
dbms_output.put_line('Skipping ' || prof_option || ', OVERRIDE=FALSE'); |
|
ELSIF override AND (prev_val = prof_value) THEN --do nothing |
|
dbms_output.put_line ('Skipping ' || prof_option || ', no change'); |
|
ELSE --try to set new profile |
|
set_result := fnd_profile.save( x_name => prof_option |
|
, x_value => prof_value |
|
, x_level_name => prof_level |
|
, x_level_value => uid |
|
); |
|
IF set_result THEN |
|
dbms_output.put_line( 'SUCCESS: Set ' || prof_option || ' to ' || |
|
prof_value |
|
); |
|
COMMIT; --may want to move outside function for large batch updates |
|
ELSE |
|
dbms_output.put_line( 'FAILED to set ' || prof_option || ' to ' || |
|
prof_value |
|
); |
|
dbms_output.put_line('Check option name and value and try again'); |
|
ROLLBACK; --For safety only; current implementation of |
|
--fnd_profile.save does not attempt a write before |
|
--returning false |
|
END IF; --set_result |
|
END IF; --NOT override AND prev_val_defined |
|
END set_ebs_profile; |