The client SimpleRecord class enables a user to manage both records in the tables and fields of single records.
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 can be not enough for managing some business tasks. In this case, use the SimpleAjax class or Table API.
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 is in the list of values.
Within this method, it is possible to use any preferred operator from the Condition Operators list. Notice that it is necessary to use the system name of the operator in the script.
Parameters:
Name | Type | Mandatory | Default Value |
---|---|---|---|
property | String | Y | N |
operator | String (see Condition Operators) | N | N |
value | Integer / String / Boolean / Array | 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.addQuery('subject', 'startswith', 'Email'); record.query(() => { while (record.next()) { console.log(record.number); // TSK0000128 } }); |
Use this method to delete the current record.
Parameter:
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('Record deleted'); } else { console.log(answer); } } |
This method loads an object from a database, based on the its ID.
Parameters:
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 }); |
This method returns a name of the current table.
Return:
Type | Description |
---|---|
String | The table name value. |
Example:
const record = new SimpleRecord('user'); record.get(s_user.userID, () => { console.log(record.getTableName()); // user }); |
Use this method to define whether a selection contains other records.
Return:
Type | Description |
---|---|
Boolean | This method returns true if there are some more records; otherwise, it returns false. |
Example:
const record = new SimpleRecord('user'); record.get(s_user.userID, () => { console.log(record.hasNext()); // true }); |
Use this method to insert a new record.
Parameter:
Name | Type | Mandatory | Default Value |
---|---|---|---|
responseFunction | Function | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
const newRecord = new SimpleRecord('task'); newRecord.subject = 'Client-side insert'; newRecord.insert((response) => { const answer = response.responseXML.documentElement.getAttribute('answer'); console.log(answer); }) |
Use this method to 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 } }); |
Use this method to specify a column to order by. To order by multiple columns, call the method several times.
Parameter:
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 ... } }); |
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 does not perform counting until it gets the query response.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
responseFunction | Function | N | 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 } }); |
Use this method to define the number of records in the query.
Parameter:
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'); // the very first record record.setLimit(1); record.query(() => { while (record.next()) { console.log(record.number); // TSK0000002 //... } }); |
Use this method to 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); }) |