OracleAppsDNA

API to Create Customer Contacts

To create Customer Contacts we need to use a series of APIs in a sequential manner, in this post I will explain you how to use the APIs to create a Customer Contact.

Below are the steps to create customer contacts

  1. Create a customer contact as a Party of type ‘PERSON
  2. Then establish a relation between the Person Party and the Organization Party (main party, means Customer)
  3. Then create contact at Account level or Site level of the customer
  4. Then create contact point(Phone, email, fax) for the person

Step 1: Creating Contact as a Party of type PERSON

/*************************************************
 *PURPOSE: To create a Party of type PERSON      *
 *AUTHOR: Shailender Thallam                     *
 *************************************************/
SET define off;
SET serveroutput on;

DECLARE                       
   lv_return_status    VARCHAR2 (500);
   lv_msg_count        NUMBER;
   lv_msg_data         VARCHAR2 (500);
   lv_party_id         NUMBER;
   lv_party_number     NUMBER;
   lv_profile_id       NUMBER;
   lv_api_message      VARCHAR2 (4000);
   lv_msg_index_out    NUMBER;
   lv_api_name         VARCHAR2 (150);
   lv_table_name       VARCHAR (150);
   lv_party_c_status   VARCHAR2 (1);
   lv_person_rec       hz_party_v2pub.person_rec_type;
BEGIN
   lv_person_rec.person_first_name := 'TEST-SITE-CON3';
   lv_person_rec.person_last_name := 'TEST3';
   lv_person_rec.party_rec.orig_system := 'USER_ENTERED';
   lv_person_rec.party_rec.orig_system_reference := '12345671'; --<>
   lv_person_rec.party_rec.status := 'A';
   lv_person_rec.created_by_module := 'TCA_V1_API';
   --
   hz_party_v2pub.create_person (p_init_msg_list      => apps.fnd_api.g_false,
                                 p_person_rec         => lv_person_rec,
                                 x_party_id           => lv_party_id,
                                 x_party_number       => lv_party_number,
                                 x_profile_id         => lv_profile_id,
                                 x_return_status      => lv_return_status,
                                 x_msg_count          => lv_msg_count,
                                 x_msg_data           => lv_msg_data
                                );
   
   --
   --Capturing error if not success 
   --	
   IF lv_return_status <> apps.fnd_api.g_ret_sts_success
   THEN
      FOR i IN 1 .. fnd_msg_pub.count_msg
      LOOP
         fnd_msg_pub.get (p_msg_index          => i,
                          p_encoded            => apps.fnd_api.g_false,
                          p_data               => lv_msg_data,
                          p_msg_index_out      => lv_msg_index_out
                         );
         lv_api_message := lv_api_message || ' ~ ' || lv_msg_data;
         DBMS_OUTPUT.put_line ('Error: ' || lv_api_message);
      END LOOP;
   ELSIF (lv_return_status = apps.fnd_api.g_ret_sts_success)
   THEN
      DBMS_OUTPUT.put_line ('***************************');
      DBMS_OUTPUT.put_line ('Output information ....');
      DBMS_OUTPUT.put_line ('Success');
      DBMS_OUTPUT.put_line ('lv_party_id: ' || lv_party_id);
      DBMS_OUTPUT.put_line ('***************************');      
   END IF;
   
   COMMIT;
END;
/

Step 2: Establish a relation between the Person Party and the Customer (main party)

Input Parameters for below Script:

  1. lv_party_id generated from step 1 and customer party_id
/*****************************************************************************
 *PURPOSE: To Establish a relation between the Person Party and the Customer *
 *AUTHOR: Shailender Thallam                                                 *
 *****************************************************************************/
