display.grid.getRecord()

display.grid.getRecord()

Description

display.grid.getRecord() retrieves a record from the grid by its relative record number (RRN). The record data is placed into the program's global fields, or into a data structure if one is passed, and is also returned as an object. It is the equivalent of the RPG CHAIN operation against a subfile, and the method can also be called as display.grid.chain().

After a successful call, display.found() returns true, the grid's RRN field (if one is defined) is set to the record number, and the record becomes the current record that display.grid.update() will update. If no record exists at the given RRN, display.found() returns false and an empty object is returned.

Syntax

display.gridName.getRecord(rrn) display.gridName.getRecord(rrn, dataStructure)

Parameters

  1. RRN (Number) - The 1-based relative record number of the record to retrieve. The first record in the grid is RRN 1.

  2. Data structure (Object, optional) - A Profound.js data structure reference. If specified, the referenced data structure is populated with the record data instead of the global fields. If the data structure is not qualified, wrap the parameter with the pjs.ds() API.

Return Value

Object - If the record is found, an object containing the record's fields as properties. The values are the raw stored values, so numeric fields are returned as strings. If the record is not found, an empty object {} is returned and display.found() returns false.

Retrieving a record with getRecord() clears the record's changed flag. A record that was changed by the user and then read with getRecord() will not be returned by a later display.grid.readChanged() loop.

Examples

Example 1: Retrieve a Record into the Global Fields

Reads record 7 of a subfile grid. When the record is found, the grid fields (product, description, quantity) hold the values from that record.

Prerequisite: a Rich Display File named subfiled.json with a control record format named ctl and a grid whose record format name is sfl, with the fields product, description, and quantity bound to its columns.

pjs.defineDisplay("display", "subfiled.json"); // ... load the grid records with display.sfl.write() here ... display.sfl.getRecord(7); // Retrieve the 7th record (RRN 7) into the global fields if (display.found()) { console.log("Product " + product + " has quantity " + quantity); } else { console.log("The grid has fewer than 7 records"); }

Example 2: Retrieve the Row the User Clicked and Update It

The grid's cursor record number property (the equivalent of SFLCSRRRN) returns the relative record number of the row the user clicked. The program retrieves that record, changes a field, and writes it back with update().

Prerequisite: a Rich Display File named subfiled.json with a control record format named ctl and a grid whose record format name is sfl, with the fields product, description, and quantity bound to its columns. The grid's cursor record number property is bound to a numeric field named csrrrn.

pjs.defineDisplay("display", "subfiled.json"); // ... load the grid records with display.sfl.write() here ... display.ctl.execute(); // Show the grid and wait for the user to click a row if (csrrrn > 0) { display.sfl.getRecord(csrrrn); // Retrieve the record the user clicked if (display.found()) { quantity = quantity + 1; // Change a field value... display.sfl.update(); // ...and update the record in the grid } } display.ctl.execute();

Example 3: Retrieve a Record into a Data Structure

Uses a data structure instead of the global fields, which keeps the record data separate from the rest of the program. The returned object can also be used directly.

Prerequisite: a Rich Display File named subfiled.json with a control record format named ctl and a grid whose record format name is sfl, with the fields product, description, and quantity bound to its columns.

pjs.defineDisplay("display", "subfiled.json"); // A qualified data structure with subfields that match the grid fields pjs.define("rec", { type: "data structure", qualified: true, elements: { "product": { type: "packed decimal", length: 5, decimals: 0 }, "description": { type: "char", length: 30 }, "quantity": { type: "packed decimal", length: 5, decimals: 0 } }}); // ... load the grid records here ... var record = display.sfl.getRecord(1, rec); // Populate the data structure with record 1 if (display.found()) { console.log(rec.description); // From the data structure console.log(record.description); // The same value from the returned object }

RPG Equivalent

CHAIN


Related Pages