Pages

Tuesday, February 16, 2016

hr_assignment_api.update_emp_asg in HRMS

create table xx_gosi_update
( emp_no varchar2(240)
,gosi  varchar2(240)
,status varchar2(240)
)

Below is the script for update the assignment (I am updating annuities field)
======================================================================

DECLARE
   -- Local Variables
   -- -----------------------
   lc_dt_ud_mode           VARCHAR2(100)    := NULL;
   ln_assignment_id       NUMBER                  := 1336;
   ln_supervisor_id        NUMBER                  := 2;
   ln_object_number       NUMBER                  := 5;
   ln_people_group_id  NUMBER                  :=null; -- 1;
   p_effective_date date;
   p_object_version_number number;
   v_assignment_id number;
 
   -- Out Variables for Find Date Track Mode API
   -- -----------------------------------------------------------------
   lb_correction                           BOOLEAN;
   lb_update                                 BOOLEAN;
   lb_update_override              BOOLEAN;
   lb_update_change_insert   BOOLEAN;
 
   -- Out Variables for Update Employee Assignment API
   -- ----------------------------------------------------------------------------
   ln_soft_coding_keyflex_id       HR_SOFT_CODING_KEYFLEX.SOFT_CODING_KEYFLEX_ID%TYPE;
   lc_concatenated_segments       VARCHAR2(2000);
   ln_comment_id                             PER_ALL_ASSIGNMENTS_F.COMMENT_ID%TYPE;
   lb_no_managers_warning        BOOLEAN;

 -- Out Variables for Update Employee Assgment Criteria
 -- -------------------------------------------------------------------------------
 ln_special_ceiling_step_id                    PER_ALL_ASSIGNMENTS_F.SPECIAL_CEILING_STEP_ID%TYPE;
 lc_group_name                                          VARCHAR2(30);
 ld_effective_start_date                             PER_ALL_ASSIGNMENTS_F.EFFECTIVE_START_DATE%TYPE;
 ld_effective_end_date                              PER_ALL_ASSIGNMENTS_F.EFFECTIVE_END_DATE%TYPE;
 lb_org_now_no_manager_warning   BOOLEAN;
 lb_other_manager_warning                  BOOLEAN;
 lb_spp_delete_warning                          BOOLEAN;
 lc_entries_changed_warning                VARCHAR2(30);
 lb_tax_district_changed_warn             BOOLEAN;

 cursor c1 is

SELECT a.rowid,pas.effective_start_date, pas.object_version_number,pas.assignment_id,decode(a.GOSI,'Yes','Y','No','N')gosi,a.emp_no,a.status
        --INTO p_effective_date, p_object_version_number,v_assignment_id
        FROM per_all_assignments_f pas
        ,xxdfc_gosi_update a
       WHERE pas.effective_end_date = TO_DATE ('12/31/4712', 'MM/DD/RRRR')
         --AND pas.assignment_id in(77,913);
         and a.EMP_NO=pas.ASSIGNMENT_NUMBER
         --and a.emp_no in('S00455','S00641')
         ;

 begin
 for rec in c1
 loop


 hr_assignment_api.update_emp_asg
 ( -- Input data elements
  -- ------------------------------
  p_effective_date                              => sysdate, --TO_DATE('12-JUN-2011'),
  p_datetrack_update_mode         => 'CORRECTION', --lc_dt_ud_mode,
  p_assignment_id                            => rec.assignment_id, --ln_assignment_id,
  --p_supervisor_id                              => NULL,
  --p_change_reason                           => NULL,
  --p_manager_flag                              => 'N',
  --p_bargaining_unit_code              => NULL,
  --p_labour_union_member_flag   => NULL,
  p_segment1                                       => 81, --DFC Business Group
  p_segment3                                       => rec.gosi, --'Y',
  --p_normal_hours                              => 8,
  --p_frequency                                       => 'W',
  -- Output data elements
  -- -------------------------------
  p_object_version_number             => rec.object_version_number, --ln_object_number,
  p_soft_coding_keyflex_id              => ln_soft_coding_keyflex_id,
  p_concatenated_segments             => lc_concatenated_segments,
  p_comment_id                                   => ln_comment_id,
  p_effective_start_date                      => ld_effective_start_date,
  p_effective_end_date                        => ld_effective_end_date,
  p_no_managers_warning               => lb_no_managers_warning,
  p_other_manager_warning            => lb_other_manager_warning
 );
 COMMIT;
 --v_assignment_id :=null;
 dbms_output.put_line('Hi-'||rec.object_version_number||'-Assignment_id-'||rec.assignment_id);
 update xx_gosi_update set status='S-'||rec.emp_no where rowid=rec.rowid;
 commit;
     end loop;                      
 --dbms_output.put_line('Hi-'||ln_object_number);
    EXCEPTION
         WHEN OTHERS THEN
                      ROLLBACK;
                      dbms_output.put_line(SQLERRM);
                      --end loop;                      

