Monday, 19 January 2015

HZ API for Customer Create


TEMP  TABLE NAME : xx_party_temp
            (PERSON_FIRST_NAME VARCHAR2,
             PERSON_LAST_NAME VARCHAR2,
             CREATED_BY_MODULE VARCHAR2(10),
             ADDRESS          VARCHAR2(60),
             EMAIL_ADDRESS    VARCHAR2(40));

/****************************************/
   HZ API for create customer and emial
/******************************************/

CREATE OR REPLACE
PROCEDURE XX_CUSTOMER_CREATE_EVENT
AS
  --Declare varibale for Customer Create
/********************************************/
  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);

  --  Declare varibale for Customer Email Address
  /****************************************/
  l_contact_point_id NUMBER;
  l_return_status    VARCHAR2 (1);
  l_msg_count        NUMBER;
  l_msg_data         VARCHAR2 (1000);
  l_output           VARCHAR2 (1000);
  l_msg_dummy        VARCHAR2 (1000);
  l_party_id         NUMBER;
  x_contact_point_id NUMBER;
  l_contact_point_rec hz_contact_point_v2pub.contact_point_rec_type;
  l_edi_rec_type hz_contact_point_v2pub.edi_rec_type;
  l_email_rec hz_contact_point_v2pub.email_rec_type;
  l_phone_rec hz_contact_point_v2pub.phone_rec_type;
  l_telex_rec_type hz_contact_point_v2pub.telex_rec_type;
  l_web_rec_type hz_contact_point_v2pub.web_rec_type;
  CURSOR parties_cur
  IS
     SELECT hp.person_first_name ,
      hp.person_last_name        ,
      hp.created_by_module       ,
      hp.address                 ,
      hp.email_address
       FROM xx_party_temp hp;
BEGIN
  fnd_global.APPS_INITIALIZE(11746,20678,222);
  FOR per_cur IN parties_cur
  LOOP
    p_cust_account_rec.account_name      := per_cur.person_first_name;
    p_cust_account_rec.status            :='I';
    p_cust_account_rec.created_by_module := 'TCA_FORM_WRAPPER';
    p_person_rec.person_first_name       := per_cur.person_first_name;--'Rohith';
    p_person_rec.person_last_name        := per_cur.person_last_name; --'Kumar';
    p_person_rec.created_by_module       := 'TCA_FORM_WRAPPER';
    DBMS_OUTPUT.PUT_LINE('Calling the API hz_cust_account_v2pub.create_cust_account');
    HZ_CUST_ACCOUNT_V2PUB.CREATE_CUST_ACCOUNT ( p_init_msg_list => FND_API.G_TRUE,
                                                p_cust_account_rec =>p_cust_account_rec,
                                                p_person_rec =>p_person_rec,
                                                 p_customer_profile_rec=>p_customer_profile_rec,
                                                p_create_profile_amt =>FND_API.G_FALSE,
                                                x_cust_account_id =>x_cust_account_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 );
    IF x_return_status                                          = fnd_api.g_ret_sts_success THEN
      COMMIT;
      DBMS_OUTPUT.PUT_LINE('Creation of Party and customer account is Successful ');
      DBMS_OUTPUT.PUT_LINE('Output information ....');
      DBMS_OUTPUT.PUT_LINE('x_cust_account_id : '||x_cust_account_id);
      DBMS_OUTPUT.PUT_LINE('x_account_number : '||x_account_number);
      DBMS_OUTPUT.PUT_LINE('x_party_id : '||x_party_id);
      DBMS_OUTPUT.PUT_LINE('x_party_number : '||x_party_number);
      DBMS_OUTPUT.PUT_LINE('x_profile_id : '||x_profile_id);
    ELSE
      DBMS_OUTPUT.put_line ('Creation of Party and customer account failed:'||x_msg_data);
      ROLLBACK;
      FOR i IN 1 .. x_msg_count
      LOOP
        x_msg_data := oe_msg_pub.get( p_msg_index => i, p_encoded => 'F');
        dbms_output.put_line( i|| ') '|| x_msg_data);
      END LOOP;
    END IF;
    DBMS_OUTPUT.PUT_LINE('Completion of API');
    -- End of Cust_Accout_Create
    /****************************************/
    -- Create customer Email Address
    /****************************************/
    BEGIN
      fnd_global.APPS_INITIALIZE(11746,20678,222);
      l_contact_point_rec.contact_point_type                      := 'EMAIL';
      l_contact_point_rec.owner_table_name                        := 'HZ_PARTIES';
      l_contact_point_rec.created_by_module                       := 'TCA_FORM_WRAPPER';
      l_contact_point_rec.owner_table_id                          := x_party_id;
      l_email_rec.email_address                                   := per_cur.email_address;
      hz_contact_point_v2pub.create_contact_point (p_init_msg_list => 'T',
                                                         p_contact_point_rec => l_contact_point_rec,
                                                         p_edi_rec => l_edi_rec_type,
                                                         p_email_rec => l_email_rec,
                                                         p_phone_rec => l_phone_rec,
                                                         p_telex_rec => l_telex_rec_type,
                                                        p_web_rec => l_web_rec_type,
                                                        x_contact_point_id => l_contact_point_id,
                                                        x_return_status => l_return_status,
                                                        x_msg_count => l_msg_count,
                                                       x_msg_data => l_msg_data );
      COMMIT;
      IF l_return_status = fnd_api.g_ret_sts_success THEN
        DBMS_OUTPUT.PUT_LINE('Creation of customer email address is Successful ');
        DBMS_OUTPUT.PUT_LINE('Output information ....');
        DBMS_OUTPUT.put_line ('l_return_status ' || l_return_status);
        DBMS_OUTPUT.put_line ('l_contact_point_id ' || l_contact_point_id);
      ELSE
        DBMS_OUTPUT.put_line ('Email addres creation  failed:'||x_msg_data);
        ROLLBACK;
        FOR i IN 1 .. l_msg_count
        LOOP
          fnd_msg_pub.get (i, fnd_api.g_false, l_msg_data, l_msg_dummy);
          l_output := (TO_CHAR (i) || ': ' || l_msg_data);
        END LOOP;
        DBMS_OUTPUT.put_line ('Error mesg' || l_output);
      END IF;
    END;
  END LOOP;
END XX_CUSTOMER_CREATE_EVENT;

No comments:

Post a Comment