Thursday, April 11, 2013

Oracle EBS API to create a Phone Number (contacts) in R12 HZ_CONTACT_POINT_V2PUB.CREATE_PHONE_CONTACT_POINT

Oracle EBS API to create a Phone Number (contacts) in R12 HZ_CONTACT_POINT_V2PUB.CREATE_PHONE_CONTACT_POINT

This API is relatively easy to work with.  It is a public API wrapper on   HZ_CONTACT_POINT_V2PUB.CREATE_CONTACT_POINT, which allows you to load phones, emails, websites, edi info, etc.   The API  we are looking at here, HZ_CONTACT_POINT_V2PUB.CREATE_PHONE_CONTACT_POINT, only creates contact phones.

I'll start with a sample script here and then explain the tricky part of working with this API down below:

Sample script for: HZ_CONTACT_POINT_V2PUB.CREATE_PHONE_CONTACT_POINT

DECLARE
    p_contact_point_rec HZ_CONTACT_POINT_V2PUB.CONTACT_POINT_REC_TYPE;
    p_phone_rec         HZ_CONTACT_POINT_V2PUB.PHONE_REC_TYPE;
    x_return_status     VARCHAR2(2000);
    x_msg_count         NUMBER;
    x_msg_data          VARCHAR2(2000);
    x_contact_point_id  NUMBER;

BEGIN
    -- Initialize the environment
  
    /*
        You probably don't need these for this API (my testing didn't require
        them and there is no org_id field in the hz_contact_points table) but
        here they are just in case:
  
        mo_global.init('AR');

        fnd_global.apps_initialize ( user_id      => 1234
                                    ,resp_id      => 50559
                                    ,resp_appl_id => 222);

        mo_global.set_policy_context('S',204);

    */

    -- Mandatory parameters
    p_contact_point_rec.contact_point_type    := 'PHONE';
    p_contact_point_rec.owner_table_name      := 'HZ_PARTIES';
    p_contact_point_rec.owner_table_id        := 1148;
    p_contact_point_rec.primary_flag          := 'Y';
    p_contact_point_rec.contact_point_purpose := 'BUSINESS';
    p_contact_point_rec.created_by_module     := 'BO_API';

    -- Non Mandatory Parameters
    p_phone_rec.phone_area_code               :=  NULL;
    p_phone_rec.phone_country_code            := '1';
    p_phone_rec.phone_number                  := '212-555-1212';
    p_phone_rec.phone_line_type               := 'GEN';
    p_phone_rec.phone_extension               := '';  
  
    /*
        Notes:
      
        1) The 'owner_table_name' can be other tables like hz_party_sites
      
        2) The 'owner_table_id' is the primary key for the record in the table
           you want to assign this contact to.  In this example, this would be
           the party_id of a party in HZ_Parties
    */
  
    DBMS_OUTPUT.PUT_LINE('-----------');
    DBMS_OUTPUT.PUT_LINE('Calling API');

    HZ_CONTACT_POINT_V2PUB.CREATE_PHONE_CONTACT_POINT(
                 p_init_msg_list      => FND_API.G_TRUE,
                 p_contact_point_rec  => p_contact_point_rec,
                 p_phone_rec          => p_phone_rec,
                 x_contact_point_id   => x_contact_point_id,
                 x_return_status      => x_return_status,
                 x_msg_count          => x_msg_count,
                 x_msg_data           => x_msg_data
                 );


    IF x_return_status = fnd_api.g_ret_sts_success
      THEN
        DBMS_OUTPUT.PUT_LINE('Success!');
        DBMS_OUTPUT.PUT_LINE('x_contact_point_id: '||x_contact_point_id);

      ELSE
          
        DBMS_OUTPUT.put_line('Failure...   Msgs: ');
          
        IF x_msg_count = 1
          THEN
            DBMS_OUTPUT.put_line('1) ' || x_msg_data);
                  
         ELSE
                                      
          FOR i IN 1 .. x_msg_count
            LOOP
              x_msg_data := fnd_msg_pub.get( p_msg_index => i, p_encoded => 'F');
              dbms_output.put_line( i|| ') '|| x_msg_data);
            END LOOP;
                                 
        END IF;
                             
    END IF;
  
END;


Now the trick to this is that you have to understand the parameters owner_table_name and owner_table_id.  The owner_table_name is the table which has the data you want to associate with this contact phone.  Typical choices are HZ_Parties or HZ_Party_Sites.  The party_id parameter is the primary ID in that table, so if the owner_table_name = 'HZ_Parties then the owner_table_id is the party_id field in HZ_Parties.  If the owner_table_name = 'HZ_Party_Sites' then the  owner_table_id is the party_site_id field in HZ_Party_Sites.  It's not super-intuitive but that's the way the table that stores contact info (hz_contact_points) works.

Knowing this, hopefully you will be able to use this API easily.

No comments:

Post a Comment

Please add your feedback, experience, or questions!

Popular Posts

Total Pageviews