Skip to content

ExecuteNonQuery

Creates a connection to the relevant system with the information defined on the domain and runs the query. Returns the number of affected rows.

1
$Database.ExecuteNonQuery(connectionName: string, query: string, parameters?: object, timeout?: number):number

Parameters

string connectionName
    The name of the external database connection.

string query
    The query to be run.

object parameters optional
    An object containing parameters for the query. Optional.

number timeout optional
    The request timeout in seconds. Optional.

Returns

The number of rows affected by the query.

Remarks

This method is used to run a query on an external database. The connection name is defined in the domain settings with a connection string to the database.

The query dialect is based on the external database type and is directly executed on the database. Use the parameter syntax of that database and pass values through parameters.

The timeout parameter is used to specify the maximum time to wait for the query to execute. If not specified, the default timeout is used.

Examples

Update rows in an external database

1
2
3
4
5
6
7
8
var affected = $Database.ExecuteNonQuery('ErpDatabase', 'update Orders set Status = @Status where Id = @Id', {
    Status : 'Approved',
    Id : $Xml.Evaluate('ErpOrderId')
});

if (affected === 0) {
    throw new Error('Order ' + $Xml.Evaluate('ErpOrderId') + ' was not found in the ERP database.');
}

See Also