CSVImportHelp

From OrangeHRM

Jump to: navigation, search

Contents

CSV Import Feature in OrangeHRM (Introduced in version 2.2.3)

Introduction

OrangeHRM 2.2.3 Introduces a CSV Import feature. This allows you to upload bulk data into the OrangeHRM system from a Comma Separated Value file.

Custom Import Definitions

In order to import CSV data into OrangeHRM, you need to create an Import definition. This defines the format of the CSV file:

  1. The fields (columns) in the CSV file
  2. Order of the columns in the CSV file
  3. Whether the CSV file contains an header.

Sample CSV file

The CSV file below contains an header row.

First Name, Last Name, Middle Name, Employee ID, Work Email, Birth Date, Street1, Street2, City, ZIP
Kamal, Ranasinghe, S, A229, kamal@example.com, 12-20-1978, "22/1, Main Street", Apt 11, Colombo, 19191
John, Amarasena, , , , , ,,,

Note that

  1. Some fields may be left empty
  2. Fields containing comma's and double quotes should be escaped properly as required for CSV files

CSV File format

The CSV file can have an optional header row. The header row will contain the names of the columns in the file. This row is optional, and OrangeHRM simply ignores this and doesn't attempt to read or validate this row.

The rest of the rows in the CSV file contain data. Each of these rows should contain details on one New employee. If the name of the employee matches an existing employee in the system, that row will not be imported.

View existing custom Import definitions

Existing import definitions in the system can be accessed by clicking on the menu item 'Data Import/Export' -> 'Define Custom Import' under the Admin tab. From this page, you can add/delete/edit Import definitions.

Adding/Editing Import definitions

After giving a name to the import definition, you can specify whether it contains a header.

The fields contained in the CSV file need to be added to the Assigned Fields list by selecting from the Available Fields list and clicking Add >.

Note that some fields are compulsary, and cannot be removed from the Assigned Fields list.

You can change the order of fields in the CSV file, by selecting the field from the Assigned Fields list and clicking on the up/down arrows.

Importing CSV Data =

  • Go to the menu 'Data Import/Export' -> 'Import' and select from the available import definitions.
  • Browse and select a CSV file and click Import.
  • Once the import is complete, the status of the import with any errors will be shown
  • Note that OrangeHRM performs some validation of input data and any rows with problems will be skipped.

Defining Import Plugins (Advanced)

If the functionality given by the custom import definitions above is not sufficient, it is possible to define import plugins by writing PHP code.

Note that this requires knowledge of PHP programming. The following steps have to be followed (All directories are relative to OrangeHRM installation directory:

  1. Write a PHP Class that implements the interface CSVImportPlugin (located at lib/models/eimadmin/CSVImportPlugin.php)
    1. You will need to implement the following functions in this interface
      1. public function getName()
        1. Can return a Name that can be used to identify this particular plugin.
      2. public function getNumHeaderRows()
        1. Return the number of header rows in the CSV file. All these rows will be ignored in import. Set to zero if no header rows.
      3. public function getNumColumns()
        1. Get the number of columns expected in CSV file.
      4. public function importCSVData($dataRow)
        1. This function is called once for each data row in CSV file. The $dataRow array is populated with the values in each column for that row.
        2. Inside this function, write the code needed to work with the imported data.
  2. Copy the file to lib/models/eimadmin/plugins directory.
  3. A new option will be available in the 'Import Type' drop down in the CSV Import page.
  4. Select this option to import files using the new plugin.
Personal tools