Thursday, August 7, 2014

Create/Update/Delete Contact Relationships - HRMS APIs

--
declare
   --
   l_action               varchar2(12) := 'CREATE';--'UPDATE' 'DELETE'
   l_eff_date             date := trunc(sysdate);
   l_date_from            date := trunc(sysdate);
   l_date_to              date := hr_general.end_of_time;
   l_business_group_id    per_business_groups.business_group_id%type := 101;
   l_person_id            per_all_people_f.person_id%type := 12345;
   l_primary_contact_flag varchar2(1) := 'Y';
   l_contact_name         per_all_people_f.last_name%type := 'KUMAR';
   l_contact_sequence     per_contact_relationships.sequence_number%type :=1;
   --
   l_contact_relationship_id      number := 678945;
   l_ctr_object_version_number    number := 1;
   l_per_person_id                number default null;
   l_con_object_version_number    number default null;
   l_con_effective_start_date     date;
   l_con_effective_end_date       date;
   l_con_full_name                varchar2( 300 );
   l_con_comment_id               number default null;
   l_con_name_combination_warning boolean := false;
   l_con_orig_hire_warning        boolean := false;
   --
   l_contact_exp   exception;
   --
begin
   --
   --per_contact_relationships
   --
   if l_action = 'CREATE' then
      --
      l_contact_relationship_id   := null;
      l_ctr_object_version_number := null;
      --
      hr_contact_rel_api.create_contact
                            ( p_validate                => false
                             ,p_start_date              => l_eff_date
                             ,p_date_start              => l_date_from
                             ,p_date_end                => l_date_to
                             ,p_business_group_id       => l_business_group_id
                             ,p_person_id               => l_person_id
                             ,p_contact_type            => 'M'
                             ,p_primary_contact_flag    => l_primary_contact_flag
                             ,p_last_name               => l_contact_name
                             ,p_sequence_number         => l_contact_sequence
                             ,p_cont_attribute_category => null
                             ,p_cont_attribute1         => 'Test Contact'
                              --Out
                             ,p_contact_relationship_id   => l_contact_relationship_id
                             ,p_ctr_object_version_number => l_ctr_object_version_number
                             ,p_per_person_id             => l_per_person_id
                             ,p_per_object_version_number => l_con_object_version_number
                             ,p_per_effective_start_date  => l_con_effective_start_date
                             ,p_per_effective_end_date    => l_con_effective_end_date
                             ,p_full_name                 => l_con_full_name
                             ,p_per_comment_id            => l_con_comment_id
                             ,p_name_combination_warning  => l_con_name_combination_warning
                             ,p_orig_hire_warning         => l_con_orig_hire_warning
                            );
       if l_contact_relationship_id is null then
         dbms_output.put_line('Create Contact Relationship failed '||sqlerrm);
          raise l_contact_exp;
       else
         dbms_output.put_line('Contact Relationship Created');        
       end if;
                                   
     elsif l_action = 'UPDATE' then  
        --                          
        hr_contact_rel_api.update_contact_relationship
                          (p_validate                          => false
                          ,p_effective_date                    => l_eff_date
                          ,p_contact_relationship_id           => l_contact_relationship_id
                          ,p_sequence_number                   => l_contact_sequence
                          ,p_primary_contact_flag              => 'N'
                          ,p_cont_attribute_category           => null
                          ,p_cont_attribute1                   => 'Test Contact2'
                           --In/Out
                          ,p_object_version_number             => l_ctr_object_version_number
                          );
        dbms_output.put_line('Contact Relationship Updated');
     elsif l_action = 'DELETE' then    
        --                    
        hr_contact_rel_api.delete_contact_relationship
                          (p_validate                          => false
                          ,p_contact_relationship_id           => l_contact_relationship_id
                          ,p_object_version_number             => l_ctr_object_version_number
                          );
        dbms_output.put_line('Contact Relationship Deleted');
     end if;                        
--
commit;
--
exception
  when l_contact_exp then
     dbms_output.put_line('Create Contact Relationship failed '||sqlerrm);
     rollback;
  when others then
     dbms_output.put_line('hr_organization_api.create_organization API failed with error :'||sqlerrm);
     rollback;
end;                          
--

7 comments:

  1. Unquestionably believe that which you said. Your favorite reason appeared to be on the internet the easiest thing to be
    aware of. I say to you, I certainly get irked while people
    consider worries that they plainly do not know about. You managed to hit the nail upon the top as well as defined
    out the whole thing without having side effect , people can take a signal.
    Will probably be back to get more. Thanks

    For an incredible response please check out this page ::  Hcg weight
    loss - Createtank.org,

    ReplyDelete
  2. i need to insert additional information, how can i do that with api ??
    thanks

    ReplyDelete
    Replies
    1. Dear Unknown,

      Additional informations are DFFs, use the hr_person_api.update_person and pass the related attribute category and attributs.

      Delete
  3. Hi Abhay,

    I am trying to delete the customer contacts. But unfortunately the api ending with exception.

    ORA-20001: The primary key specified is invalid

    Cause: The primary key values specified are invalid and do not exist in the schema.

    Action: Check the primary key values before attempting to carry out the operation again.

    Can you please help on this issue.

    Regards,
    Devendra Pennam.

    ReplyDelete
    Replies
    1. Hi Devendra,

      Please make sure you are passing the correct contact relationship id and corresponding object version number.

      Regards
      Abhay

      Delete
  4. Hi,

    How i can add another relationship in same contact like the contact is Father and Friend?

    ReplyDelete
  5. HOW TO UPDATE NAMES OF CONTACT ?

    ReplyDelete