Skip to content

Information

This page describes the employee payroll records and documents usage.

Employee Payroll Records Layout

Field 1 Field 2 Field 3 Field 4
Employee Number Employee Name Hourly Wage Hours Worked

Using the Employee Payroll Records

  • The records are made available to your programs with this function:
openEmployeePayrollRecords();
  • The function returns the records so you need to store them in a variable:
let records;
records = openEmployeePayrollRecords();
  • After the openEmployeePayrollRecords() function has been run you have access to the first record's data. You will retrieve each part of one record with a different function. Here are the functions:
records.getEmployeeNumber();
records.getEmployeeName();
records.getEmployeeHourlyWage();
records.getEmployeeHoursWorked();
  • Notice that you need to have "records." in front of each of the functions.

  • When you want to read the next record you use the following function. It will make the next record available and you then use the above functions to retrieve the data. This function returns true if there was a next record and false if the end of the record set has been reached.

records.readNextRecord();

Example Usage

Here's an example of how the Employee Payroll Records are used.

/*
    This is file /unit5/employeePayrollRecords.js
    It contains the JavaScript code for

    "Employee Payroll Records" File: /unit5/employeePayrollRecords.html
*/
function employeePayrollRecords() {
    "use strict";

    // Variable Declarations
    let employeeNumber;
    let employeeName;
    let hourlyWage;
    let hoursWorked;
    let records;
    let outputTable;
    let outputRows;

    // Get the HTML output table so we can add rows
    outputTable = document.getElementById("outputTable");

    // build table header
    outputRows = "<tr><th>Employee<br />Number</th>"
            + "<th>Employee<br />Name</th>"
            + "<th>Hourly<br />Wage</th>"
            + "<th>Hours<br />Worked</th></tr>";

    // Open the Employee Payroll Records and make them
    // available to the script
    records = openEmployeePayrollRecords();

    // Test to see if there is a next record and then output it
    while (records.readNextRecord()) {
        employeeNumber = records.getEmployeeNumber();
        employeeName = records.getEmployeeName();
        hourlyWage = records.getEmployeeHourlyWage();
        hoursWorked = records.getEmployeeHoursWorked();

        // build employee payroll row
        outputRows += "<tr><td>"
                + employeeNumber
                + "</td><td>"
                + employeeName
                + "</td><td>"
                + hourlyWage.toFixed(2)
                + "</td><td>"
                + hoursWorked.toFixed(1)
                + "</td></tr>";
    }

    // output all table rows
    outputTable.innerHTML = outputRows;
}

Employee Payroll Records Data