Showing posts with label TCA Apis. Show all posts
Showing posts with label TCA Apis. Show all posts

Monday, September 23, 2013

Create Customer in TCA Using API


DECLARE
   p_cust_account_rec                                hz_cust_account_v2pub.cust_account_rec_type;
   p_organization_rec                                hz_party_v2pub.organization_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);
   l_created_by_module                               VARCHAR2 (240);
   l_error_message                                   VARCHAR2 (2000);
   l_msg_index_out                                   NUMBER;
BEGIN
   DBMS_APPLICATION_INFO.set_client_info ('&ORG_ID');

   SELECT lookup_code
     INTO l_created_by_module
     FROM fnd_lookup_values
    WHERE lookup_type = 'HZ_CREATED_BY_MODULES'
      AND ROWNUM = 1
      AND enabled_flag = 'Y'
      AND NVL (end_date_active, SYSDATE) >= SYSDATE;

   p_cust_account_rec.account_name                          := 'TCA API Test Acconut';
   p_cust_account_rec.created_by_module                     := l_created_by_module;
   p_organization_rec.organization_name                     := 'TCA API Test Party';
   p_organization_rec.created_by_module                     := l_created_by_module;
   hz_cust_account_v2pub.create_cust_account (p_init_msg_list               => fnd_api.g_true
                                            , p_cust_account_rec            => p_cust_account_rec
                                            , p_organization_rec            => p_organization_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
      FOR i IN 1 .. x_msg_count
      LOOP
         apps.fnd_msg_pub.get (p_msg_index                   => i
                             , p_encoded                     => fnd_api.g_false
                             , p_data                        => x_msg_data
                             , p_msg_index_out               => l_msg_index_out
                              );

         IF l_error_message IS NULL
         THEN
            l_error_message                                          := SUBSTR (x_msg_data, 1, 250);
         ELSE
            l_error_message                                          :=
                                                                      l_error_message || ' /' || SUBSTR (x_msg_data, 1, 250);
         END IF;
      END LOOP;

      DBMS_OUTPUT.put_line ('*****************************************');
      DBMS_OUTPUT.put_line ('API Error : ' || l_error_message);
      DBMS_OUTPUT.put_line ('*****************************************');
      ROLLBACK;
   ELSE
      DBMS_OUTPUT.put_line ('*****************************************');
      DBMS_OUTPUT.put_line ('Organization Created Successfully ');
      DBMS_OUTPUT.put_line ('Party Id : ' || x_party_id);
      DBMS_OUTPUT.put_line ('Party Number : ' || x_party_number);
      DBMS_OUTPUT.put_line ('Cust Account Id : ' || x_cust_account_id);
      DBMS_OUTPUT.put_line ('Account Number : ' || x_account_number);
      DBMS_OUTPUT.put_line ('Profile id : ' || x_profile_id);
      DBMS_OUTPUT.put_line ('*****************************************');
      COMMIT;
   END IF;
EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.put_line ('Unexpected Error ' || SUBSTR (SQLERRM, 1, 250));
END;

Tuesday, March 12, 2013

API to Create the Extensible Attributes in TCA for Organization using API HZ_EXTENSIBILITY_PUB

This Scripts explains how to create the extensible attributes for the Organization In TCA Architecture  using API HZ_EXTENSIBILITY_PUB.

Front End Navigation :-

Oracle Customer Data Librarian Superuser à Administration à Extension à Select the Extensible Attribute Group name form the LOV as shown in Screen shot




DECLARE
   l_org_profile_id                                  NUMBER;
   l_user_attr_data_table                            ego_user_attr_data_table;
   l_user_attr_row_table                             ego_user_attr_row_table;
   l_application_id                                  NUMBER;
   l_attr_group_type                                 VARCHAR2 (40);
   l_attr_group1_name                                VARCHAR2 (30);
   l_start_time                                      DATE;
   l_end_time                                        DATE;
   x_failed_row_id_list                              VARCHAR2 (10000);
   x_return_status                                   VARCHAR2 (1);
   x_errorcode                                       NUMBER;
   x_msg_count                                       NUMBER;
   x_msg_data                                        VARCHAR2 (1000);
BEGIN
   l_org_profile_id                               := 3203;
   l_application_id                               := 222;
   l_attr_group_type                              := 'HZ_ORG_PROFILES_GROUP';
   l_attr_group1_name                             := 'OS_INFO';

   l_user_attr_row_table                          :=
      ego_user_attr_row_table (ego_user_attr_row_obj (1
                                                    , NULL
                                                    , l_application_id
                                                    , l_attr_group_type
                                                    , l_attr_group1_name
                                                    , NULL
                                                    , NULL
                                                    , NULL
                                                    , NULL
                                                    , NULL
                                                    , NULL
                                                    , ego_user_attrs_data_pvt.g_update_mode
                                                     )
                              );

   l_user_attr_data_table                         :=
      ego_user_attr_data_table (ego_user_attr_data_obj (1, 'OS_KEY', NULL, 42787902, NULL, NULL, NULL, NULL)
                              , ego_user_attr_data_obj (1, 'OS_PARENT_KEY', NULL, 517045, NULL, NULL, NULL, NULL)
                              , ego_user_attr_data_obj (1
                                                      , 'OS_PARENT_NAME'
                                                      , 'Century Insurance'
                                                      , NULL
                                                      , NULL
                                                      , NULL
                                                      , NULL
                                                      , NULL
                                                       )
                              , ego_user_attr_data_obj (1, 'OS_ULT_PARENT_KEY', NULL, 517045, NULL, NULL, NULL, NULL)
                              , ego_user_attr_data_obj (1
                                                      , 'OS_ULT_PARENT_NAME'
                                                      , 'Century Insurance'
                                                      , NULL
                                                      , NULL
                                                      , NULL
                                                      , NULL
                                                      , NULL
                                                       )
                              , ego_user_attr_data_obj (1, 'OS_LATITUDE', 'OS_LATITUDE', NULL, NULL, NULL, NULL, NULL)
                              , ego_user_attr_data_obj (1, 'OS_LONGITUDE', 'OS_LONGITUDE', NULL, NULL, NULL, NULL, NULL)
                              , ego_user_attr_data_obj (1
                                                      , 'OS_BUSINESS_DESC'
                                                      , 'OS_BUSINESS_DESC'
                                                      , NULL
                                                      , NULL
                                                      , NULL
                                                      , NULL
                                                      , NULL
                                                       )
                               );


   hz_extensibility_pub.process_organization_record (p_api_version                 => 1.0
                                                   , p_org_profile_id              => l_org_profile_id
                                                   , p_attributes_row_table        => l_user_attr_row_table
                                                   , p_attributes_data_table       => l_user_attr_data_table
                                                   , p_debug_level                 => 3
                                                   , p_commit                      => fnd_api.g_true
                                                   , x_failed_row_id_list          => x_failed_row_id_list
                                                   , x_return_status               => x_return_status
                                                   , x_errorcode                   => x_errorcode
                                                   , x_msg_count                   => x_msg_count
                                                   , x_msg_data                    => x_msg_data
                                                    );

   DBMS_OUTPUT.put_line (   'API Status, Return Status is: '
                         || x_return_status
                         || ', Mesage Count is: '
                         || x_msg_count
                         || ' and Error Message is: '
                         || x_msg_data
                        );

   IF (LENGTH (x_failed_row_id_list) > 0)
   THEN
      DBMS_OUTPUT.put_line (   'Details of rows which failed: '
                            || x_failed_row_id_list);

      DECLARE
         l_errors_tbl                                      error_handler.error_tbl_type;
      BEGIN
         error_handler.get_message_list (l_errors_tbl);

         FOR i IN 1 .. l_errors_tbl.COUNT
         LOOP
            DBMS_OUTPUT.put_line (   'API Error : '
                                  || l_errors_tbl (i).MESSAGE_TEXT);
            DBMS_OUTPUT.put_line (   'Message Type : '
                                  || l_errors_tbl (i).MESSAGE_TYPE);
         END LOOP;
      END;
   END IF;

END;