Write values into tables

/**
 * @param {Config} config
 * @param {Context} context
 * Do not edit this comment or parameter types. Required for code suggestions
*/
exports.main = function (config, context) {
    // LCOS: /Setup/WAN/DSL-Broadband-Peers
    var dslPeers = config.getTableByOid("1.2.2.19");

    var dslBackup = dslPeers.createNewRow();
    dslBackup.setByOid("1", "BACKUP");
    dslBackup.setByOid("3", "9999");
    dslBackup.setByOid("5", "DHCPOE");
    dslBackup.setByOid("15", "local");
    dslBackup.setByOid("17", "off");

    // insert changes
    dslPeers.addOrMerge(dslBackup);

};
  • <table>.createNewRow() creates a new row object in the script's memory.
  • <table>.addOrMerge() will add a new row if no matching index column in the given table exists, in the device's config. <table>.addOrMerge() will merge the data if a row with a matching index column already exists, in the device's config. This means, overwriting existing rows is handled by this step.


Read values from tables

/**
 * @param {Config} config
 * @param {Context} context
 * Do not edit this comment or parameter types. Required for code suggestions
*/
exports.main = function (config, context) {
    // LCOS: /Setup/WAN/DSL-Broadband-Peers
    var dslPeers = config.getTableByOid("1.2.2.19");

    var dslBackup = dslPeers.getRowBySingleIndex("BACKUP");
    dslBackup.setByOid("3", "8888");

    // update changes
    dslPeers.addOrMerge(dslBackup);
};
  • To get multiple matches you can use table.getRowsByAliases(Map<alias, value>).
    For example:
    // returns all rows with value `SH-Time` = 9999
    var rows = dslPeers.getRowsByOids({"5": "9999"});

Delete values from tables

/**
 * @param {Config} config
 * @param {Context} context
 * Do not edit this comment or parameter types. Required for code suggestions
*/
exports.main = function (config, context) {
    var table1_2_2_19 = config.getTableByOid("1.2.2.19");
    var table_1_2_2_19_row_2 = table1_2_2_19.createNewRow();            // delete INTERNET-DEFAULT
    table_1_2_2_19_row_2.setByOid(1, "INTERNET-DEFAULT");
    table_1_2_2_19_row_2.delete();
};