END;

hr_person_api.update_person in HRMS

CREATE OR REPLACE FORCE VIEW apps.xxhr_people_assignment_v (person_id,
                                                            assignment_id,
                                                            assignment_number,
                                                            employee_number,
                                                            employee_name,
                                                            date_of_joining,
                                                            ORGANIZATION,
                                                            organization_id,
                                                            email_address,
                                                            POSITION,
                                                            grade,
                                                            job,
                                                            age,
                                                            national_identifier,
                                                            dob,
                                                            title,
                                                            sex,
                                                            marital_status,
                                                            religion,
                                                            nationality,
                                                            employee_group,
                                                            payroll_id,
                                                            user_person_type,
                                                            business_group_id,
                                                            effective_start_date,
                                                            effective_end_date,
                                                            overtime_yes_no
                                                           )
AS
   (SELECT per.person_id, asg.assignment_id, asg.assignment_number,
           per.employee_number, per.full_name employee_name,
           per.original_date_of_hire date_of_joining, org.NAME ORGANIZATION,
           org.organization_id, per.email_address, pos.NAME POSITION,
           gra.NAME grade, job.NAME job,
           TRUNC ((SYSDATE - per.date_of_birth) / 365) age,
           per.national_identifier, per.date_of_birth dob,
           hr_general.decode_lookup ('TITLE', per.title) title,
           hr_general.decode_lookup ('SEX', per.sex) sex,
           hr_general.decode_lookup ('MAR_STATUS',
                                     per.marital_status
                                    ) marital_status,
           hr_general.decode_lookup ('SA_RELIGION',
                                     per.per_information7
                                    ) religion,
           hr_general.decode_lookup ('NATIONALITY',
                                     per.nationality
                                    ) nationality,
           grp.group_name employee_group, asg.payroll_id,
           ptp.user_person_type, per.business_group_id,
           per.effective_start_date, per.effective_end_date,
           grp.segment4 overtime_yes_no
      FROM per_all_people_f per,
           per_person_types ptp,
           per_all_assignments_f asg,
           hr_organization_units_v org,
           per_jobs job,
           per_positions pos,
           per_grades gra,
           pay_people_groups grp
     WHERE 1 = 1
       AND per.person_type_id = ptp.person_type_id
       --AND ptp.user_person_type IN ('Employee', 'Contract Employee')--Dev
       AND ptp.user_person_type IN ('Employee', 'Contract')              --UAT
       AND TRUNC (SYSDATE) BETWEEN per.effective_start_date
                               AND per.effective_end_date
       AND per.current_employee_flag = 'Y'
       AND per.person_id = asg.person_id
       AND TRUNC (SYSDATE) BETWEEN asg.effective_start_date
                               AND asg.effective_end_date
       AND asg.organization_id = org.organization_id
       AND asg.position_id = pos.position_id(+)
       AND asg.job_id = job.job_id(+)
       AND asg.grade_id = gra.grade_id(+)
       AND asg.people_group_id = grp.people_group_id(+));


============================================================
Below is the script for Update the Person i..e in Correction mode not update mode.

