Friday, September 14, 2012

Create Person using the TCA API - HZ_PARTY_V2PUB

Running the Create Person API
Name of the API: CREATE PERSON API
Base Tables Affected: HZ_PARTIES
HZ_PERSON_PROFILES
PL/SQL Procedure used: CREATE_PERSON
Package Used: HZ_PARTY_V2PUB
HZ_CUST_ACCOUNT_V2PUB
Mandatory Parameters:
p_init_msg_list IN VARCHAR2:= FND_API.G_FALSE
p_person_rec IN PERSON_REC_TYPE
x_party_id OUT NUMBER,
x_party_number OUT VARCHAR2
x_prof i l e_i d OUT NUMBER
x_return_status OUT VARCHAR2
x_msg_count OUT NUMBER
x_msg_data OUT VARCHAR2

PROCEDURE create_person (
p_init_msg_list IN VARCHAR2:= FND_API.G_FALSE,
p_person_rec IN PERSON_REC_TYPE,
x_party_id OUT NUMBER,
x_party_number OUT VARCHAR2,
x_prof i l e_i d OUT NUMBER,
x_return_status OUT VARCHAR2,
x_msg_count OUT NUMBER,
x_msg_data OUT VARCHAR2
)

General Tips for Running the Create Person API
a) Save the API in a script file and then run the script from the SQL Prompt (Example: RUN createperson.txt)
b) Enter the values for the Parameters from inside the script file itself unless it is required to enter some value from the SQL Prompt.
c) Set the organization id before running the script as: EXEC fnd_client_info.set_org_context ('<orgid>');
d) Ensure that the Profile Option HZ: Generate Party Number is set to ‘Yes’ at Site Level.

Code for Create Person API
DECLARE
   p_cust_account_rec       HZ_CUST_ACCOUNT_V2PUB.CUST_ACCOUNT_REC_TYPE;
   p_person_rec             HZ_PARTY_V2PUB.PERSON_REC_TYPE;
   p_customer_profile_rec   HZ_CUSTOMER_PROFILE_V2PUB.CUSTOMER_PROFILE_REC_TYPE;
   x_cust_account_id        NUMBER;
   x_account_number         VARCHAR2 (2000);
   x_party_id               NUMBER;
   x_party_number           VARCHAR2 (2000);
   x_profile_id             NUMBER;
   x_return_status          VARCHAR2 (2000);
   x_msg_count              NUMBER;
   x_msg_data               VARCHAR2 (2000);
BEGIN
   Fnd_client_info.set_org_context ('&Org_Id');
   p_cust_account_rec.account_name := '&Customer_Name';
   p_cust_account_rec.created_by_module := 'TCA_EXAMPLE';
   p_person_rec.person_first_name := '&First_Name';
   p_person_rec.person_last_name := '&Last_Name';
   hz_cust_account_v2pub.create_cust_account ('T',
                                              p_cust_account_rec,
                                              p_person_rec,
                                              p_customer_profile_rec,
                                              'F',
                                              x_cust_account_id,
                                              x_account_number,
                                              x_party_id,
                                              x_party_number,
                                              x_profile_id,
                                              x_return_status,
                                              x_msg_count,
                                              x_msg_data);
   DBMS_OUTPUT.put_line (
      'x_return_status = ' || SUBSTR (x_return_status, 1, 255));
   DBMS_OUTPUT.put_line ('x_msg_count = ' || TO_CHAR (x_msg_count));
   DBMS_OUTPUT.put_line ('Party Id = ' || TO_CHAR (x_party_id));
   DBMS_OUTPUT.put_line ('Party Number = ' || x_party_number);
   DBMS_OUTPUT.put_line ('Profile Id = ' || TO_CHAR (x_profile_id));
   DBMS_OUTPUT.put_line ('x_msg_data = ' || SUBSTR (x_msg_data, 1, 255));

   IF x_msg_count > 1
   THEN
      FOR I IN 1 .. x_msg_count
      LOOP
         DBMS_OUTPUT.put_line (
               I
            || '. '
            || SUBSTR (FND_MSG_PUB.Get (p_encoded => FND_API.G_FALSE), 1, 255));
      END LOOP;
   END IF;
END;

Sample Output of the Create Person Script
x_return_status = S
x_msg_count = 0
Party Id = 7860
Party Number = 6245
Profile Id = 4955
x_msg_data = ''

Script To Verify whether the Create Person API is successful
SELECT party_id,
       SUBSTR (party_number, 1, 5),
       SUBSTR (party_name, 1, 20),
       SUBSTR (person_last_name, 1, 20),
       SUBSTR (person_first_name, 1, 20),
       SUBSTR (object_version_number, 1, 1),
       SUBSTR (created_by_module, 1, 25)
  FROM hz_parties
 WHERE party_id = '7860';

Party_id = 7860
Party_number = 6245
Party_name = Oracle India
Person_last_name = India
Person_first_name = Oracle
Object_version_number = 1
Created_by_module = TCA_EXAMPLE

SELECT person_profile_id,
       party_id,
       effective_start_date,
       object_version_number,
       SUBSTR (created_by_module, 1, 20)
  FROM hz_person_profiles
 WHERE person_profile_id = ‘4955’;

person_profile_id = 4955
party_id = 7860
effective_start_date = 12-MAY-02
object_version_number = 1
created_by_module = TCA_EXAMPLE