Skip to main content
Version: 1.23.3

SimpleRecord Client-Side

This class provides methods for managing the database in client-side scripts: auto population of the fields, displaying some form elements and setting mandatory attribute for them regarding the values set in the Reference Fields.

The SimpleRecord client class allows a user to manage both records in the tables and its fields.

In this class, client-side queries are executed on the server. That is, to get a record data, a request from the client side should be sent to the server.

The functionality of the client-side SimpleRecord class might be not enough for managing some business tasks. In this case, use the SimpleAjax class or Table API.

addQuery(field, operator, value)


Use this method to filter the records by specifying certain conditions (field, operator, value). You can also add a condition to get records with a field equal to the value or that is in the list.

In this method, you can use any required operator from the condition operators list, specified in lower- or uppercase. Use the system names of the operators in the scripts.

Use the following operators without a value:

  • ISEMPTY
  • ISNOTEMPTY
  • ANYTHING
  • VALCHANGES
  • IN (you can also use it with a value)
  • NOT IN (you can also use it with a value)
  • NOTHING

Parameter(s):

NameTypeMandatoryDefault value
fieldStringYN
operatorStringNN
valueInteger/String/Boolean/ArrayYN

Return:

TypeDescription
VoidThis method does not return a value.

Example:

addQuery()
const record = new SimpleRecord('task');
record.addQuery('number', 'like', 'TSK');
record.addQuery('subject', 'startswith', 'Email');
record.query(() => {
while (record.next()) {
console.log(record.number); // TSK0000128
}
});

deleteRecord(responseFunction)


Use this method to delete the current record.

Parameter(s):

NameTypeMandatoryDefault value
responseFunctionFunctionNN

Return:

TypeDescription
VoidThis method does not return a value.

Example:

deleteRecord()
const taskRecord = new SimpleRecord('task');
taskRecord.get('123456789012345678', () => {
taskRecord.deleteRecord(callback);
});

function callback(response) {
const answer = response.responseXML.documentElement.getAttribute('answer');
if (answer == '1') {
console.log('Record deleted');
} else {
console.log(answer);
}
}

get(recordId, callback)


Use this method to load an object from a database based on its ID.

Parameter(s):

NameTypeMandatoryDefault value
recordIdStringYN
callbackFunctionYN

Return:

TypeDescription
VoidThis method does not return a value.

Example:

get()
const record = new SimpleRecord('user');
record.get(s_user.userID, () => {
console.log(record.email); // admin@admin.ru
});

getRows()


Use this method to receive an array of records that contain column-value pairs.

Return:

TypeDescription
Array of StringsThis method returns an array of records.

Example:

getRows()
const record = new SimpleRecord('sys_db_table');
record.addQuery('is_vcs_enabled', 'IS', true);
record.query();
record.getRows();

getTableName()


Use this method to return a name of the current table.

Return:

TypeDescription
StringThis method returns the table name value.

Example:

getTableName()
const record = new SimpleRecord('user');
record.get(s_user.userID, () => {
console.log(record.getTableName()); // user
});

hasNext()


Use this method to define whether a selection contains other records.

Return:

TypeDescription
BooleanThis method returns true if there are some more records; otherwise, it returns false.

Example:

hasNext()
const record = new SimpleRecord('user');
record.get(s_user.userID, () => {
console.log(record.hasNext()); // true
});

insert(responseFunction)


Use this method to insert a new record.

Parameter(s):

NameTypeMandatoryDefault value
responseFunctionFunctionYN

Return:

TypeDescription
VoidThis method does not return a value.

Example:

insert()
const newRecord = new SimpleRecord('task');
newRecord.subject = 'Client-side insert';
newRecord.insert((response) => {
const answer = response.responseXML.documentElement.getAttribute('answer');
console.log(answer);
})

next()


Use this method to move to the next record.

Return:

TypeDescription
BooleanThis method returns false if there are no more records in the query set.

Example:

next()
const record = new SimpleRecord('task');
record.addQuery('number', 'like', 'TSK');
record.addQuery('subject', 'startswith', '[SWD-10]');
record.query(() => {
while (record.next()) {
console.log(record.number); // TSK0000128
}
});

orderBy(column)


Use this method to specify a column to order by. To order by multiple columns, call the method several times.

Parameter(s):

NameTypeMandatoryDefault value
columnStringYN

Return:

TypeDescription
VoidThis method does not return a value.

Example:

orderBy()
const record = new SimpleRecord('task');
record.addQuery('number', 'like', 'TSK');
record.orderBy('number');
record.query(() => {
while (record.next()) {
console.log(record.number); // >TSK0000128 >TSK0000129 >TSK0000130 ...
}
});

query(responseFunction, property, value, ...)


Use this method to execute a query taking 0 or more parameters in any order. It takes any pair of literals as a query pair (field: value) and any function as a response function.

Do not make synchronous query calls. The call becomes synchronous if a query is performed without a response function. In this case, the state of the object does not change.

Parameter(s):

NameTypeMandatoryDefault value
responseFunctionFunctionNN
propertyStringNN
valueAnyNN

Return:

TypeDescription
VoidThis method does not return a value.

Example:

query()
const record = new SimpleRecord('user');
record.addQuery('sys_id', s_user.userID);
record.query(() => {
if (record.next()) {
console.log(record.email); // admin@admin.ru
}
});

setLimit(maxQuery)


Use this method to define the number of records in the query.

Parameter(s):

NameTypeMandatoryDefault value
maxQueryIntegerYN

Return:

TypeDescription
VoidThis method does not return a value.

Example:

setLimit()
const record = new SimpleRecord('task');
record.addQuery('number', 'like', 'TSK');
record.orderBy('sys_created_at'); // the very first record
record.setLimit(1);
record.query(() => {
while (record.next()) {
console.log(record.number); // TSK0000002
//...
}
});

setValue(fieldName, value)


Use this method to define a value for the field.

Parameter(s):

NameTypeMandatoryDefault value
fieldNameStringYN
valueStringYN

Return:

TypeDescription
VoidThis method does not return a value.

Example:

setValue()
const record = new SimpleRecord('task');
record.setValue('subject', 'Another type of prop assignement');
record.insert((response) => {
const answer = response.responseXML.documentElement.getAttribute('answer');
console.log(answer);
})