This server class provides methods to operate with database records.
This method appends a 2-or-3 parameter OR condition to an existing query. It works in conjunction with any of the addQuery() methods.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
property | String | Y | N |
operatorOrValue | Choice (=, Like), etc. | Y | N |
operatorOrValue | Mixed | Y | N |
value | Mixed | N | NULL |
Return:
Type | Description |
---|
SimpleRecord | An object performing the request to the method. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | addOrCondition |
---|
linenumbers | true |
---|
|
let incident = new SimpleRecord('incident');
incident.addQuery('contact_type', 'email').addOrCondition('number', 'INC0000006');
incident.query(); |
This method adds a condition for the selection from the database.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
property | String | Y | N |
operatorOrValue | Choice (=, Like), etc. | Y | N | Mixed | N | operatorOrValue | Mixed | Y | N |
value | Mixed | N | NULL |
Return:
Type | Description |
---|
SimpleRecord | An object performing the request to the method. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | addQuery |
---|
linenumbers | true |
---|
|
let incident = new SimpleRecord("incident");
incident.addQuery( "active", true );
incident.addQuery( "subject" , "LIKE" , "сеть" );
incident.addQuery( "sys_created_at" , "<" , "2019-04-01 00:00:00" );
incident.query(); |
Adds encoded query to other queries already created.
Parameter(s)
Name | Type | Mandatory | Default Value |
---|
condition | String | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | addEncodedQuery |
---|
linenumbers | true |
---|
|
let incident = new SimpleRecord('incident');
incident.addEncodedQuery('active=1'); |
This method determines if the Access Control Rules permit inserting new records in this table.
Return:
Type | Description |
---|
Boolean | The method returns TRUE if this operation is permitted; otherwise it returns FALSE. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | canCreate |
---|
linenumbers | true |
---|
|
let incident = new SimpleRecord('incident');
ss.info( incident.canCreate() ); |
This method determines if the Access Control Rules permit deleting records in this table.
Return:
Type | Description |
---|
Boolean | The method returns TRUE if this operation is permitted; otherwise it returns FALSE. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | canDelete |
---|
linenumbers | true |
---|
|
let incident = new SimpleRecord('incident');
ss.info( incident.canDelete() ); |
This method determines if the Access Control Rules permit reading records in this table.
Return:
Type | Description |
---|
Boolean | The method returns TRUE if this operation is permitted; otherwise it returns FALSE. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | canRead |
---|
linenumbers | true |
---|
|
let incident = new SimpleRecord('incident');
ss.info( incident.canRead() ); |
This method determines if the Access Control Rules permit updating records in this table.
Return:
Type | Description |
---|
Boolean | The method returns TRUE if this operation is permitted; otherwise it returns FALSE. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | canUpdate |
---|
linenumbers | true |
---|
|
let incident = new SimpleRecord('incident');
ss.info( incident.canUpdate() ); |
This method allows deleting multiple records that meet the query condition. It does not allow deleting attachments.
Do not use it on tables with dependencies. Always delete each record individually.
Also, do not use it combined with the setLimit() method when working with large tables.
Do not use the deleteMultiple() method on the tables with the currency fields. Always delete each record individually. Also, do not use this method with the chooseWindow() or setLimit() methods when working with large tables.
Return:
Type | Description |
---|
Boolean | This method returns TRUE if deleted successfully; otherwise returns false. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | deleteMultiple |
---|
linenumbers | true |
---|
|
let incident = new SimpleRecord('incident');
incident.addQuery( 'subject' , "LIKE" , "network" );
incident.query();
incident.deleteMultiple(); |
This method deletes the current record.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
recordSetId | Integer | N | -1 |
Return:
Type | Description |
---|
Boolean | This method returns TRUE if the record is deleted successfully; otherwise it returns FALSE. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | deleteRecord |
---|
linenumbers | true |
---|
|
let incident = new SimpleRecord('incident');
incident.get(5236);
incident.deleteRecord(); |
This method loads an object from a database based on the field value, or, in a specific case, by the sys_id.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
propertyOrValue | name (value must be specified as well). | Y | N |
propertyOrValue | mixed | Y | N |
value | mixed | N | NULL |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | get |
---|
linenumbers | true |
---|
|
let incident = new SimpleRecord("incident");
incident.get( "subject" , "Network does not work" ) |
This method returns an object with current record properties as keys and properties values as key values.
Return:
Type | Description |
---|
Object | The array containing attributes. |
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getAttributes |
---|
linenumbers | true |
---|
|
const rec = new SimpleRecord('sys_db_table');
rec.get(some_id);
const attrs = rec.getAttributes();
// attrs = {sys_id: some_id, title: "My title", name: "my_name", ...} |
This method returns the table title. If the title is not set, then returns name.
Return:
Type | Description |
---|
String | Title or name. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getClassDisplayValue |
---|
linenumbers | true |
---|
|
let incident = new SimpleRecord("incident");
ss.info( incident.getClassDisplayValue() ); |
This method returns displayed field or record value (the display_by_ref field). For example, for the reference field the entity name will be returned, but not the ID.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
Property | String | N | NULL |
Return:
Type | Description |
---|
Mixed | A field or record value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getDisplayValue |
---|
linenumbers | true |
---|
|
let incident = new SimpleRecord("incident");
incident.get(5236);
ss.info( incident.getDisplayValue( "caller_id" ) ); |
If the record creating, updating or deleting will fail, then this method will display error message.
Return:
Type | Description |
---|
Array | The error value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getErrors |
---|
linenumbers | true |
---|
|
let rec = new SimpleRecord('sys_db_table');
rec.get('name', 'task');
if (!rec.deleteRecord()) {
let errors = rec.getErrors();
errors.forEach(function(error) {
ss.addErrorMessage(error);
})
} |
This method returns the field title.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
property | String | Y | N |
Return:
Type | Description |
---|
Mixed | The field title. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getLabel |
---|
linenumbers | true |
---|
|
let incident = new SimpleRecord("incident");
incident.get(5236);
ss.info( incident.getLabel( "caller_id" ) ); |
This method returns the current table name.
Return:
Type | Description |
---|
String | The current table name. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getTableName |
---|
linenumbers | true |
---|
|
let incident = new SimpleRecord('incident');
ss.info( incident.getTableName() ); // incident |
This method returns the value of the object property based on its name.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
Property | String | Y | N |
Return:
Type | Description |
---|
Mixed | The value of the field. Tip |
---|
The value from the database will be returned for the reference fields. |
|
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getValue |
---|
linenumbers | true |
---|
|
const record = new SimpleRecord('task');
record.get('15000000000001');
ss.info(record.getValue('assigned_user')); // 150000000534521234 |
This method creates a database record.
Return:
Type | Description |
---|
Integer | The Sys_id of the record created. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | insert |
---|
linenumbers | true |
---|
|
let incident = new SimpleRecord('incident');
incident.insert(); |
This method checks whether the current record meets the condition being in the current state.
Name | Type | Mandatory | Default Value |
---|
condition | String | N | '' |
Type | Description |
---|
Void | This method does not return a value. |
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | matchesCondition |
---|
linenumbers | true |
---|
|
rec.description = 'dsc';
rec.matchesCondition('descriptionLIKEesc'); // false
rec.description = 'desc';
rec.matchesCondition('descriptionLIKEesc'); // true |
If this is a new request, then this method returns the first record from the list; otherwise it returns FALSE, in the case if the record is unavailable.
Return:
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | next |
---|
linenumbers | true |
---|
|
let incident = new SimpleRecord("incident");
incident.query();
while ( incident.next() ){
ss.info( incident.sys_id);
} |
This method sorts records in the ascending order.
Tip |
---|
Call this method several times to order by multiple columns. |
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
column | String | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | orderBy |
---|
linenumbers | true |
---|
|
let incident = new SimpleRecord('incident');
incident.orderBy('subject');
incident.query(); |
This method sorts the records in the descending order.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
column | String | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | orderByDesc |
---|
linenumbers | true |
---|
|
let incident = new SimpleRecord('incident');
incident.orderByDesc('subject');
incident.query(); |
This method runs a query against the selection from the database, based on the $this→query. After this, it fills in the record set.
Return:
Type | Description |
---|
Void | This method does not return a value. |
This method is intended to optimize database queries. Sometimes, it is necessary to obtain only several object fields, not the whole object, Therefore, this method is added.
Name | Type | Mandatory | Default Value |
---|
attributes | String or Array | Y | N |
Return:
Type | Description |
---|
SimpleRecord object | This method returns a SimpleRecord object containing attributes. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | selectAttributes |
---|
linenumbers | true |
---|
|
const record = new SimpleRecord('user');
record.selectAttributes(['email']);
record.query();
while (record.next()) {
ss.info(record.email); // not null
ss.info(record.first_name); // null
ss.info(record.username); // null
... // other fields are null
} |
This method sets a flag, indicating that will be current operation (insert/update/delete) interrupted. It used in business-rules.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
flag | Boolean | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | setAbortAction |
---|
linenumbers | true |
---|
|
current.setAbortAction(true); |
Sets a limit for a number of records are fetched by SimpleRecord query.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
maxNumRecords | Integer | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | setLimit |
---|
linenumbers | true |
---|
|
let incident = new SimpleRecord('incident');
incident.setLimit(30);
incident.query(); |
This method sets the properties values for every entry in the current selection.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
property | String | Y | N |
value | Mixed | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | setMultipleValue |
---|
linenumbers | true |
---|
|
const rec = new SimpleRecord('task');
rec.addQuery('state', 'Created');
rec.query();
rec.setMultipleValue('state', 'Confirmed');
rec.updateMultiple(); |
This method sets the value of the field in the current record.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
property | String | Y | N |
value | Mixed | Y | N |
Return:
Type | Description |
---|
Void | This property does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | setValue |
---|
linenumbers | true |
---|
|
let incident = new SimpleRecord('incident');
incident.setValue("subject" , "Help me");
incident.insert(); |
This method is intended to update the record without executing any entities related to this record implementing the business logic, such as business rules, notifications, workflows, etc.
Name | Type | Mandatory | Default Value |
---|
enable | Boolean | Y | N |
Type | Description |
---|
Void | This property does not return a value. |
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | silentMode |
---|
linenumbers | true |
---|
|
let record = new SimpleRecord('task');
record.query();
record.next();
record.silentMode();
record.update(); |
This method updates a database record.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
reason | String | N | '' |
Return:
Type | Description |
---|
Integer | Sys_id of the updated record. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | update |
---|
linenumbers | true |
---|
|
let incident = new SimpleRecord('incident');
incident.get(5246);
incident.subject += " (repair)";
incident.update(); |
This method updates all the selection entries.
Return:
Type | Description |
---|
Void | This property does not returns a value. |
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | updateMultiple |
---|
linenumbers | true |
---|
|
const rec = new SimpleRecord('task');
rec.addQuery('state', 'Created');
rec.query();
rec.setMultipleValue('state', 'Confirmed');
rec.updateMultiple(); |