Monday, September 3, 2012

API to Create Vacancy Requisition


DECLARE
   l_object_version_number   NUMBER := NULL;
   l_vacancy_id              NUMBER := NULL;
   l_inv_pos_grade_warning   BOOLEAN := NULL;
   l_inv_job_grade_warning   BOOLEAN := NULL;
   l_requisition_id          NUMBER := NULL;
   l_position_id             NUMBER := NULL;
   l_job_id                  NUMBER := NULL;
   l_position                VARCHAR2 (2000) := NULL;
   l_pos_name                VARCHAR2 (2000) := NULL;
   l_position_type           VARCHAR2 (2000) := NULL;
   l_location_id             NUMBER := NULL;
   l_organization_id         NUMBER := NULL;
   l_grade_id                NUMBER := NULL;
   l_org_name                VARCHAR2 (2000) := NULL;
BEGIN
   INSERT INTO fnd_sessions
     VALUES   (USERENV ('sessionid'), SYSDATE);

   --create vacancy requisition for vacancy
   BEGIN
      per_requisitions_api.create_requisition (
         p_validate                => FALSE,
         p_business_group_id       => 44,
         p_date_from               => SYSDATE,
         p_name                    => 'IRCDUMMY',
         p_requisition_id          => l_requisition_id,
         p_object_version_number   => l_object_version_number
      );
      COMMIT;

      DBMS_OUTPUT.put_line ('Success creating req: ' || l_requisition_id);
   EXCEPTION
      WHEN OTHERS
      THEN
         DBMS_OUTPUT.put_line ('FAILURE req: ' || SQLERRM);
   END;

   l_object_version_number := NULL;

   -- get position to create vacancy
   BEGIN
      SELECT   hapf.position_type,
               hapf.position_id,
               hapf.job_id,
               hapf.location_id,
               hapf.organization_id,
               entry_grade_id,
               hr_general.decode_organization (hapf.organization_id),
               hapf.name
        INTO   l_position_type,
               l_position_id,
               l_job_id,
               l_location_id,
               l_organization_id,
               l_grade_id,
               l_org_name,
               l_pos_name
        FROM   hr_all_positions_f hapf
       WHERE   hapf.position_id = 21665 AND hapf.business_group_id = 44
               AND TRUNC (SYSDATE) BETWEEN hapf.effective_start_date
                                       AND  hapf.effective_end_date;
   EXCEPTION
      WHEN OTHERS
      THEN
         l_position_id := NULL;
         l_job_id := NULL;
         l_position := NULL;
         l_position_type := NULL;
         l_location_id := NULL;
         l_organization_id := NULL;
         l_grade_id := NULL;
         l_org_name := NULL;
   END;

   DBMS_OUTPUT.put_line ('l_requisition_id: ' || l_requisition_id);

   per_vacancy_api.create_vacancy (
      p_validate                => FALSE,
      p_effective_date          => SYSDATE,
      p_requisition_id          => l_requisition_id,
      p_date_from               => SYSDATE,
      p_name                    => 'IRCDUMMY',
      p_business_group_id       => 44,
      p_description             => 'Creating Dummy IRC for Local & International Recruitment',
      p_position_id             => l_position_id,
      p_job_id                  => l_job_id,
      p_grade_id                => l_grade_id,
      p_organization_id         => l_organization_id,
      p_number_of_openings      => 100,
      p_attribute7              => 'Internal',
      p_object_version_number   => l_object_version_number,
      p_vacancy_id              => l_vacancy_id,
      p_inv_pos_grade_warning   => l_inv_pos_grade_warning,
      p_inv_job_grade_warning   => l_inv_job_grade_warning
   );
   COMMIT;
   DBMS_OUTPUT.put_line ('Success creating vacancy: ' || l_vacancy_id);
EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.put_line ('FAILURE Vac: ' || SQLERRM);
END;

No comments:

Post a Comment