Below is the usual sequence followed in the Customer conversion, more number of columns would be included in API usage but that depends on the business requirements.
1. Create a party and an account
2. Create a physical location
3. Create a party site using party_id from step 1 and location_id from step 2
4. Create an account site using cust_account_id from step 1 and party_site_id from step 3.
5. Create a definition contact
6. Create an account site use using cust_acct_site_id from step 4 and site_use_code='BILL_TO'
1) Create Party an account:
p_location_rec hz_location_v2pub.location_rec_type;
x_location_id NUMBER;
x_return_status VARCHAR2(2000);
x_msg_count NUMBER;
x_msg_data VARCHAR2(2000);
v_organization_rec hz_party_v2pub.organization_rec_type; -- API Parameter
v_customer_account_rec hz_cust_account_v2pub.cust_account_rec_type; -- API Parameter
v_party_rec hz_party_v2pub.party_rec_type;
v_customer_profile_rec hz_customer_profile_v2pub.customer_profile_rec_type;
v_location_rec hz_location_v2pub.location_rec_type;
v_party_site_rec hz_party_site_v2pub.party_site_rec_type;
v_party_site_use_rec hz_party_site_v2pub.party_site_use_rec_type;
v_customer_profile_amt hz_customer_profile_v2pub.cust_profile_amt_rec_type;
v_cust_acct_site_rec hz_cust_account_site_v2pub.cust_acct_site_rec_type;
v_customer_site_use_rec hz_cust_account_site_v2pub.cust_site_use_rec_type;
v_customer_ship_site_use_rec hz_cust_account_site_v2pub.cust_site_use_rec_type;
v_contact_point_rec hz_contact_point_v2pub.contact_point_rec_type;
v_phone_rec hz_contact_point_v2pub.phone_rec_type;
v_email_rec hz_contact_point_v2pub.email_rec_type;
v_person_rec hz_party_v2pub.person_rec_type;
v_org_contact_rec hz_party_contact_v2pub.org_contact_rec_type;
x_party_site_id NUMBER;
x_party_site_number VARCHAR2(2000);
v_party_tax_profile_id NUMBER;
x_cust_acct_site_id NUMBER;
x_site_use_id NUMBER;
x_contact_point_id NUMBER;
x_cust_account_id NUMBER;
x_account_number VARCHAR2(2000);
x_party_id NUMBER;
x_party_number VARCHAR2(2000);
x_profile_id NUMBER;
l_party_id NUMBER;
l_success NUMBER;
l_count NUMBER;
l_cust_acc_id NUMBER;
v_count NUMBER;
v_customer_account_id NUMBER;
x_cust_account_profile_id NUMBER;
v_cust_act_prof_amt_id NUMBER;
v_org_id NUMBER;
v_gl_id_rec NUMBER;
x_object_version_number NUMBER;
v_profile_class_id hz_cust_profile_classes.profile_class_id%TYPE;
variable assignment are done with the cusror, the data is fetched from the temp table and assigned into rec_cur variable.
BEGIN
SELECT profile_class_id
INTO v_profile_class_id
FROM hz_cust_profile_classes
WHERE name = rec_cur.profile_class;
EXCEPTION
WHEN NO_DATA_FOUND THEN
v_profile_class_id := 0;
WHEN OTHERS THEN
v_profile_class_id := 0;
END;
v_organization_rec.organization_name := TRIM(rec_cur.cust_name_arabic);
v_organization_rec.created_by_module := 'TCA_V1_API';
v_organization_rec.known_as := 'N\A';
v_customer_account_rec.account_name := rec_cur.cust_name_eng;
v_customer_account_rec.customer_class_code := rec_cur.Classification;
v_customer_profile_rec.profile_class_id := v_profile_class_id;
hz_cust_account_v2pub.create_cust_account
( p_init_msg_list =>FND_API.G_FALSE,
p_cust_account_rec => v_customer_account_rec, -- Customer Account Record
p_organization_rec => v_organization_rec, -- Party Organization Record
p_customer_profile_rec => v_customer_profile_rec, -- Customer Profile Record
p_create_profile_amt => fnd_api.g_true,
x_cust_account_id => l_cust_acc_id, x_account_number => x_account_number,
x_party_id => x_party_id, x_party_number => x_party_number, x_profile_id => x_profile_id,
x_return_status =>x_return_status, x_msg_count => x_msg_count, x_msg_data => x_msg_data );
COMMIT;
IF x_return_status = 'S' THEN
NULL;
ELSE
ROLLBACK;
L_SUCCESS :=2;
--Update the staging table status based on the status.
-- 2. Create a physical location
v_location_rec.country := 'US'; -- Country location code.
v_location_rec.address1 := rec_cur.cust_no;
v_location_rec.address2 := rec_cur.site_Address2;
v_location_rec.city := rec_cur.cust_city;
v_location_rec.created_by_module := 'TCA_V1_API';
hz_location_v2pub.create_location(P_INIT_MSG_LIST => 'T', P_LOCATION_REC => v_location_rec, X_LOCATION_ID => X_LOCATION_ID,
X_RETURN_STATUS =>X_RETURN_STATUS, X_MSG_COUNT => X_MSG_COUNT, X_MSG_DATA => X_MSG_DATA);
-- 3. Create a party site using party_id from step 1 and location_id from step 2
IF x_location_id IS NOT NULL THEN -- Location ID not Null
v_party_site_rec.party_id := x_party_id;
v_party_site_rec.location_id := x_location_id;
v_party_site_rec.party_site_number := NULL;
v_party_site_rec.identifying_address_flag := 'Y';
v_party_site_rec.created_by_module := 'TCA_V1_API';
hz_party_site_v2pub.create_party_site( P_INIT_MSG_LIST => 'T', P_PARTY_SITE_REC => v_party_site_rec,
X_PARTY_SITE_ID => X_PARTY_SITE_ID, X_PARTY_SITE_NUMBER => X_PARTY_SITE_NUMBER,
X_RETURN_STATUS => X_RETURN_STATUS, X_MSG_COUNT => X_MSG_COUNT, X_MSG_DATA => X_MSG_DATA);
-- 4. Create an account site using cust_account_id from step 1 and party_site_id from step 3.
IF x_party_site_id IS NOT NULL THEN -- Party Site ID not null
FOR rec_cur_ou IN cur_ou
LOOP
v_org_id := rec_cur_ou.organization_id;
v_cust_acct_site_rec.cust_account_id := l_cust_acc_id;
v_cust_acct_site_rec.party_site_id := x_party_site_id;
v_cust_acct_site_rec.org_id := v_org_id;
-- p_cust_acct_site_rec.orig_system_reference := p_cust_acct_site_id;
v_cust_acct_site_rec.created_by_module := 'TCA_V1_API';
hz_cust_account_site_v2pub.create_cust_acct_site(P_INIT_MSG_LIST => 'T', P_CUST_ACCT_SITE_REC => v_cust_acct_site_rec,
X_CUST_ACCT_SITE_ID => X_CUST_ACCT_SITE_ID, X_RETURN_STATUS => X_RETURN_STATUS, X_MSG_COUNT => X_MSG_COUNT,
X_MSG_DATA => X_MSG_DATA);
IF x_cust_acct_site_id IS NOT NULL THEN -- Customer Account Site ID is not null
-- v_gl_id_rec := NULL;
v_customer_ship_site_use_rec.cust_acct_site_id := x_cust_acct_site_id;
v_customer_ship_site_use_rec.site_use_code := 'SHIP_TO';
-- v_customer_site_use_rec.gl_id_rec := 7006;
v_customer_ship_site_use_rec.org_id := v_org_id;
v_customer_ship_site_use_rec.created_by_module := 'TCA_V1_API';
hz_cust_account_site_v2pub.create_cust_site_use ( 'T', v_customer_ship_site_use_rec, v_customer_profile_rec, '', '',
x_site_use_id, x_return_status, x_msg_count, x_msg_data);
v_customer_site_use_rec.cust_acct_site_id := x_cust_acct_site_id;
v_customer_site_use_rec.site_use_code := 'BILL_TO';
v_customer_site_use_rec.gl_id_rec := rec_cur.ar_receivable_account;--7006;
v_customer_site_use_rec.org_id := v_org_id;
v_customer_site_use_rec.created_by_module := 'TCA_V1_API';
hz_cust_account_site_v2pub.create_cust_site_use ( 'T', v_customer_site_use_rec,
v_customer_profile_rec, '', '', x_site_use_id, x_return_status, x_msg_count, x_msg_data);
END IF;--X_CUST_ACCT_SITE_ID
-- 5. Create a definition contact
IF rec_cur.cust_phone1 IS NOT NULL THEN -- Phone No 1 not null
v_contact_point_rec.owner_table_name := 'HZ_PARTY_SITES';
v_contact_point_rec.owner_table_id := x_party_site_id;
v_contact_point_rec.created_by_module := 'TCA_V1_API';
v_contact_point_rec.contact_point_type := 'PHONE';
v_PHONE_REC.phone_number := rec_cur.cust_phone1;
v_PHONE_REC.phone_line_type := 'GEN';
hz_contact_point_v2pub.create_phone_contact_point(p_init_msg_list => 'T', p_contact_point_rec => v_contact_point_rec,
p_phone_rec => v_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 );
THe API return status should be used appropriately for updating the staging table.
1. Create a party and an account
2. Create a physical location
3. Create a party site using party_id from step 1 and location_id from step 2
4. Create an account site using cust_account_id from step 1 and party_site_id from step 3.
5. Create a definition contact
6. Create an account site use using cust_acct_site_id from step 4 and site_use_code='BILL_TO'
1) Create Party an account:
p_location_rec hz_location_v2pub.location_rec_type;
x_location_id NUMBER;
x_return_status VARCHAR2(2000);
x_msg_count NUMBER;
x_msg_data VARCHAR2(2000);
v_organization_rec hz_party_v2pub.organization_rec_type; -- API Parameter
v_customer_account_rec hz_cust_account_v2pub.cust_account_rec_type; -- API Parameter
v_party_rec hz_party_v2pub.party_rec_type;
v_customer_profile_rec hz_customer_profile_v2pub.customer_profile_rec_type;
v_location_rec hz_location_v2pub.location_rec_type;
v_party_site_rec hz_party_site_v2pub.party_site_rec_type;
v_party_site_use_rec hz_party_site_v2pub.party_site_use_rec_type;
v_customer_profile_amt hz_customer_profile_v2pub.cust_profile_amt_rec_type;
v_cust_acct_site_rec hz_cust_account_site_v2pub.cust_acct_site_rec_type;
v_customer_site_use_rec hz_cust_account_site_v2pub.cust_site_use_rec_type;
v_customer_ship_site_use_rec hz_cust_account_site_v2pub.cust_site_use_rec_type;
v_contact_point_rec hz_contact_point_v2pub.contact_point_rec_type;
v_phone_rec hz_contact_point_v2pub.phone_rec_type;
v_email_rec hz_contact_point_v2pub.email_rec_type;
v_person_rec hz_party_v2pub.person_rec_type;
v_org_contact_rec hz_party_contact_v2pub.org_contact_rec_type;
x_party_site_id NUMBER;
x_party_site_number VARCHAR2(2000);
v_party_tax_profile_id NUMBER;
x_cust_acct_site_id NUMBER;
x_site_use_id NUMBER;
x_contact_point_id NUMBER;
x_cust_account_id NUMBER;
x_account_number VARCHAR2(2000);
x_party_id NUMBER;
x_party_number VARCHAR2(2000);
x_profile_id NUMBER;
l_party_id NUMBER;
l_success NUMBER;
l_count NUMBER;
l_cust_acc_id NUMBER;
v_count NUMBER;
v_customer_account_id NUMBER;
x_cust_account_profile_id NUMBER;
v_cust_act_prof_amt_id NUMBER;
v_org_id NUMBER;
v_gl_id_rec NUMBER;
x_object_version_number NUMBER;
v_profile_class_id hz_cust_profile_classes.profile_class_id%TYPE;
variable assignment are done with the cusror, the data is fetched from the temp table and assigned into rec_cur variable.
BEGIN
SELECT profile_class_id
INTO v_profile_class_id
FROM hz_cust_profile_classes
WHERE name = rec_cur.profile_class;
EXCEPTION
WHEN NO_DATA_FOUND THEN
v_profile_class_id := 0;
WHEN OTHERS THEN
v_profile_class_id := 0;
END;
v_organization_rec.organization_name := TRIM(rec_cur.cust_name_arabic);
v_organization_rec.created_by_module := 'TCA_V1_API';
v_organization_rec.known_as := 'N\A';
v_customer_account_rec.account_name := rec_cur.cust_name_eng;
v_customer_account_rec.customer_class_code := rec_cur.Classification;
v_customer_profile_rec.profile_class_id := v_profile_class_id;
hz_cust_account_v2pub.create_cust_account
( p_init_msg_list =>FND_API.G_FALSE,
p_cust_account_rec => v_customer_account_rec, -- Customer Account Record
p_organization_rec => v_organization_rec, -- Party Organization Record
p_customer_profile_rec => v_customer_profile_rec, -- Customer Profile Record
p_create_profile_amt => fnd_api.g_true,
x_cust_account_id => l_cust_acc_id, x_account_number => x_account_number,
x_party_id => x_party_id, x_party_number => x_party_number, x_profile_id => x_profile_id,
x_return_status =>x_return_status, x_msg_count => x_msg_count, x_msg_data => x_msg_data );
COMMIT;
IF x_return_status = 'S' THEN
NULL;
ELSE
ROLLBACK;
L_SUCCESS :=2;
--Update the staging table status based on the status.
-- 2. Create a physical location
v_location_rec.country := 'US'; -- Country location code.
v_location_rec.address1 := rec_cur.cust_no;
v_location_rec.address2 := rec_cur.site_Address2;
v_location_rec.city := rec_cur.cust_city;
v_location_rec.created_by_module := 'TCA_V1_API';
hz_location_v2pub.create_location(P_INIT_MSG_LIST => 'T', P_LOCATION_REC => v_location_rec, X_LOCATION_ID => X_LOCATION_ID,
X_RETURN_STATUS =>X_RETURN_STATUS, X_MSG_COUNT => X_MSG_COUNT, X_MSG_DATA => X_MSG_DATA);
-- 3. Create a party site using party_id from step 1 and location_id from step 2
IF x_location_id IS NOT NULL THEN -- Location ID not Null
v_party_site_rec.party_id := x_party_id;
v_party_site_rec.location_id := x_location_id;
v_party_site_rec.party_site_number := NULL;
v_party_site_rec.identifying_address_flag := 'Y';
v_party_site_rec.created_by_module := 'TCA_V1_API';
hz_party_site_v2pub.create_party_site( P_INIT_MSG_LIST => 'T', P_PARTY_SITE_REC => v_party_site_rec,
X_PARTY_SITE_ID => X_PARTY_SITE_ID, X_PARTY_SITE_NUMBER => X_PARTY_SITE_NUMBER,
X_RETURN_STATUS => X_RETURN_STATUS, X_MSG_COUNT => X_MSG_COUNT, X_MSG_DATA => X_MSG_DATA);
-- 4. Create an account site using cust_account_id from step 1 and party_site_id from step 3.
IF x_party_site_id IS NOT NULL THEN -- Party Site ID not null
FOR rec_cur_ou IN cur_ou
LOOP
v_org_id := rec_cur_ou.organization_id;
v_cust_acct_site_rec.cust_account_id := l_cust_acc_id;
v_cust_acct_site_rec.party_site_id := x_party_site_id;
v_cust_acct_site_rec.org_id := v_org_id;
-- p_cust_acct_site_rec.orig_system_reference := p_cust_acct_site_id;
v_cust_acct_site_rec.created_by_module := 'TCA_V1_API';
hz_cust_account_site_v2pub.create_cust_acct_site(P_INIT_MSG_LIST => 'T', P_CUST_ACCT_SITE_REC => v_cust_acct_site_rec,
X_CUST_ACCT_SITE_ID => X_CUST_ACCT_SITE_ID, X_RETURN_STATUS => X_RETURN_STATUS, X_MSG_COUNT => X_MSG_COUNT,
X_MSG_DATA => X_MSG_DATA);
IF x_cust_acct_site_id IS NOT NULL THEN -- Customer Account Site ID is not null
-- v_gl_id_rec := NULL;
v_customer_ship_site_use_rec.cust_acct_site_id := x_cust_acct_site_id;
v_customer_ship_site_use_rec.site_use_code := 'SHIP_TO';
-- v_customer_site_use_rec.gl_id_rec := 7006;
v_customer_ship_site_use_rec.org_id := v_org_id;
v_customer_ship_site_use_rec.created_by_module := 'TCA_V1_API';
hz_cust_account_site_v2pub.create_cust_site_use ( 'T', v_customer_ship_site_use_rec, v_customer_profile_rec, '', '',
x_site_use_id, x_return_status, x_msg_count, x_msg_data);
v_customer_site_use_rec.cust_acct_site_id := x_cust_acct_site_id;
v_customer_site_use_rec.site_use_code := 'BILL_TO';
v_customer_site_use_rec.gl_id_rec := rec_cur.ar_receivable_account;--7006;
v_customer_site_use_rec.org_id := v_org_id;
v_customer_site_use_rec.created_by_module := 'TCA_V1_API';
hz_cust_account_site_v2pub.create_cust_site_use ( 'T', v_customer_site_use_rec,
v_customer_profile_rec, '', '', x_site_use_id, x_return_status, x_msg_count, x_msg_data);
END IF;--X_CUST_ACCT_SITE_ID
-- 5. Create a definition contact
IF rec_cur.cust_phone1 IS NOT NULL THEN -- Phone No 1 not null
v_contact_point_rec.owner_table_name := 'HZ_PARTY_SITES';
v_contact_point_rec.owner_table_id := x_party_site_id;
v_contact_point_rec.created_by_module := 'TCA_V1_API';
v_contact_point_rec.contact_point_type := 'PHONE';
v_PHONE_REC.phone_number := rec_cur.cust_phone1;
v_PHONE_REC.phone_line_type := 'GEN';
hz_contact_point_v2pub.create_phone_contact_point(p_init_msg_list => 'T', p_contact_point_rec => v_contact_point_rec,
p_phone_rec => v_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 );
THe API return status should be used appropriately for updating the staging table.