You are viewing an old version of this page. View the current version.
Compare with Current View Page History
« Previous Version 99 Next »
This server class provides methods to operate with database records.
SimpleRecord(tableName)
Instantiates a SimpleRecord class object for the table specified.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
tableName | String | N | '' |
Example:
const task = new SimpleRecord('task');
addOrCondition(property, operatorOrValue, value)
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 | Integer or String or Boolean (if this parameter is used as a value); String (if this parameter is used as an operator). | N | N |
value | Integer or String or Boolean | N | NULL |
Return:
Type | Description |
---|---|
SimpleRecord | The query containing OR condition added to the SimpleRecord object. |
Example:
const task = new SimpleRecord('task'); task.addQuery('subject', 'like', 'email').addOrCondition('description', 'like', 'email'); task.query();
addQuery(property, operatorOrValue, value)
This method adds a condition for the selection from the database. In this method, you can use any preferred operator from the Condition Operators list, specified either in lowercase or in uppercase.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
property | String | Y | N |
operatorOrValue | Integer or String or Boolean (if this parameter is used as a value); String (if this parameter is used as an operator). | N | N |
value | Integer or String or Boolean | N | NULL |
Return:
Type | Description |
---|---|
SimpleRecord | The query condition added to the SimpleRecord object. |
Example:
const task = new SimpleRecord('task'); task.addQuery('active', true); task.addQuery('subject', 'like', 'сеть'); task.addQuery('sys_created_at', '<', '2019-04-01 00:00:00'); task.query();
addEncodedQuery(condition)
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:
const task = new SimpleRecord('task'); task.addEncodedQuery('active=1');
canCreate()
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:
const task = new SimpleRecord('task'); ss.info(task.canCreate());
canDelete()
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:
const task = new SimpleRecord('task'); task.get('155964310500000194') ss.info(task.canDelete());
canRead()
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:
const task = new SimpleRecord('task'); task.get('155964310500000194') ss.info(task.canRead());
canUpdate()
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:
const task = new SimpleRecord('task'); task.get('155964310500000194') ss.info(task.canUpdate());
deleteMultiple()
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:
const message = new SimpleRecord('message'); message.addQuery('subject', 'LIKE', 'network'); message.query(); message.deleteMultiple();
deleteRecord(recordSetId)
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:
let incident = new SimpleRecord('itsm_incident'); incident.get(5236); incident.deleteRecord();
get(propertyOrValue, value)
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 | Integer or String or Boolean (if this parameter is used as a value); String (if this parameter is used as an operator). | Y | N |
value | Integer or String or Boolean | N | NULL |
Return:
Type | Description |
---|---|
SimpleRecord object | This method returns the SimpleRecord object from the table specified in the query. |
Example:
let incident = new SimpleRecord('itsm_incident'); incident.get( 'subject' , 'Network does not work');
getAttributes()
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. |
const rec = new SimpleRecord('sys_db_table'); rec.get(174837590393975); const attrs = rec.getAttributes(); // attrs = {sys_id: some_id, title: 'My title', name: 'my_name'}
getClassDisplayValue()
This method returns the table title. If the title is not set, then returns name.
Return:
Type | Description |
---|---|
String | Title or name. |
Example:
let incident = new SimpleRecord('itsm_incident'); ss.info( incident.getClassDisplayValue() );
getConditionQuery()
This method returns current query condition.
Return:
Type | Description |
---|---|
String | The query condition. |
Example:
var getq = new SimpleRecord('task'); var condition = getq.addQuery('state','=','-2'); condition.addOrCondition('state', '=', '0'); condition.addOrCondition('state', '=', '7'); getq.next(); ss.info(getq.getConditionQuery())
getDisplayValue(property)
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 |
---|---|
String | A field or record value. |
Example:
let incident = new SimpleRecord('incident'); incident.get(5236); ss.info( incident.getDisplayValue('caller_id') );
getErrors()
If the record creating, updating or deleting will fail, then this method will display error message.
Return:
Type | Description |
---|---|
Array | The error value. |
Example:
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); }) }
getLabel(property)
This method returns the field title.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
property | String | Y | N |
Return:
Type | Description |
---|---|
String | The field title. |
Example:
let incident = new SimpleRecord('itsm_incident'); incident.get(5236); ss.info( incident.getLabel('caller_id') );
getRowCount()
This method gets an amount of the items in a row.
Returns:
Type | Description |
---|---|
Integer | Items amount in a row specified. |
Example:
let row = new SimpleRecord('itsm_incident'); row.query; ss.info('Rows: ') + row.getRowCount;
getTableName()
This method returns the current table name.
Return:
Type | Description |
---|---|
String | The current table name. |
Example:
let incident = new SimpleRecord('itsm_incident'); ss.info( incident.getTableName() ); // incident
getValue(property)
This method returns the value of the object property based on its name.
If the field is of the Reference or List types, then its sys_id value returns.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
Property | String | Y | N |
Return:
Type | Description |
---|---|
Mixed | The value of the field. The value from the database will be returned for the reference fields. |
const record = new SimpleRecord('task'); record.get('15000000000001'); ss.info(record.getValue('assigned_user')); // 150000000534521234
hasAttachment()
This method checks whether the record specified has an attachment or not.
Return:
Type | Description |
---|---|
Boolean | Method returns TRUE if the record has an attachment; otherwise, it returns FALSE. |
Example:
let attach = new SimpleRecord('156647460404629960'); attach.hasAttachment();
initialize()
Creates an empty record suitable for filling with a value before inserting.
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
let record = new SimpleRecord('c_test'); ss.info(record.description); record.initialize(); ss.info(record.description);
insert()
This method creates a database record.
Return:
Type | Description |
---|---|
Integer | The ID of the record created. |
Example:
let incident = new SimpleRecord('itsm_incident'); incident.insert();
isTableVcsEnabled()
This method checks whether the VCS enabled attribute is enabled against the table specified or not.
Return:
Type | Description |
---|---|
Boolean | Method returns TRUE if this attribute is enabled against the table specified; otherwise, it returns FALSE. |
Example:
var check = new SimpleRecord('user'); check.isTableVcsEnabled(); // Returns TRUE or FALSE for the user table.
matchesCondition(condition)
This method checks whether the current record meets the condition being in the current state.
Name | Type | Mandatory | Default Value |
---|---|---|---|
condition | String | N | '' |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
rec.description = 'dsc'; rec.matchesCondition('descriptionLIKEesc'); // false rec.description = 'desc'; rec.matchesCondition('descriptionLIKEesc'); // true
next()
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:
Type |
---|
Record or Boolean |
Example:
let incident = new SimpleRecord('itsm_incident'); incident.query(); while ( incident.next() ){ ss.info( incident.sys_id); }
orderBy(column)
This method sorts records in the ascending order.
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:
let incident = new SimpleRecord('incident'); incident.orderBy('subject'); incident.query();
orderByDesc(column)
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:
let incident = new SimpleRecord('itsm_incident'); incident.orderByDesc('subject'); incident.query();
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. |
selectAttributes(attributes)
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:
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 }
Example:
const record = new SimpleRecord('user'); record.selectAttributes(['email', 'first_name']); record.query(); while (record.next()) { ss.info(record.email); // not null ss.info(record.first_name); // not null ss.info(record.username); // null ... // other fields are null }
setAbortAction(flag)
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:
current.setAbortAction(true);
setLimit(maxNumRecords)
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:
let incident = new SimpleRecord('itsm_incident'); incident.setLimit(30); incident.query();
setMultipleValue(property,value)
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 | String | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
const rec = new SimpleRecord('task'); rec.addQuery('state', 'Created'); rec.query(); rec.setMultipleValue('state', 'Confirmed'); rec.updateMultiple();
setValue(property, value)
This method sets the value of the field in the current record.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
property | String | Y | N |
value | String | Y | N |
Return:
Type | Description |
---|---|
Void | This property does not return a value. |
Example:
let incident = new SimpleRecord('incident'); incident.setValue("subject" , "Help me"); incident.insert();
silentMode(enable)
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. |
let record = new SimpleRecord('task'); record.query(); record.next(); record.silentMode(); record.update();
update(reason)
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:
let incident = new SimpleRecord('itsm_incident'); incident.get(5246); incident.subject += " (repair)"; incident.update();
updateMultiple()
This method updates all the selection entries.
Return:
Type | Description |
---|---|
Void | This property does not returns a value. |
const rec = new SimpleRecord('task'); rec.addQuery('state', 'Created'); rec.query(); rec.setMultipleValue('state', 'Confirmed'); rec.updateMultiple();
- No labels