Inventory Item
Inventory Items Records Layout
Field 1 |
Field 2 |
Field 3 |
Item Number |
Item Description |
Item Stock Amount |
Using the Inventory Items Records
- The records are made available to your programs with this function:
openInventoryItemsRecords();
- The function returns the records so you need to store them in a variable:
| let itemRecords;
itemRecords = openInventoryItemsRecords();
|
* After the openInventoryItemsRecords() 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:
itemRecords.getItemNumber();
itemRecords.getItemDescription();
itemRecords.getItemStockAmount();
-
Notice that you need to have "itemRecords." 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.
itemRecords.readNextRecord();
Example Usage
Here's an example of how the Inventory Items Records are used.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 | /*
This is the JavaScript code for
"Inventory Items Records" File: /unit5/inventoryItemsRecords.html
*/
function inventoryItemsRecords() {
"use strict";
// Variable Declarations
let currentNumber;
let currentDescription;
let currentStockAmount;
let itemRecords;
let outputTable;
let outputRows;
// Get the HTML output table so we can add rows
outputTable = document.getElementById("outputTable");
// build table header
outputRows = "<tr><th>Item<br />Number</th>"
+ "<th>Item<br />Description</th>"
+ "<th>Item Stock<br />Amount</th></tr>";
// Open the Inventory Items Records and make them
// available to the script
itemRecords = openInventoryItemsRecords();
// Test to see if there is a next record and then output it
while (itemRecords.readNextRecord()) {
currentNumber = itemRecords.getItemNumber();
currentDescription = itemRecords.getItemDescription();
currentStockAmount = itemRecords.getItemStockAmount();
//build inventory row
outputRows += "<tr><td>" + currentNumber
+ "</td><td>" + currentDescription
+ "</td><td>" + currentStockAmount.toFixed(1)
+ "</td></tr>";
}
// output table rows
outputTable.innerHTML = outputRows;
}
|
Inventory Items Records Data