Monday, 22 December 2025

Script to set profile value at Different Levels in Oracle EBS R12

/*Changing Profile Options from Backend in Oracle APPS R12*/ 


/*Set profile value at SITE Level*/
DECLARE
  v_check        BOOLEAN;
  v_profile_name VARCHAR2(240) := 'HZ: Generate Party Number';
  v_profile      VARCHAR2(240);
  v_value        VARCHAR2(1) := 'Y';
BEGIN
  SELECT profile_option_name
  INTO   v_profile
  FROM   fnd_profile_options_tl
  WHERE  LANGUAGE = 'US'
  AND    user_profile_option_name = v_profile_name ;
  
  v_check := fnd_profile.save( x_name => v_profile ,
                              x_value => v_value ,
                              x_level_name => 'SITE' ,
                              x_level_value => NULL ,
                              x_level_value_app_id => NULL) ;
  IF v_check THEN
    dbms_output.Put_line('Profile '||v_profile_name||' updated with '||v_value);
    COMMIT;
  ELSE
    dbms_output.Put_line('Error while updating Profile '||v_profile_name||' with value '||v_value);
  END IF;
EXCEPTION
WHEN OTHERS THEN
  dbms_output.Put_line('Error: '||SQLERRM);
END;


/*Set profile value at Application Level*/
DECLARE
  v_check        BOOLEAN;
  v_profile_name VARCHAR2(240) := 'HZ: Generate Party Number';
  v_profile      VARCHAR2(240);
  v_value        VARCHAR2(1) := 'Y';
  v_appl_name    VARCHAR2(4) := 'AR';
  v_appl_id      NUMBER;
BEGIN
  SELECT profile_option_name
  INTO   v_profile
  FROM   fnd_profile_options_tl
  WHERE  LANGUAGE = 'US'
  AND    user_profile_option_name = v_profile_name ;
  
  SELECT application_id
  INTO   v_appl_id
  FROM   fnd_application
  WHERE  application_short_name = 'AR';

  v_check := fnd_profile.save( x_name => v_profile ,
                              x_value => v_value ,
                              x_level_name => 'APPL' ,
                              x_level_value => v_appl_id ,
                              x_level_value_app_id => NULL) ;
  IF v_check THEN
    dbms_output.put_line('Profile '||v_profile_name||' updated with '||v_value);
    COMMIT;
  ELSE
    dbms_output.put_line('Error while updating Profile '||v_profile_name||' with value '||v_value);
  END IF;
EXCEPTION
WHEN OTHERS THEN
  dbms_output.put_line('Error: '||SQLERRM);
END;


/*Set profile value at Responsibility Level*/
DECLARE
  v_check        BOOLEAN;
  v_profile_name VARCHAR2(240) := 'HZ: Generate Party Number';
  v_profile      VARCHAR2(240);
  v_value        VARCHAR2(1) := 'Y';
  v_resp_name    VARCHAR2(240) := 'Purchasing Super User';
  v_resp_id      NUMBER;
  v_resp_app_id  NUMBER;
BEGIN
  SELECT profile_option_name
  INTO   v_profile
  FROM   fnd_profile_options_tl
  WHERE  LANGUAGE = 'US'
  AND    user_profile_option_name = v_profile_name ;
  
  SELECT responsibility_id ,
         application_id
  INTO   v_resp_id ,
         v_resp_app_id
  FROM   fnd_responsibility_tl
  WHERE  responsibility_name = v_resp_name ;
  
  v_check := fnd_profile.save( x_name => v_profile ,
                              x_value => v_value ,
                              x_level_name => 'RESP' ,
                              x_level_value => v_resp_id ,
                              x_level_value_app_id => v_resp_app_id) ;
  IF v_check THEN
    dbms_output.put_line('Profile '||v_profile_name||' updated with '||v_value);
    COMMIT;
  ELSE
    dbms_output.put_line('Error while updating Profile '||v_profile_name||' with value '||v_value);
  END IF;
EXCEPTION
WHEN OTHERS THEN
  dbms_output.put_line('Error: '||SQLERRM);
END;


/*Set profile value at User Level*/
DECLARE
  v_check        BOOLEAN;
  v_profile_name VARCHAR2(240) := 'OM: Debug Level';
  v_profile      VARCHAR2(240);
  v_value        VARCHAR2(1) := '5';
  v_user_name    VARCHAR2(240) := 'USER123';
  v_user_id      NUMBER;
BEGIN
  SELECT profile_option_name
  INTO   v_profile
  FROM   fnd_profile_options_tl
  WHERE  LANGUAGE = 'US'
  AND    user_profile_option_name = v_profile_name ;
  
  SELECT user_id
  INTO   v_user_id
  FROM   fnd_user
  WHERE  user_name = v_user_name ;
  
  v_check := fnd_profile.save( x_name => v_profile ,
                              x_value => v_value ,
                              x_level_name => 'USER' ,
                              x_level_value => v_user_id ,
                              x_level_value_app_id => NULL) ;
  IF v_check THEN
    dbms_output.put_line('Profile '||v_profile_name||' updated with '||v_value);
    COMMIT;
  ELSE
    dbms_output.put_line('Error while updating Profile '||v_profile_name||' with value '||v_value);
  END IF;
EXCEPTION
WHEN OTHERS THEN
  dbms_output.put_line('Error: '||SQLERRM);
END;

No comments:

Post a Comment