Table and field references

A table reference is a property on a JSDO instance that maps to a table in the resource being accessed after fill( ) is called. For example, if you call fill( ) on a SportsService with a CustomerOrders resource that has two tables, ttCustomer and ttOrders, the JSDO will have two table references named ttCustomer and ttOrders. The following example demonstrates how to populate and use table references:

// custOrders.ttCustomer and custOrders.ttOrders will be undefined before fill( ) is called.
custOrders.fill( ); 
custOrders.ttCustomer.foreach((customer) => {
    if (customer.data.Name === "Jim Robert") {
        customer.assign({State: "Missouri"});
    }
});
custOrders.ttOrders.foreach((order) => {
    if (order.data.OrderNum === 50052) {
        order.assign({OrderStatus: "Shipped"});
    }
});

In this example, the fill( ) method is called on the dsOrderEntry JSDO to load the available data for the Data Object resource into JSDO memory by calling the standard Data Object Read operation. Then, the foreach( ) method is called on the ttCustomer property of the JSDO to loop through all the record objects loaded from the ttCustomer temp-table, allowing each one to be accessed from within the function that is passed as a parameter.

You can access the data in each record object of a table reference using a field reference. A field reference is a property on a JSDO table reference that references a field in the current working record (if available) as specified by the schema of the resource table data model. Each field reference property has the name and data type of a field in the table schema and its current value in the working record.

The JSDO also supports access to the elements of one-dimensional array fields using either standard JavaScript subscripts on an array field reference or JSDO-defined array-element references. A JSDO array-element reference is an individual field reference property whose name consist of the array field name appended with a one-based integer that corresponds to each element of the array.

For more information on using table reference and field reference properties to access tables and fields in a JSDO, see the description of the table reference property (JSDO class).

A working record is the current record object that is implicitly available on a table reference after certain JSDO methods are called that set a working record. For more information on field references and working records, see Working records.