Tuesday 22 March 2016

Create/Update Organization - HRMS APIs

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;

Wednesday 9 March 2016

API to Delete Absence Attendances

API to Delete Absence Attendances


DECLARE
   CURSOR get_absence
   IS
      SELECT absence_attendance_id, object_version_number
        FROM per_absence_attendances
       WHERE TRUNC (creation_date) = TRUNC (SYSDATE);
BEGIN
   FOR fetch_absence IN get_absence
   LOOP
      BEGIN
         hr_person_absence_api.
          delete_person_absence (
            p_validate                => FALSE,
            p_absence_attendance_id   => fetch_absence.absence_attendance_id,
            p_object_version_number   => fetch_absence.object_version_number);
         COMMIT;
         DBMS_OUTPUT.
          put_line (
            fetch_absence.absence_attendance_id
            || ' has been deleted Successfully !!!');
      EXCEPTION
         WHEN OTHERS
         THEN
            DBMS_OUTPUT.
             put_line (
                  'Inner Exception: '
               || fetch_absence.absence_attendance_id
               || ' - - '
               || SQLERRM);
      END;
   END LOOP;
EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.put_line ('Main Exception: ' || SQLERRM);

END;

Cost Allocation Create/Update - HRMS APIs

Cost Allocation Create/Update - HRMS APIs



Cost Allocation Create/Update - HRMS APIs
--
declare
  --
  l_action            varchar2(10) := 'CREATE';--'UPDATE'
  --
  --- DECLARE variables for PAY_COST_ALLOCATION_API
  --- IN variables
  l_assignment_id     number := 123456;
  l_business_group_id number := 101;
  l_proportion  pay_cost_allocations_f.proportion%type := 1;
  l_cost_code   varchar2(20) := '14';
  l_company     varchar2(20) := 'AK';
  l_business    varchar2(20) := 'GRT';
  l_budget_code varchar2(20) := '99999';
  l_account     varchar2(20) := '0000';
  --- OUT variables
  l_combination_name          varchar2(100);
  l_cost_allocation_id        number;
  l_cost_effective_start_date date;
  l_cost_effective_end_date   date;
  l_cost_allocation_keyflex_id pay_cost_allocation_keyflex.cost_allocation_keyflex_id%type;
  l_cost_obj_version_number   number;
  --
begin
   /*
    * This API creates/updates cost allocations.
    * Requires a valid assignment.
  */
      
   if l_action = 'CREATE' then
       --
       l_cost_allocation_id := null;
       --
       pay_cost_allocation_api.create_cost_allocation (p_validate => false
                        ,p_effective_date       => trunc(sysdate)    
                        ,p_assignment_id        => l_assignment_id  
                        ,p_proportion           => l_proportion
                        ,p_business_group_id    => l_business_group_id
                        ,p_segment1             => l_company
                        ,p_segment2             => l_business
                        ,p_segment3             => l_cost_code   
                        ,p_segment4             => l_budget_code
                        ,p_segment5             => l_account
                        -- Out    
                        ,p_combination_name     => l_combination_name
                        ,p_cost_allocation_id   => l_cost_allocation_id 
                        ,p_effective_start_date => l_cost_effective_start_date  
                        ,p_effective_end_date   => l_cost_effective_end_date              
                        ,p_object_version_number => l_cost_obj_version_number 
                        -- In / Out
                        ,p_cost_allocation_keyflex_id => l_cost_allocation_keyflex_id  
                        );
         
       if l_cost_obj_version_number is null then
         dbms_output.put_line('Cost Allocation creation failed '||sqlerrm);
         rollback;
       else
         dbms_output.put_line('Cost Allocation created');
         commit;
       end if;
                                  
   else
        --  
        l_cost_obj_version_number := 3;
        l_cost_allocation_id      := 345612;
        --                      
        pay_cost_allocation_api.update_cost_allocation
                                 ( p_validate                    =>  false
                                 , p_effective_date              =>  trunc(sysdate)
                                 , p_datetrack_update_mode       =>  'UPDATE'
                                 , p_cost_allocation_id          =>  l_cost_allocation_id
                                 , p_proportion                  =>  l_proportion
                                 , p_segment1                    =>  l_company
                                 , p_segment2                    =>  l_business
                                 , p_segment3                    =>  l_cost_code
                                 , p_segment4                    =>  l_budget_code
                                 , p_segment5                    =>  l_account
                                 -- In / Out
                                 , p_cost_allocation_keyflex_id  =>  l_cost_allocation_keyflex_id
                                 , p_object_version_number       =>  l_cost_obj_version_number                               
                                 -- Out
                                 , p_effective_start_date        =>  l_cost_effective_start_date
                                 , p_effective_end_date          =>  l_cost_effective_end_date
                                 , p_combination_name            =>  l_combination_name
                                 );
        
        if l_cost_obj_version_number > 3  then
           dbms_output.put_line('Cost Allocation updated');
           commit;
        else
           dbms_output.put_line('Cost Allocation updation failed '||sqlerrm);
           rollback;
        end if;        
   end if;                                  