set define off;
set serveroutput on;
DECLARE					

      lv_return_status     VARCHAR2 (500);
      lv_msg_count         NUMBER;
      lv_msg_data          VARCHAR2 (500);
      lv_api_message       VARCHAR2 (4000);
      lv_msg_index_out     NUMBER;
      lv_api_name          VARCHAR2 (150);
      lv_table_name        VARCHAR2 (150);
      lv_oc_c_status       VARCHAR2 (1);
      lv_org_contact_id    NUMBER;
      lv_party_rel_id      NUMBER;
      lv_party_id          NUMBER;
      lv_party_number      VARCHAR2 (150);
      lv_org_contact_rec   hz_party_contact_v2pub.org_contact_rec_type;
   BEGIN
       
      lv_org_contact_rec.party_rel_rec.relationship_code := 'CONTACT_OF';
      lv_org_contact_rec.party_rel_rec.relationship_type := 'CONTACT';
      
      lv_org_contact_rec.party_rel_rec.subject_id := 47903; --<< this is party id of the contact created in Step 1>>
      lv_org_contact_rec.party_rel_rec.subject_type := 'PERSON';
      lv_org_contact_rec.party_rel_rec.subject_table_name := 'HZ_PARTIES';
      lv_org_contact_rec.party_rel_rec.object_type := 'ORGANIZATION';
      lv_org_contact_rec.party_rel_rec.object_id := 47804; --<< this is hz_parties.party_id of the Customer (main organization/party)>>
      lv_org_contact_rec.party_rel_rec.object_table_name := 'HZ_PARTIES';
      lv_org_contact_rec.party_rel_rec.start_date := SYSDATE;
      lv_org_contact_rec.created_by_module := 'TCA_V1_API';
      
      hz_party_contact_v2pub.create_org_contact
                                    (p_init_msg_list        => fnd_api.g_true,
                                     p_org_contact_rec      => lv_org_contact_rec,
                                     x_org_contact_id       => lv_org_contact_id,
                                     x_party_rel_id         => lv_party_rel_id,
                                     x_party_id             => lv_party_id,
                                     x_party_number         => lv_party_number,
                                     x_return_status        => lv_return_status,
                                     x_msg_count            => lv_msg_count,
                                     x_msg_data             => lv_msg_data
                                    );
   --
   --Capturing error if not success 
   --
      IF lv_return_status <> fnd_api.g_ret_sts_success
      THEN
         FOR i IN 1 .. fnd_msg_pub.count_msg
         LOOP
            fnd_msg_pub.get (p_msg_index          => i,
                             p_encoded            => fnd_api.g_false,
                             p_data               => lv_msg_data,
                             p_msg_index_out      => lv_msg_index_out
                            );
            lv_api_message := lv_api_message || ' ~ ' || lv_msg_data;
         END LOOP;
	         dbms_output.put_line('Error: '||lv_api_message);
    ELSIF (lv_return_status = fnd_api.g_ret_sts_success)
      THEN
      DBMS_OUTPUT.put_line ('***************************');
      DBMS_OUTPUT.put_line ('Output information ....');
      DBMS_OUTPUT.put_line ('Success');      
      DBMS_OUTPUT.put_line ('lv_org_contact_id: '||lv_org_contact_id);
      DBMS_OUTPUT.put_line ('lv_party_id: '||lv_party_id);
      DBMS_OUTPUT.put_line ('lv_party_rel_id: '||lv_party_rel_id);
      DBMS_OUTPUT.put_line ('***************************');
    
     END IF;
        COMMIT;
END;
/

Step 3: Create the Contact at Account/Site level of the Customer

Input Parameters for below Script:

  1. lv_party_id generated from step 2
  2. cust_account_id if the contact needs to be assigned at account level
  3. cust_acct_site_id if the contact needs to be assigned at site level
/***********************************************************************
 *PURPOSE: To Create the Contact at Account/Site level of the Customer *
 *AUTHOR: Shailender Thallam                                           *
 ***********************************************************************/
SET define off;
SET serveroutput on;

DECLARE
   p_cr_cust_acc_role_rec   hz_cust_account_role_v2pub.cust_account_role_rec_type;
   lv_api_message           VARCHAR2 (4000);
   lv_msg_index_out         NUMBER;
   x_cust_account_role_id   NUMBER;
   x_return_status          VARCHAR2 (2000);
   x_msg_count              NUMBER;
   x_msg_data               VARCHAR2 (2000);
BEGIN
   -- NOTE:
   -- must be unique CUST_ACCOUNT_ID, CUST_ACCT_SITE_ID, PARTY_ID,ROLE_TYPE
   --
   p_cr_cust_acc_role_rec.party_id := 47904; --<>
   p_cr_cust_acc_role_rec.cust_account_id := 5040; --<>
   p_cr_cust_acc_role_rec.cust_acct_site_id := 2248; --<>
-- p_cr_cust_acc_role_rec.primary_flag := 'Y';
   p_cr_cust_acc_role_rec.role_type := 'CONTACT';
   p_cr_cust_acc_role_rec.created_by_module := 'HZ_CPUI';
   mo_global.init ('AR');
