Monday, February 24, 2014

How to progrmmatically create FND flex values for a Flex Value Set using FND_FLEX_VAL_API



-- Following is the sample code to programmatically create Flex value for a particular Value set
--API Name: fnd_flex_val_api.create_independent_vset_value
-- Parameters:
--       p_user_id -- FND User_Id
--       p_resp_id -- Responsibility Id
--       p_resp_appl_id -- Responsibility Application Id
--       p_flex_value_set_name -- FND Flex Value Set Name
--       p_flex_value -- FND Flex Value
--       p_flex_value_desc -- FND Flex Value Description

DECLARE
   x_str_value          VARCHAR2 (2000);
   lv_message           VARCHAR2 (2000);
   lv_user_id           NUMBER := &p_user_id;
   lv_resp_id           NUMBER := &p_resp_id;
   lv_resp_appl_id      NUMBER := &p_resp_appl_id;
   lv_flex_vs_name      VARCHAR2 (60) := '&p_flex_value_set_name';
   lv_flex_value        VARCHAR2 (60) := '&p_flex_value';
   lv_flex_value_desc   VARCHAR2 (60) := '&p_flex_value_desc';
BEGIN
   --Initialize required if this block is run from within Oracle database
   fnd_global.apps_initialize (user_id        => lv_user_id,
                               resp_id        => lv_resp_id,
                               resp_appl_id   => lv_resp_appl_id);

   fnd_flex_val_api.create_independent_vset_value (
      p_flex_value_set_name   => lv_flex_vs_name,
      p_flex_value            => lv_flex_value,
      p_description           => lv_flex_value_desc,
      p_enabled_flag          => 'Y',
      x_storage_value         => x_str_value);
   DBMS_OUTPUT.put_line (x_str_value);
EXCEPTION
   WHEN OTHERS
   THEN
      v_message := fnd_flex_val_api.MESSAGE;
      DBMS_OUTPUT.put_line (lv_message);
END;

How to programmatically create HR Job Codes Key Flexfield using HR_JOB_API

-- Following is a sample code to create/populate HR Jobs in Oracle HRMS module
-- API Name: HR_JOB_API.CREATE_JOB
-- Parameters:
--   p_bg_id - Business_Group_Id
--   p_job_code - Job Code populated into Segment1 of Job Key Flexfield
--   p_job_code - Job Title populated into Segment2 of Job Key Flexfield
DECLARE
   op_job_id                  NUMBER;
   op_object_version_number   NUMBER;
   x_job_definition_id        NUMBER;
   op_name                    VARCHAR2 (1000);
   lv_job_group_id            per_job_groups.job_group_id%TYPE;
   lv_business_group_id       NUMBER := &p_bg_id;
   lv_job_code                VARCHAR2 (60) := '&p_job_code';
   lv_job_title               VARCHAR2 (60) := '&p_job_title';
BEGIN
   ---------------------------------------------------
   -->> JOB GROUP ID <<--
   ---------------------------------------------------
   SELECT job_group_id
     INTO lv_job_group_id
     FROM per_job_groups
    WHERE 1=1
      AND displayed_name LIKE 'Setup Business Group'
      AND internal_name = 'HR_81';

   hr_job_api.create_job (
      p_business_group_id          => lv_business_group_id,
      p_date_from                  => '01-JAN-1950',
      p_job_group_id               => lv_job_group_id,
      p_segment1                   => lv_job_code,                  --JOB_CODE
      p_segment2                   => lv_job_title,                --JOB_TITLE
      p_job_id                     => op_job_id,
      p_object_version_number      => op_object_version_number,
      p_job_definition_id          => x_job_definition_id,
      p_job_information_category   => 'US',
      p_name                       => op_name);

   DBMS_OUTPUT.PUT_LINE ('OUTPUT JOB NAME CREATED : ' || op_name);
   DBMS_OUTPUT.PUT_LINE ('OUTPUT JOB ID CREATED : ' || op_job_id);
EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.PUT_LINE ('Error Message Is: ' || SQLERRM);
END;