This class is used to operate a database by providing ways to use some of the functional capabilities of this class in client-side scripts, for example, UI policy scripts.
In SimpleRecord API, records and fields are included.
In this class, client-side queries execute on the server. That is, to get the record data, perform the request from the client browser.
Scoped applications do not provide the client-side SimpleRecord. Create an include script instead or use API REST.
addQuery()
Using this method, you can filter records by specifying certain conditions (field, operator, value). Also, this method can return records having a field equal to the value (or is in the list of the values).
Within this method, you can use any preferred operator from the Condition Operators list. Notice that you need to use the system name of the operator in your scripts.
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
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)
Using this method, delete the current record.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
responseFunction | Function | N | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
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('Запись удалена'); } else { console.log(answer); } }
get(recordId, callback)
This method loads an object from a database, based on the field value.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
recordId | String (the sys_id value) | Y | N |
callback | Function | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
const record = new SimpleRecord('user'); record.get(s_user.userID, () => { console.log(record.email); // admin@admin.ru });
getTableName()
This method gets the current table name.
Return:
Type | Description |
---|---|
String | The table name value. |
Example:
const record = new SimpleRecord('user'); record.get(s_user.userID, () => { console.log(record.getTableName()); // user });
hasNext()
Using this method, you can define whether the selection contains any more records.
Return:
Type | Description |
---|---|
Boolean | This method returns TRUE if there are any more records; otherwise, it returns FALSE. |
Example:
const record = new SimpleRecord('user'); record.get(s_user.userID, () => { console.log(record.hasNext()); // true });
insert(responseFunction)
This method allows inserting a new record.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
responseFunction | Function | Y | N |
Return:
Type | Description |
---|---|
String | Sys_id of the record created. |
Example:
const newRecord = new SimpleRecord('task'); newRecord.subject = 'Client-side insert'; newRecord.insert((response) => { const answer = response.responseXML.documentElement.getAttribute('answer'); console.log(answer); })
next()
Using this method, you can move to the next record.
Return:
Type | Description |
---|---|
Boolean | This method returns FALSE if there are no more records in the query set. |
Example:
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)
Using this method, you can specify an orderBy column. To order by multiple columns, call the method several times.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
Column | String | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
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(callback)
This method executes 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 display will not perform counting until it gets the query response.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
responseFunction | Function | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
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)
Using this method, you can define the number of records in the query.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
maxQuery | Integer | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
const record = new SimpleRecord('task'); record.addQuery('number', 'like', 'TSK'); record.orderBy('sys_created_at'); // very first record record.setLimit(1); record.query(() => { while (record.next()) { console.log(record.number); // TSK0000002 //... } });
setValue(fieldName, value)
Using this method, you can define a value for the field.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
fieldName | String | Y | N |
value | String | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
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); })