DECLARE  
   -- Local Variables  
   -- -----------------------  
    ln_object_version_number       PER_ALL_PEOPLE_F.OBJECT_VERSION_NUMBER%TYPE ;-- := 7;  
    lc_dt_ud_mode                 VARCHAR2(100)                                                                                     := NULL;  
    ln_assignment_id              PER_ALL_ASSIGNMENTS_F.ASSIGNMENT_ID%TYPE; --          := 33564;  
    lc_employee_number            PER_ALL_PEOPLE_F.EMPLOYEE_NUMBER%TYPE; --    := 'PRAJ_01';  
   
   -- Out Variables for Find Date Track Mode API  
   -- ----------------------------------------------------------------  
    lb_correction                  BOOLEAN;  
    lb_update                     BOOLEAN;  
    lb_update_override            BOOLEAN;   
    lb_update_change_insert       BOOLEAN;

   -- Out Variables for Update Employee API  
   -- -----------------------------------------------------------  
    ld_effective_start_date       DATE;  
    ld_effective_end_date         DATE;  
    lc_full_name                  PER_ALL_PEOPLE_F.FULL_NAME%TYPE;  
    ln_comment_id                 PER_ALL_PEOPLE_F.COMMENT_ID%TYPE;   
    lb_name_combination_warning   BOOLEAN;  
    lb_assign_payroll_warning     BOOLEAN;  
    lb_orig_hire_warning          BOOLEAN;

    cursor c1 is
    
            select --* 
        B.OBJECT_VERSION_NUMBER,A.*
        from XXHR_PEOPLE_ASSIGNMENT_V A
        --,per_all_assignments_f B
        ,per_all_people_f B
        WHERE 1=1
        AND A.PERSON_ID=B.PERSON_ID
        AND B.effective_end_date = TO_DATE ('12/31/4712', 'MM/DD/RRRR')
        and trunc(sysdate) between b.effective_start_date and b.effective_end_date
        --AND A.EMPLOYEE_NUMBER IN('E01549','E00007')
        --AND A.EMPLOYEE_NUMBER IN('E01577','S01112')
        order by a.person_id
        ;

BEGIN
for rec in c1
 loop
  
-- Update Employee API 
    -- ---------------------------------   
    hr_person_api.update_person 
    (       -- Input Data Elements 
            -- ------------------------------ 
            p_effective_date                => sysdate, ---TO_DATE('29-JUN-2011'), 
            p_datetrack_update_mode         => 'CORRECTION', 
            p_person_id                     => REC.PERSON_ID,
            p_per_information2              => NULL, --To Update Granfather is null 
            --p_middle_names                => 'TEST', 
            --p_marital_status              => 'M', 
            -- Output Data Elements 
            -- ---------------------------------- 
           p_employee_number                => rec.employee_number, 
           p_object_version_number          => REC.object_version_number, 
           p_effective_start_date           => ld_effective_start_date, 
           p_effective_end_date             => ld_effective_end_date, 
           p_full_name                      => lc_full_name, 
           p_comment_id                     => ln_comment_id, 
           p_name_combination_warning       => lb_name_combination_warning, 
           p_assign_payroll_warning         => lb_assign_payroll_warning, 
           p_orig_hire_warning              => lb_orig_hire_warning 
    ); 
  
   COMMIT;
    dbms_output.put_line('uPDATED FOR-'||rec.object_version_number||'-Employee No-'||rec.employee_number); 
 --update xx_gosi_update set status='S-'||rec.emp_no where rowid=rec.rowid;
 commit;
     end loop;                       
     EXCEPTION 
         WHEN OTHERS THEN 
                      ROLLBACK; 
                      dbms_output.put_line(SQLERRM); 
END; 

Tuesday, February 2, 2016

Create User and Create Responsibility Using Script

