Tuesday, July 22, 2014

Create/Update Organization - HRMS APIs

-----------------------------------
--Create Organization
-----------------------------------
declare
l_validate_mode          BOOLEAN := TRUE;
l_begin_date             DATE    := SYSDATE;
l_end_date               DATE    := hr_general.end_of_time;
l_business_group_id      NUMBER  := 101;
l_orgname                hr_all_organization_units.name%TYPE := 'Test Org';
l_intl_extl              fnd_lookup_values.meaning%TYPE;
l_organization_id        hr_all_organization_units.organization_id%TYPE;
l_object_version_number  hr_all_organization_units.object_version_number%TYPE;
l_duplicate_org_warning  BOOLEAN;
begin
  apps.hr_organization_api.create_organization
  (
     p_validate                    => l_validate_mode
    ,p_effective_date           => l_begin_date --Reference date for validating lookup values
    ,p_business_group_id    => l_business_group_id
    ,p_date_from                => l_begin_date --Date the organization takes effect
    ,p_name                        => l_orgname
    ,p_location_id                => null
    ,p_date_to                     => l_end_date
    ,p_internal_external_flag  => l_intl_extl--'INT' --Internal/External org flag
    ,p_internal_address_line  => null
    ,p_type                           => null  --Org type -- Lookup Type ORG_TYPE
    ,p_comments                   => null
    ,p_attribute_category       => null
    ,p_attribute1                    => null
    ,p_attribute2                    => 'Test Org'
    ,p_attribute3                    => null
    ,p_attribute4                    => null
    ,p_attribute5                    => null
    --Out Variables
    ,p_organization_id                 => l_organization_id
    ,p_object_version_number      => l_object_version_number
    ,p_duplicate_org_warning       => l_duplicate_org_warning
    );

   if l_organization_id is null or l_object_version_number is null then
      dbms_output.put_line('hr_organization_api.update_organization API Error: '||sqlerrm);
      rollback;
   elsif l_duplicate_org_warning then
      dbms_output.put_line('Warning: Duplicate Organization');
      rollback;
   else
      commit;
   end if;  
--
exception
  when others then
     dbms_output.put_line('hr_organization_api.create_organization API failed with error :'||sqlerrm);
     rollback;
end;

-----------------------------------
-----------------------------------
--Update Organization
-----------------------------------

declare
l_validate_mode          BOOLEAN := TRUE;
l_begin_date             DATE    := SYSDATE;
l_end_date               DATE    := hr_general.end_of_time;
l_organization_id        hr_all_organization_units.organization_id%TYPE := 104;
l_orgname                hr_all_organization_units.name%TYPE := 'Test Org';
l_object_version_number  hr_all_organization_units.object_version_number%TYPE;
l_duplicate_org_warning  BOOLEAN;
begin
   --
   hr_organization_api.update_organization
      (
        p_validate                  => l_validate_mode
       ,p_effective_date         => l_begin_date --Reference date for validating lookup values
       ,p_date_from               => l_begin_date --Date the organization takes effect
       ,p_date_to                   => l_end_date
       ,p_organization_id        => l_organization_id
       ,p_name                      => l_orgname
       ,p_attribute_category    => null
       ,p_attribute1                => null
       ,p_attribute2                => 'Test Org'
       --Out Variables
       ,p_object_version_number    => l_object_version_number
       ,p_duplicate_org_warning     => l_duplicate_org_warning
      );

   if l_object_version_number is null then
      dbms_output.put_line('hr_organization_api.update_organization API Error: '||sqlerrm);
      rollback;
   elsif l_duplicate_org_warning then
      dbms_output.put_line('Warning: Duplicate Organization');
      rollback;
   else
      commit;
   end if;
--
exception
  when others then
     dbms_output.put_line('hr_organization_api.update_organization API failed with error :'||sqlerrm);
     rollback;
end;

Find The Date Track Mode - HRMS APIs

Hmmm....it's been a long time since I've posted here. Currently I am working on an HRMS project so I shall try to provide the details of HRMS related APIs and try to cover as many as possible.

I have noticed that below three parameters are common and important for these APIs.
1> Date track mode
   >> I won't explain the date track mode in detail, please refer the script below. I hope I have given the enough description above each mode there.
2> Validate mode
   >> It's better to use the API first in the validate mode with passing this parameter as TRUE and then in process mode by passing this parameter as FALSE.
3> Version number
   >> Make sure you pass the correct version number.

I shall start with Organization Management APIs (Org/position/hierarchy) followed by Personal Administration(PA) (Person/Contacts/Assignment/Termination) and at last the User account one (User/Responsibility). - Please refer posts under HRMS lebels.

-----------------------------------------------------------
-- Determine the date track mode
-----------------------------------------------------------
declare
  lv_assignmnet_id    number;
  lv_effective_date   date;
  -- DT_API Output Variables
  lv_correction       boolean;
  lv_update           boolean;
  lv_update_override  boolean;
  lv_update_change_insert boolean;
  lv_mode             varchar2(50);

begin
    -- determine the datetrack mode
    dt_api.find_dt_upd_modes
        (p_effective_date       => lv_effective_date,
         p_base_table_name   => 'PER_ALL_ASSIGNMENTS_F', --'PER_ALL_PEOPLE_F'
         p_base_key_column   => 'ASSIGNMENT_ID',         --'PERSON_ID'
         p_base_key_value      => lv_assignmnet_id,        --lv_person_id
         --Out Variables
         p_correction               => lv_correction,
         p_update                    => lv_update,
         p_update_override      => lv_update_override,
         p_update_change_insert => lv_update_change_insert
        );
 
    if lv_correction then
      --Correction - Over writes the existing record, no history will be maintained
      lv_mode:='CORRECTION';
    elsif lv_update then
      --Inserts a new record effective as of the effective date parameter and keeps the history
      lv_mode:='UPDATE';
    elsif lv_update_override then
      --Future dated changes - do insert then overrides the future record
      lv_mode:='UPDATE_OVERRIDE';
    elsif lv_update_change_insert then
      --Future dated changes - do insert and keeps the future record
      lv_mode:='UPDATE_CHANGE_INSERT';
    end if;    
    --  
exception
   when others then
      dbms_output.put_line('Error: '||sqlerrm);
end;