This class is used to operate a database by providing ways to use some of the functional capabilities of 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, for example, UI policy scripts.In SimpleRecord API, records and fields are included.
In this class, client-side queries execute are executed on the server. That is, to get the a record data, perform the a request from the client browser.side should be sent to the server.
The functionality of Scoped applications do not provide the client-side SimpleRecord . Create an include script instead or use API RESTclass can be not enough for managing some business tasks. In this case, use the SimpleAjax class or Table API.
addQuery()
Using Use this method , you can to filter the records by specifying certain conditions (field, operator, value). Also, this method can return records having You can also add a condition to get records with a field equal to the value (, or that is in the list of the values).?
Within this method, you can it is possible to use any preferred operator from the Condition Operators list. Please notice that you need to use condition operator. Notice that it is necessary to use the system name of the operator in your scripts.the script.
Parameters:
Name | Type | Mandatory | Default value |
---|
property | String | Y | N |
operator | String | N | N |
value | Integer/String/Boolean/Array | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | addQuery |
---|
linenumbers | true |
---|
|
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 Use this method , to delete the current record.
Parameter(s):
Valuevalue |
---|
responseFunction | Function | N | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | deleteRecord |
---|
linenumbers | true |
---|
|
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)
This Use this method loads to load an object from a database , based on the field valueits ID.
Parameter(s)Parameters:
ValueString (thesys_id value)String | Y | N |
callback | Function | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | get |
---|
linenumbers | true |
---|
|
const record = new SimpleRecord('user');
record.get(s_user.userID, () => {
console.log(record.email); // admin@admin.ru
}); |
getTableName()
This method gets Use this method to return a name of the current table name.
Return:
The This method returns the table name value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getTableName |
---|
linenumbers | true |
---|
|
const record = new SimpleRecord('user');
record.get(s_user.userID, () => {
console.log(record.getTableName()); // user
}); |
hasNext()
Using Use this method , you can to define whether the a selection contains any more other records.
Return:
Type | Description |
---|
Boolean | This method returns |
TRUE any some more records; otherwise, it returns |
FALSEExample:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | hasNext |
---|
linenumbers | true |
---|
|
const record = new SimpleRecord('user');
record.get(s_user.userID, () => {
console.log(record.hasNext()); // true
}); |
insert(responseFunction)
This method allows inserting Use this method to insert a new record.
Parameter(s):
Valuevalue |
---|
responseFunction | Function | Y | N |
Return:
String | Sys_id of the record createdVoid | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | insert |
---|
linenumbers | true |
---|
|
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 Use this method , you can to move to the next record.
Return:
Type | Description |
---|
Boolean | This method returns |
FALSE false if there are no more records in the query set. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | next |
---|
linenumbers | true |
---|
|
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 Use this method , you can specify an orderBy columnto specify a column to order by. To order by multiple columns, call the method several times.
Parameter(s):
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | orderBy |
---|
linenumbers | true |
---|
|
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(
callbackresponseFunction, property, value, ...)
This Use this method executes 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 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 responsethe state of the object does not change.
Parameter(s):
Valuevalue |
---|
responseFunction | Function |
YN | N |
property | String | N | N |
value | Any | N | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | query |
---|
linenumbers | true |
---|
|
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 Use this method , you can to define the number of records in the query.
Parameter(s):
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | setLimit |
---|
linenumbers | true |
---|
|
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)
Using Use this method , you can to define a value for the field.
Parameter(s):
Valuevalue |
---|
fieldName | String | Y | N |
value | String | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | setValue |
---|
linenumbers | true |
---|
|
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);
}) |