0 Replies Latest reply on Jan 28, 2018 5:31 AM by 3383498

    Unable to import data for the salesrep territories using salesrep API

    3383498

      Hello,

       

      I have created Salesperson through API but unable to create the territory as shown below:

       

       

       

       

       

      The above sections are not populated:

       

      Below is the Procedure created for the auto create of the salesrep API.Please advise if its OK

       

      CREATE OR REPLACE PROCEDURE TEST_CREATE_SALESREP_API(p_effective_date DATE) AS

       

       

      CURSOR

      cur_emp_fetch_data

      IS

      SELECT

      PER.person_id,

      PER.full_name,

      PER.first_name,

      PER.last_name,

      USR.user_name,

      PER.employee_number,

      PER.EMAIL_ADDRESS,

      USR.user_id

      FROM

      apps.PER_ALL_PEOPLE_F PER,

      apps.FND_USER USR

      WHERE

      USR.employee_id=PER.person_id

      AND PER.EFFECTIVE_START_DATE=NVL(p_effective_date,TRUNC(SYSDATE));

       

       

      ln_responsibility_id         NUMBER;

      ln_application_id            NUMBER;

      ln_user_id                   PLS_INTEGER := fnd_global.user_id;

      lc_return_status             VARCHAR2(1);

      ln_msg_count                 NUMBER;

      lc_msg_data                  VARCHAR2(5000);

      lc_msg_dummy                 VARCHAR2(5000);

      lc_output                    VARCHAR2(5000);

      ln_resource_id               JTF_RS_RESOURCE_EXTNS.RESOURCE_ID%TYPE;

      lc_resource_number           JTF_RS_RESOURCE_EXTNS.RESOURCE_NUMBER%TYPE;

      ln_salesrep_number           NUMBER;

      ln_salesrep_id                NUMBER;

      l_msg_index_out  NUMBER;

       

       

       

      BEGIN

       

       

       

       

      FOR rec_cur_emp_fetch_data IN cur_emp_fetch_data

      LOOP

       

       

      DBMS_OUTPUT.PUT_LINE('COMES HERE');

         

      SELECT

          responsibility_id,

          application_id

        INTO

         ln_responsibility_id,

         ln_application_id

        FROM

         fnd_responsibility_vl

      WHERE

         responsibility_name = 'CRM Administrator';

       

       

      BEGIN

      ln_user_id:=111;

             fnd_global.apps_initialize (ln_user_id, ln_responsibility_id, ln_application_id);

      DBMS_OUTPUT.PUT_LINE('COMES HERE123');      

            

              jtf_rs_resource_pub.create_resource

                 (   p_api_version                 => 1.0,

                     p_category                     => 'EMPLOYEE',

                     p_start_date_active             => SYSDATE,

                     p_source_id                    => rec_cur_emp_fetch_data.person_id,

                     p_user_id                    => rec_cur_emp_fetch_data.user_id,

                     p_user_name                  => rec_cur_emp_fetch_data.user_name,

                     p_resource_name              => rec_cur_emp_fetch_data.full_name,

                     p_source_number              => rec_cur_emp_fetch_data.employee_number,

                     p_source_name                => rec_cur_emp_fetch_data.full_name,

                     p_source_first_name          => rec_cur_emp_fetch_data.first_name,

                     p_source_last_name           => rec_cur_emp_fetch_data.last_name,

                     p_source_business_grp_id        => fnd_profile.value_specific('PER_BUSINESS_GROUP_ID'),  

                     x_return_status                 => lc_return_status,

                     x_msg_count                     => ln_msg_count,

                     x_msg_data                     => lc_msg_data,

                     x_resource_id                 => ln_resource_id,

                     x_resource_number             => lc_resource_number

                 );

                

                

      DBMS_OUTPUT.PUT_LINE('COMES HERE456 return status'||lc_return_status);

                

               IF (lc_return_status <> 'S') THEN

                  BEGIN

                     FOR i IN 1 .. ln_msg_count

                     LOOP

                        fnd_msg_pub.get (i, fnd_api.g_false, lc_msg_data, lc_msg_dummy);

                        lc_output := (TO_CHAR || ': ' || lc_msg_data);

                     END LOOP;

                        dbms_output.put_line('Error :'||lc_output);

                  END;

                  ROLLBACK;

               ELSE

              

               COMMIT;

               dbms_output.put_line('Resource imported sucessfully.');

              

               SELECT

                  JTF_RS_SALESREP_NUMBER_S.nextval

               INTO

                  ln_salesrep_number

               FROM

                  DUAL;    

              

               DBMS_OUTPUT.PUT_LINE('COMES HERE8888');

              

               BEGIN

               jtf_rs_salesreps_pub.CREATE_SALESREP(

      P_API_VERSION                  => 1.0,

      P_INIT_MSG_LIST                => 'T',

      P_COMMIT                       => 'T',

      P_RESOURCE_ID                  => ln_resource_id,          ----Get the resource id from JTF_RS_RESOURCE_EXTNS

      P_SALES_CREDIT_TYPE_ID         => 1,

      P_NAME                         => rec_cur_emp_fetch_data.full_name,--

      P_STATUS                       => NULL,

      P_START_DATE_ACTIVE            => sysdate,

      P_END_DATE_ACTIVE              => NULL,

      P_GL_ID_REV                    => NULL,

      P_GL_ID_FREIGHT                => NULL,

      P_GL_ID_REC                    => NULL,

      P_SET_OF_BOOKS_ID              => 1111,         

      P_SALESREP_NUMBER              => ln_salesrep_number,

      P_EMAIL_ADDRESS                => rec_cur_emp_fetch_data.email_address,----Replace with Email ID of the user

      P_WH_UPDATE_DATE               => sysdate,

      P_SALES_TAX_GEOCODE            => NULL,

      P_SALES_TAX_INSIDE_CITY_LIMITS => NULL,

      X_RETURN_STATUS                => lc_return_status,

      X_MSG_COUNT                    => ln_msg_count,

      X_MSG_DATA                     => lc_msg_data,

      X_SALESREP_ID                  => ln_salesrep_id);

       

       

               COMMIT;

              

               DBMS_OUTPUT.PUT_LINE('COMES HERE000000');

              

               dbms_output.put_line('return status is ' || lc_return_Status);

      FND_MSG_PUB.GET(p_msg_index     => 1,

                       p_encoded       => 'F',          

                       p_data          => lc_msg_data,

                       p_msg_index_out => l_msg_index_out);  

                               

      DBMS_OUTPUT.put_line('API Error Message : '||lc_msg_data);

      dbms_output.put_line('msg data is  ' || lc_msg_data);

      dbms_output.put_line('Sales Rep id is ' || ln_salesrep_id);

      END;

              

               END IF;

              

             EXCEPTION

            WHEN OTHERS THEN

             DBMS_OUTPUT.PUT_LINE ('Error While importing the Resource :'||SQLERRM);

             ROLLBACK;

            END; 

       

       

      END LOOP;

       

       

      END;