Thursday, July 31, 2014

Update/Delete Person - HRMS APIs

--
/*This update API updates person information in a United Kingdom business group.
  The person must exist in the relevant business group on the effective date.
*/
--
declare
--
   l_mode                     varchar2(10) := 'UPDATE'; --'DELETE'
   l_validate                 boolean      :=  false;
   l_date_track_mode          varchar2(30) := 'CORRECTION';
 
   --- DECLARE variables for HR_PERSON_API.update_gb_person
   --- IN variables
   l_person_id                per_all_people_f.person_id%type       := 123456;
   l_employee_number_upd      per_all_people_f.employee_number%type := '567891';
   l_npw_number_upd           per_all_people_f.npw_number%type default null;
   l_object_version_number    per_all_people_f.object_version_number%type :=1;
   --- OUT variables
   l_effective_start_date     date;
   l_effective_end_date       date;
   l_full_name                varchar2(300);
   l_comment_id               number;
   l_name_combination_warning boolean;
   l_assign_payroll_warning   boolean;
   l_orig_hire_warning        boolean;
   --out variable for delete_person
   l_person_org_manager_warning varchar2(100);
--
begin
  --
   if l_mode = 'UPDATE' then
       --
       hr_person_api.update_gb_person (
                         p_validate              => l_validate             --in    boolean   default false
                        ,p_effective_date        => trunc(sysdate)         --in    date
                        ,p_datetrack_update_mode => l_date_track_mode      --in    varchar2
                        ,p_person_id             => l_person_id            --in    number
                         --In/Out
                        ,p_object_version_number => l_object_version_number
                        ,p_employee_number       => l_employee_number_upd
                        ,p_npw_number            => l_npw_number_upd      
                         --Out
                        ,p_effective_start_date  => l_effective_start_date
                        ,p_effective_end_date    => l_effective_end_date
                        ,p_full_name             => l_full_name
                        ,p_comment_id            => l_comment_id
                        ,p_name_combination_warning => l_name_combination_warning
                        ,p_assign_payroll_warning   => l_assign_payroll_warning
                        ,p_orig_hire_warning        => l_orig_hire_warning
                        );
        --                  
        if (l_name_combination_warning = true
            or l_assign_payroll_warning = true
             or l_orig_hire_warning = true)
        then
            dbms_output.put_line('Warning validating API: hr_person_api.update_gb_person');
            rollback;
        else
            dbms_output.put_line('Person Updated');
            commit;
        end if;
  --
  elsif l_mode = 'DELETE' then
         --
         hr_person_api.delete_person(
                           p_validate        => l_validate
                          ,p_effective_date  => trunc(sysdate)
                          ,p_person_id       => l_person_id
                          ,p_perform_predel_validation  => false
                          ,p_person_org_manager_warning => l_person_org_manager_warning
                          );
        --                
        if l_person_org_manager_warning is not null then
            dbms_output.put_line('Warning validating API: hr_person_api.delete_person '||l_person_org_manager_warning||' : '||sqlerrm);
            rollback;
        else
            dbms_output.put_line('Person Deleted');
            commit;
        end if;
        --
  end if;
  --
exception
  when others then
     dbms_output.put_line('Error: '||sqlerrm);
     rollback;
end;

2 comments:

  1. unable to delete person record. Getting below error

    ORA-20001: You cannot delete application users

    Is there any API which can be used to delete record using datetrack mode (I need to delete only future dated records.)

    Thanks!

    ReplyDelete
  2. Looking at the error message it looks like this employee is linked to an application user, delink from the user account and retry please.

    ReplyDelete