--
exception
  when others then
     dbms_output.put_line('pay_cost_allocation_api API failed with error :'||sqlerrm);
     rollback;
end;
--

Tuesday 8 March 2016

How To Restrict Absence Type List of Values in Oracle Self-Service Human Resources


 How To Restrict Absence Type List of Values in Oracle Self-Service Human Resources


Introduction

Oracle Self-Service HR enables users to apply for absences. When applying for an absence, users enter thenabsence date or time, absence type, absence status, and absence reason. The absence types (for example,Vacation, Sick Leave etc.) are defined in Oracle HRMS application. Currently, all the absence types defined in Oracle HRMS application are displayed to the self-service user. The user may not be eligible for all the absence types displayed in the self-service application. This leads to users applying for ineligible absence types. Approvers are forced to verify if the absence type is valid for the employee.

With Release 12.1.3, Oracle Self-Service HR introduces a custom package that enables customers to write the logic for deriving the absence type values based on their business requirements. The absence type list of values can be based on parameters such as: Gender, Business Group, Organization, Responsibility, Grade, and Payroll. Customers can use user hooks within the custom package to derive a restricted list of values for absence type in Absence Management function in Oracle Self-Service Human Resources.

Setup for Restricting Absence Type LOV 

Use the following the sample steps to derive a restricted list of values for absence type LOV in Absence
Management. The custom logic has to be written in the New Package function
HR_ABSENCE_RESTRICTED.ABSENCES_RESTRICTED. Login person id and selected person id
will be passed by default – using these two parameters the rest of the data or parameters can be queried
from the tables.


Package Name
HR_ABSENCE_RESTRICTED
Procedure Name
ABSENCES_RESTRICTED
New Parameters
1) selected_person_id 2) login_person_id



The above procedure will be called from the AbsenceTypeVOImpl java file with the
proper input parameters and the return value will be appended to the AbsenceTypeVO

Sample Code

1. For the purpose of this document, the following example illustrates restricting absence type based
on gender.

1. How to restrict Maternity Absence type to employees of gender ‘Female’ only
--------------------Based on Gender------------
 if to_number(selected_person_id) is not null then
 select sex into l_sex from per_all_people_f where person_id= to_number(selected_person_id)
 and sysdate between effective_start_date and effective_end_date;
 if l_sex <>'F' THEN
 return '36050';
 END IF;
Note: In this example, ‘36050’ is the id of the absence type, which has to restricted

2. How to restrict Absence type based on organization
--------------------Based on Organization------------
if to_number(selected_person_id) is not null then

 select organization_id into l_orgid
 from per_all_assignments_f
 where person_id= to_number(selected_person_id)
 and sysdate between effective_start_date and effective_end_date;
 if l_orgid =7545 then
 return '36046';
 end if;

end if;
Note: In this example, ‘36046’ is the id of the absence type which has to restricted

3. How to return more than one Absence Type
/* Example code logic
 if to_number(selected_person_id) = 36003 then
 return '31044,31045';
 end if;
*/