Skip to main content

Get records

Gets records from the selected table

Function GetRecords(Val Table, Val Fields = "*", Val Filters = "", Val Sort = "", Val Count = "", Val Connection = "", Val Tls = "") Export

ParameterCLI optionTypeRequiredDescription
Table--tableStringTable name
Fields--fieldsArray Of StringFields for selection
Filters--filterArray of StructureFilters array. See GetRecordsFilterStrucutre
Sort--orderStructure Of KeyAndValueSorting: Key > field name, Value > direction (ASC, DESC)
Count--limitNumberLimiting the number of received strings
Connection--dbcString, ArbitraryConnection or connection string
Tls--tlsStructure Of KeyAndValueTLS settings, if necessary. See GetTlsSettings

Returns: Map Of KeyAndValue - Result of query execution


1C:Enterprise/OneScript code example
    Address  = "127.0.0.1";
Login = "SA";
Password = "12we...";
Base = "testbase1";

TLSSettings = OPI_MSSQL.GetTlsSettings(True);
ConnectionString = OPI_MSSQL.GenerateConnectionString(Address, Base, Login, Password);

// All records without filters

Table = "testtable";

// When using the connection string, a new connection is initialised,
// which will be closed after the function is executed.
// If several operations are performed, it is desirable to use one connection,
// previously created by the CreateConnection function()
Result = OPI_MSSQL.GetRecords(Table, , , , , ConnectionString, TLSSettings);

// Filter, selected fields, limit and sorting

ConnectionString = OPI_MSSQL.GenerateConnectionString(Address, "test_data", Login, Password);

Table = "test_data";

Fields = New Array;
Fields.Add("first_name");
Fields.Add("last_name");
Fields.Add("email");

Filters = New Array;

FilterStructure1 = New Structure;

FilterStructure1.Insert("field", "gender");
FilterStructure1.Insert("type" , "=");
FilterStructure1.Insert("value", "Male");
FilterStructure1.Insert("union", "AND");
FilterStructure1.Insert("raw" , False);

FilterStructure2 = New Structure;

FilterStructure2.Insert("field", "id");
FilterStructure2.Insert("type" , "BETWEEN");
FilterStructure2.Insert("value", "20 AND 50");
FilterStructure2.Insert("raw" , True);

Filters.Add(FilterStructure1);
Filters.Add(FilterStructure2);

Sort = New Structure("ip_address", "DESC");
Count = 5;

Result = OPI_MSSQL.GetRecords(Table, Fields, Filters, Sort, Count, ConnectionString, TLSSettings);
    # JSON data can also be passed as a path to a .json file

oint mssql GetRecords \
--table "testtable" \
--dbc "Server=127.0.0.1;Database=***;User Id=SA;Password=***;" \
--tls "{'use_tls':true,'accept_invalid_certs':true}"
Result
{
"data": [
{
"bigint_field": 20000000000,
"bit_field": 1,
"date_field": "2025-07-14",
"datetime_field": "2025-07-14T11:12:57",
"dto_field": "2025-07-14T01:12:57.073372100+00:00",
"float24_field": 10.1234569549561,
"float53_field": 10.1234567891235,
"int_field": 200000,
"numeric_field": 5.333,
"nvarchar_field": "Some text",
"smallint_field": 2000,
"time_field": "11:12:57",
"tinyint_field": 5,
"uid_field": "68c5ab79-8481-4983-ab04-45558c8f1baa",
"varbinary_field": {
"BYTES": "/9j/4VTBRX..."
},
"xml_field": "<root><element><name>Example</name><value>123</value></element><element><name>Test</name><value>456</value></element></root>"
}
],
"result": true
}