--
   hz_cust_account_role_v2pub.create_cust_account_role
                                                     ('T',
                                                      p_cr_cust_acc_role_rec,
                                                      x_cust_account_role_id,
                                                      x_return_status,
                                                      x_msg_count,
                                                      x_msg_data
                                                     );
   DBMS_OUTPUT.put_line ('***************************');
   DBMS_OUTPUT.put_line ('Output information ....');
   --
   --Capturing error if not success 
   --
   IF x_return_status <> fnd_api.g_ret_sts_success
   THEN
      FOR i IN 1 .. fnd_msg_pub.count_msg
      LOOP
         fnd_msg_pub.get (p_msg_index          => i,
                          p_encoded            => fnd_api.g_false,
                          p_data               => x_msg_data,
                          p_msg_index_out      => lv_msg_index_out
                         );
         lv_api_message := lv_api_message || ' ~ ' || x_msg_data;
      END LOOP;

      DBMS_OUTPUT.put_line ('Error: ' || lv_api_message);
   ELSIF (x_return_status = fnd_api.g_ret_sts_success)
   THEN
      DBMS_OUTPUT.put_line ('Success');
      DBMS_OUTPUT.put_line (   'x_cust_account_role_id: '
                            || x_cust_account_role_id
                           );
   END IF;

   DBMS_OUTPUT.put_line ('***************************');
   COMMIT;
END;
/

Step 4: Create a Contact Point for the contact person

Input Parameters for below Script:

  1. lv_party_id generated from step 2
/************************************************************
 *PURPOSE: To create a Contact Point for the contact person *
 *AUTHOR: Shailender Thallam                                *
 ************************************************************/
SET define off;
SET serveroutput on;

DECLARE
   lv_return_status       VARCHAR2 (500);
   lv_msg_count           NUMBER;
   lv_msg_data            VARCHAR2 (500);
   lv_api_message         VARCHAR2 (4000);
   lv_msg_index_out       NUMBER;
   lv_api_name            VARCHAR2 (150);
   lv_table_name          VARCHAR (150);
   lv_contact_point_id    NUMBER;
   lv_contact_point_rec   hz_contact_point_v2pub.contact_point_rec_type;
   lv_phone_rec           hz_contact_point_v2pub.phone_rec_type;
   lv_email_rec           hz_contact_point_v2pub.email_rec_type;
BEGIN
   lv_contact_point_rec.contact_point_type := 'PHONE';
   lv_contact_point_rec.contact_point_purpose := 'BUSINESS';
   lv_contact_point_rec.created_by_module := 'TCA_V1_API';
   lv_contact_point_rec.status := 'A';
   lv_email_rec.email_format := 'HTML';
   lv_email_rec.email_address := 'shailender@OracleAppsDNA.com';
   lv_phone_rec.phone_area_code := 001;
   lv_phone_rec.phone_number := 567890;
   lv_phone_rec.phone_extension := 1953;
   lv_contact_point_rec.owner_table_name := 'HZ_PARTIES';
   lv_contact_point_rec.owner_table_id := 47904;
               --<< This is the lv_party_id value generated from the Step 2>>
   lv_phone_rec.phone_line_type := 'MOBILE';
   mo_global.init ('AR');
   hz_contact_point_v2pub.create_contact_point
                                (p_init_msg_list          => fnd_api.g_true,
                                 p_contact_point_rec      => lv_contact_point_rec,
                                 p_email_rec              => lv_email_rec,
                                 p_phone_rec              => lv_phone_rec,
                                 x_contact_point_id       => lv_contact_point_id,
                                 x_return_status          => lv_return_status,
                                 x_msg_count              => lv_msg_count,
                                 x_msg_data               => lv_msg_data
                                );

   --
   --Capturing error if not success
   --
   IF lv_return_status <> fnd_api.g_ret_sts_success
   THEN
      FOR i IN 1 .. fnd_msg_pub.count_msg
      LOOP
         fnd_msg_pub.get (p_msg_index          => i,
                          p_encoded            => fnd_api.g_false,
                          p_data               => lv_msg_data,
                          p_msg_index_out      => lv_msg_index_out
                         );
         lv_api_message := lv_api_message || ' ~ ' || lv_msg_data;
         DBMS_OUTPUT.put_line ('Error:' || lv_api_message);
      END LOOP;
   ELSIF (lv_return_status = fnd_api.g_ret_sts_success)
   THEN
      DBMS_OUTPUT.put_line ('***************************');
      DBMS_OUTPUT.put_line ('Output information ....');
      DBMS_OUTPUT.put_line ('Success');
      DBMS_OUTPUT.put_line ('lv_contact_point_id: ' || lv_contact_point_id);
      DBMS_OUTPUT.put_line ('***************************');
   END IF;

   COMMIT;
END;
/
 
Exit mobile version