Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Overview

Adds or updates rows in DataTable and DataTableDictionary by specified key and properties .

( DataRow | Array<DataRow> ) myDataTableDictionary.Ensure(key: string, input: object)

Updates or creates a row with given input properties. If key does not exists initializes new row with initInput properties.

( DataRow | Array<DataRow> ) myDataTableDictionary.Ensure(key: string, input: object, initInput: object)

Arguments

string key
Required. Key of rows to be updated or added.
object input
Row properties to be updated.
object initInput
Row properties to be updated if no match found.

Remarks

initProperties argument used as to initialize a new row no matching row found in DataTable

This method inserts or updates rows in DataTable

Example

Code Block
languagejs
var table = $Database.Get({
    Parameters : {
        TargetSchema : 'HR',
        TargetTable : 'Groups'
    }
});

var list = table.ToDictionary('Name');

var myGroup = list.Ensure("MyGroup", {
    Name : 'MyGroup',
    Code : '123'
}, {
    Id : Script.NewId()
});

list.Save();