Export (0) Print
Expand All

tables object

Updated: August 21, 2013

Provides functionality for working with specific tables as a table object instance.

This object contains the following members:

getTable

Syntax Returns Description

tables.getTable(tableName)

table object

Returns the specified tableName as a table object.

current

Syntax Returns Description

tables.current

table object

Returns the current table as a table object.

Call the getTable method on the global tables object to get a table object that represents a specific tableName.

The current property on the global tables object gets a table object that represents the current table.

The following script calls the getTable method to get the permissions table against which to execute queries.

function insert(item, user, request) {
    var permissionsTable = tables.getTable('permissions');

    permissionsTable.where({
        userId: user.userId,
        permission: 'submit order'
    }).read({
        success: function(results) {
            if (results.length > 0) {
                // Permission record was found. Continue normal execution.
                request.execute();
            } else {
                console.log('User %s attempted to submit an order without permissions.', user.userId);
                request.respond(statusCodes.FORBIDDEN, 'You do not have permission to submit orders.');
            }
        }
    });
}

The following script shows usage of the current property in validation logic.

function insert(item, user, request) {
    var currentTable = tables.current;
    currentTable.where({ name: item.name }).read({
        success: function (items) {
            if (items.length > 0) {
                request.respond(400, { error: 'Item with this name already exists' });
            } else {
                request.execute();
            }
        }
    });
}


Show:
© 2014 Microsoft