CREATE TABLE APPS.XX_CREATE_USER
(
  EMP_NO         VARCHAR2(100 BYTE),
  USER_NAME      VARCHAR2(240 BYTE),
  EMAIL          VARCHAR2(240 BYTE),
  STATUS         VARCHAR2(240 BYTE),
  ERROR_MESSAGE  VARCHAR2(2000 BYTE)
)


CREATE OR REPLACE PROCEDURE APPS.XX_CREATE_FNDUSER (errbuf out varchar2, rectcode out varchar2)
AS
   lc_user_name                      VARCHAR2(100);
   lc_user_password                  VARCHAR2(100)   := 'aaa123';
   ld_user_start_date                DATE            := sysdate;
   ld_user_end_date                  VARCHAR2(100)   := NULL;
   ld_password_date                  VARCHAR2(100)   := sysdate; -- TO_DATE('23-JUN-2012');
   ld_password_lifespan_days         NUMBER          := 90;
   ln_person_id                      NUMBER       ;
   lc_email_address                  VARCHAR2(240);
   v_session_id                      integer := userenv('sessionid');

    CURSOR c1
   IS
   
      SELECT a.rowid,a.*
        FROM XX_CREATE_USER a        
        WHERE 1=1
        --AND NVL(STATUS,'E') ='E'
        AND A.EMP_NO not  IN
        --AND A.user_name   IN
        (SELECT PPF.EMPLOYEE_NUMBER
        --(SELECT fu.user_name
            FROM
            per_all_people_f PPF
            ,FND_USER FU
            --,XXDFC_CREATE_USER XXU
            WHERE 1=1
            AND PPF.PERSON_ID=FU.EMPLOYEE_ID
            --AND XXU.EMP_NO(+)=PPF.EMPLOYEE_NUMBER
            AND SYSDATE BETWEEN PPF.EFFECTIVE_START_DATE AND PPF.EFFECTIVE_END_DATE
          )
          --and a.emp_no in('S00722','S02016','E02148','E01530')
          --and a.emp_no !='C0249'
        ;
       
BEGIN

   FOR REC IN C1
   LOOP
   BEGIN
   select PERSON_ID
   INTO ln_person_id
   from per_all_people_f WHERE 1=1
   AND SYSDATE BETWEEN EFFECTIVE_START_DATE AND EFFECTIVE_END_DATE
   AND upper (ltrim (rtrim (EMPLOYEE_NUMBER))) = upper (ltrim (rtrim (REC.EMP_NO)))
   ;
   END;

--If you Enable  x_password_date  in below code, it is not asking to change password while login first time in application

   fnd_user_pkg.createuser
    (  x_user_name              => REC.USER_NAME,
     x_owner                    => NULL,
     x_unencrypted_password     => lc_user_password,
     x_session_number           => v_session_id,
     x_start_date               => ld_user_start_date,
     x_end_date                 => ld_user_end_date,
     --x_password_date            => ld_password_date,
     x_password_lifespan_days   => ld_password_lifespan_days,
     x_employee_id              => ln_person_id,
     x_email_address            => rec.email
    );
   
    IF ln_person_id IS NOT NULL THEN

    UPDATE XXDFC_CREATE_USER SET STATUS='S' where rowid=rec.rowid;
    ELSE
   
   
        UPDATE XXDFC_CREATE_USER SET STATUS='E' where rowid=rec.rowid;
        END IF;
        END LOOP;
       
    COMMIT;

END;
/

-/**************************Create Responsibility for the exist user for the above code ******************************************************/

CREATE TABLE APPS.XX_CREATE_RESP_STG
(
  EMP_NO               VARCHAR2(100 BYTE),
  USER_NAME            VARCHAR2(240 BYTE),
  RESPONSIBILITY_NAME  VARCHAR2(240 BYTE),
  STATUS               VARCHAR2(240 BYTE),
  ERROR_MESSAGE        VARCHAR2(2000 BYTE)
)


CREATE OR REPLACE PROCEDURE APPS.XX_CREATE_RESP (errbuf out varchar2, rectcode out varchar2)
AS
v_user_name varchar2(240);
v_resp varchar2(240);
v_resp_key varchar2(240);
v_app_short_name varchar2(240);

CURSOR C1 IS

SELECT rownum,a.rowid,UPPER(a.EMP_NO)EMP_NO,UPPER(A.USER_NAME)USER_NAME,A.RESPONSIBILITY_NAME,A.STATUS,A.ERROR_MESSAGE
        FROM XX_CREATE_RESP_STG a        
        WHERE 1=1
        AND NVL(STATUS,'E') ='E'
        --AND EMP_NO IN('S02225','S02224')
        ORDER BY EMP_NO
        ;
       
/*select rownum,a.rowid,UPPER(a.EMP_NO)EMP_NO,UPPER(A.USER_NAME)USER_NAME,A.RESPONSIBILITY_NAME,A.STATUS,A.ERROR_MESSAGE
FROM XX_CREATE_RESP_STG a where upper(a.user_name)  in(
SELECT distinct upper(fu.user_name)
  FROM fnd_user_resp_groups_direct        furg,
       applsys.fnd_user                   fu,
       applsys.fnd_responsibility_tl      frt,
       applsys.fnd_responsibility         fr,
       applsys.fnd_application_tl         fat,
       applsys.fnd_application            fa
 WHERE furg.user_id             =  fu.user_id
   AND furg.responsibility_id   =  frt.responsibility_id
   AND fr.responsibility_id     =  frt.responsibility_id
   AND fa.application_id        =  fat.application_id
   AND fr.application_id        =  fat.application_id
   AND frt.language             =  USERENV('LANG')
   )
   --and a.emp_no in('E00011') --,'S02173')
   ---and rownum <10 --and="" nbsp="" p="" rownum=""> 
   ;        */

BEGIN

   FOR REC IN C1
   LOOP
 
   v_resp_key :=null;
   v_app_short_name :=null;
 
   /*BEGIN
 
   SELECT distinct FU.USER_NAME
   INTO v_user_name
            FROM
            per_all_people_f PPF
            ,FND_USER FU
            --,XXDFC_CREATE_USER XXU
            WHERE 1=1
            AND PPF.PERSON_ID=FU.EMPLOYEE_ID
            --AND XXU.EMP_NO(+)=PPF.EMPLOYEE_NUMBER
            AND SYSDATE BETWEEN PPF.EFFECTIVE_START_DATE AND PPF.EFFECTIVE_END_DATE  
            --AND PPF.EMPLOYEE_NUMBER IN('S00015','S00024','S00064')
            AND UPPER(PPF.EMPLOYEE_NUMBER)= upper (ltrim (rtrim (REC.EMP_NO)))            
            ;
            END;*/
           
        BEGIN
        select
            r.responsibility_key ,
            a.application_short_name
          into v_resp_key,v_app_short_name
          from fnd_responsibility_vl r,
            fnd_application_vl a
          where
            r.application_id =a.application_id
            and upper(r.responsibility_name) = upper(TRIM(REC.RESPONSIBILITY_NAME));
        END;
       
        DBMS_OUTPUT.put_line ('v_resp_key-'||v_resp_key||' '||'v_app_short_name-'||v_app_short_name||'-REC.RESPONSIBILITY_NAME');
       
        fnd_user_pkg.AddResp (
          username => rec.user_name, --v_user_name,
          resp_app => 'PER', --v_app_short_name,
          resp_key => v_resp_key,
          security_group => 'STANDARD',
          description => null,
          start_date => sysdate,
          end_date => null
          );
          COMMIT;
          UPDATE XX_CREATE_RESP_STG SET STATUS='S' where rowid=rec.rowid;
          END LOOP;
            EXCEPTION
            when others then
          DBMS_OUTPUT.put_line ('Unable to add the responsibility due to'||SQLCODE||' '||SUBSTR(SQLERRM, 1, 100));
          FND_FILE.put_line(FND_FILE.output,'Error in Calling Receipt API'||SQLCODE||' '||SUBSTR(SQLERRM, 1, 100));
          rollback;
          END;
/