This server class provides methods to operate the database records.
SimpleRecord(tableName)
This method instantiates a Use the constructor to instantiate an object of the SimpleRecord class object for a particular table.
Parameter(s):
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | SimpleRecord |
---|
linenumbers | true |
---|
|
const taskRecord = new SimpleRecord('task'); |
REM attribute object
The SimpleRecord class has a special object for Record Extended Models – rem_attr that contains information about the REM attributes. Used it Use it to read and edit REM attribute values of the current record with other class the methods as in the example shown below.
Tip |
---|
rem_attr has a number of methods equal similar to the methods of the SimpleRecord: For exampleExample: record.rem_attr.getValue('my_rem_attribute');
|
Parameter:
Name | Type | Mandatory | Default Value |
propertyString | Y | N | Return:
Type | Description |
---|
SimpleRecord object | This method returns the SimpleRecord object from the defined RE model. The method returns 'null' if the record does not have a RE model. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | get() using REM |
---|
linenumbers | true |
---|
|
const record = new SimpleRecord('task');
record.get('160638931615274614');
if (record.getReModelId()) {
ss.info(record.rem_attr.description);
} |
addOrCondition(property, operator, value)
This method appends a 2-or-3 parameter OR a condition to an existing query. It works in conjunction with any of the addQuery() methods. In this method, you can use any preferred operator from the Condition Operators list, specified either in lowercase or in uppercase. Notice that you need to use the system name of the operator in the scripts.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
property | String | Y | N |
operator | String (refer to the Condition Operators article for more information) | N | N |
value | Integer or String or Boolean or Array | Y | N |
SimpleReference object
Anchor |
---|
| SimpleReference |
---|
| SimpleReference |
---|
|
When you call the fields of the Reference type, the response contains a special SimpleReference object. This object allows you to access the fields of the record in the Reference field with dot-walking.
Tip |
---|
SimpleReference object has a number of methods similar to the methods of the SimpleRecord: |
Example:
Code Block |
---|
language | js |
---|
title | getValue() using SimpleReference object |
---|
linenumbers | true |
---|
|
let |
Return:
Type | Description |
---|
SimpleRecord | A query containing OR a condition added to the SimpleRecord object. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | addOrCondition |
---|
linenumbers | true |
---|
|
const record = new SimpleRecord('task');
record.addQuery('subject', 'like', 'not work')setLimit(1);
record.addOrCondition('description', 'like', 'not work'query();
ss.info('Condition query: ' + record.getConditionQuerynext());
ss.info(record.query();
// Info: Condition query: (subjectLIKEnot work)^OR(descriptionLIKEnot work) |
addQuerycaller.getValue('username')); |
addOrCondition(property, operator, value)
This method adds a condition to make a selection of records from the databaseUse the method to add the OR condition to an existing query. It works in conjunction with the addQuery() method. In this method, you can use any preferred necessary operator from the Condition Operators the condition operators list, specified either in lowercase lower- or in uppercase. Notice that you need to use Use the system name names of the operator operators in the scripts.
You can also specify a RE model attribute of a specific table. To filter records, use the operators corresponding to the attribute type.
Note |
---|
The condition may contain criteria based on the attribute of different RE models. If such criteria are built using the AND operator, the selection of records will be empty. To return records that match a condition, use the OR operator. |
Parameter(s)Parameter(s):
Valueoperator | String (refer to the Condition Operators article for more information) | N | Info |
---|
For the REM attributes use the following pattern: '<sys_id>:<attr_name>' where sys_id – the ID of the model that contain the attribute, and attr_name – the system name of the REM attribute. |
|
operator | String | N | = |
N or or or Return:
Type | Description |
---|
SimpleRecord |
The query condition added to the SimpleRecord object. | object | This method returns the instance where the method was called. |
ExamplesExample:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | addQueryaddOrCondition() |
---|
linenumbers | true |
---|
|
const taskrecord = new SimpleRecord('task');
taskrecord.addQuery('activesubject', true);
task.addQuery('subject'like', 'like', 'emailnot work');
taskrecord.addQueryaddOrCondition('sys_created_atdescription', '<like', '2019-04-01 00:00:00');
task.query(not work');
ss.info('CountCondition query: ' + taskrecord.getRowCountgetConditionQuery());
record.query();
// Info: Condition Countquery: 0 |
addEncodedQuery(condition)
This method adds encoded query and applies it to the current query method.
Info |
---|
Decoded query is also applicable. |
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
condition | String | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
(subjectLIKEnot work)^OR(descriptionLIKEnot work) |
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | addOrCondition() with a REM attribute |
---|
|
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | addEncodedQuery |
---|
linenumbers | true |
---|
|
constlet currentUserrecord = ss.getUser();
const reciever = new SimpleRecord('employeetask');
recieverrecord.addQuery('activesubject', true);
if (currentUser.company.class === 'internal') {
reciever.addEncodedQuery(`(company=${currentUser.getValue('company')})`);
} else {
reciever.addEncodedQuery(`%28sys_db_table_id%3D158645243815904649%5Esys_created_byDYNAMIC156957117519820256%29`);
}'like', 'not work')
record.addOrCondition('166972638116358001:description', 'contains', 'not work');
ss.info('DecodedCondition conditionquery: ' + recieverrecord.getConditionQuery());
recieverrecord.query();
// Info: DecodedCondition conditionquery: (active=1)^((sys_db_table_id=158645243815904649^sys_created_byDYNAMIC156957117519820256)) |
canCreate()
This method checks whether inserting new records in this table satisfies the Access Control Rule (ACL).
Also, use this method in the UI Actions to adjust its visibility more precisely.
Return:
Type | Description |
---|
Boolean | The method returns 'true' if this operation is permitted; otherwise, it returns 'false'. |
subjectLIKEnot work)^OR(166972638116358001:descriptionLIKEnot work) |
Info |
---|
It is possible to pass the Reference field value as current.{reference_field_name} instead of the record ID as the addOrCondition() method value. The script example: |
Example:
Code Block |
---|
language | canCreatePass SimpleRecord as an argument | linenumbers | true |
---|
collapse | true |
---|
|
|
current.canCreate(); |
canDelete()
This method checks whether deleting records in this table satisfies the Access Control Rule (ACL).
Also, use this method in the UI Actions to adjust its visibility more precisely.
Return:
Type | Description |
---|
Boolean | The method returns 'true' if this operation is permitted; otherwise, it returns 'false'. |
const task = new SimpleRecord('task');
task.setLimit(1);
task.query();
if (!task.next()) {
ss.info('No tasks found!');
return;
}
const relatedTask = new SimpleRecord('task');
relatedTask.addQuery('caller', task.caller);
relatedTask.addOrCondition('assigned_user', task.caller);
relatedTask.query();
ss.info('Tasks count: ' + relatedTask.getRowCount());
// Info: Tasks count: 122 |
|
addQuery(property, operator, value)
Use this method to add a condition to make a selection of records from the database. In this method, you can use any required operator from the condition operators list, specified in lower- or uppercase. Use the system names of the operators in the scripts.
You can also specify a RE model attribute of a specific table. To filter records, use the operators corresponding to the attribute type.
Note |
---|
The condition may contain criteria based on the attribute of different RE models. If such criteria are built using the AND operator, the selection of records will be empty. To return records that match a condition, use the OR operator. |
Parameter(s):
Name | Type | Mandatory | Default value |
---|
property | String | Y | N Info |
---|
For the REM attributes use the following pattern: '<sys_id>:<attr_name>' where sys_id is the ID of the model that contain the attribute, and attr_name is the system name of the REM attribute. |
|
operator | String | N | = |
value | Integer/String/Boolean/Array/SimpleReference object | Y | N |
Return:
Type | Description |
---|
SimpleRecord object | This method returns the instance where the method was called. |
Examples
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | canDelete |
---|
linenumbers | true |
---|
|
current.canDelete(); |
canRead()
This method checks whether reading records in this table satisfies the Access Control Rule (ACL).
Also, use this method in the UI Actions to adjust its visibility more precisely.
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 |
---|
|
current.canRead(); |
canUpdate()
This method checks whether updating records in this table satisfies the Access Control Rule (ACL).
Also, use this method in the UI Actions to adjust its visibility more precisely.
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 | canUpdateaddQuery() |
---|
linenumbers | true |
---|
|
current.canUpdate(); |
deleteMultiple()
This method allows deleting multiple records in a query selection. Note that the attachments cannot be deleted using this method.
Note |
---|
Do not use this method on tables with dependencies. Always delete each record individually. |
Return:
Type | Description |
---|
Boolean | This method returns 'true' if records are deleted successfully; otherwise, it returns 'false'. |
const task = new SimpleRecord('task');
task.addQuery('active', true);
task.addQuery('subject', 'like', 'email');
task.addQuery('sys_created_at', '<', '2019-04-01 00:00:00');
task.query();
ss.info('Count: ' + task.getRowCount());
// Info: Count: 0 |
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | addQuery() with REM attribute |
---|
linenumbers | true |
---|
|
let |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | deleteMultiple |
---|
linenumbers | true |
---|
|
const record = new SimpleRecord('sys_activity_feed_itemtask');
record.addQuery('content166972638116358001:description', 'isemptynot work');
record.query();
ss.info("Total rows: " + record.getRowCount());
ss.info(record.deleteMultiple());
// Info: 0
// InfoTotal rows: true1 |
deleteRecord()
This method deletes the current record.
Return:
Type | Description |
---|
Boolean | This method returns 'true' if the record is deleted successfully; otherwise it returns 'false'. |
Info |
---|
It is possible to pass the value of the Reference field as current.{reference_field_name} instead of the record ID as the addQuery() в method value. The script example |
Example: Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title |
---|
|
| deleteRecordPass SimpleRecord as an argument | linenumbers | true |
---|
collapse | true |
---|
| const task = new SimpleRecord('task');
task.setLimit(1);
task. | get'155931135900000000'sys_idreturnss.info('No tasks found!');
return;
}
const | isDeletedtask.deleteRecord(if (isDeleted) {
ss.info('Task with ID ' +otherTask.addQuery('caller', task.caller);
otherTask.addQuery('sys_id', '!=', task.sys_id | + ' was deleted!' return;
}error(task.getErrorsinfo('Tasks count: ' + otherTask.getRowCount()); |
|
get(propertyOrValue, value)
This method loads an object from a database by the field value, or, in a specific case, by the sys_id.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
propertyOrValue | A string value of a record ID or property name. If it is equal to the property name, the second parameter 'value' is mandatory.
Note |
---|
Passing 'NULL' or an empty string as the propertyOrValue parameter value causes an exception: "Argument 1 passed to "get()" must not be empty". |
// Info: Tasks count: 720 |
|
addEncodedQuery(condition)
Anchor |
---|
| addEncodedQuery |
---|
| addEncodedQuery |
---|
|
Use this method to add an encoded query to select records from the database. You can also use a decoded query.
You can also specify a RE model attribute of a specific table. To filter records, use the operators corresponding to the attribute type.
Note |
---|
The condition may contain criteria based on the attribute of different RE models. If such criteria are built using the AND operator, the selection of records will be empty. To return records that match a condition, use the OR operator. |
Use curly brackets when setting a filter argument for the text fields of type String, Text, Translated Text, Conditions, and URL. Using parenthesis for the argument may cause a filter query error.
Y | N | value | String | N | NULL |
Return:
Type | Description |
---|
SimpleRecord object | This method returns a SimpleRecord object from the table specified in the query. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | get | Filter with text fields |
---|
linenumbers | true |
---|
collapselinenumbers | true |
---|
|
const subject = 'Hello, SimpleOne)';
const currenttask = new SimpleRecord('task');
currenttask.get('163663310116371174'addEncodedQuery(`subjectLIKE${subject}`);
if (current.sys_id)ss.info(task.getConditionQuery());
try {
task.query();
} catch const company = new SimpleRecord('org_company'(e) {
ss.error(e.message);
}
// Info: company.get('c_website', current.c_customer_url);
ss.eventQueue('notify.responsible', current, company.responsible.email);
} |
getAttributes()
This method returns an object with the current record properties as the keys and properties values as the key values.
Return:
Type | Description |
---|
Object | An array of attributes. |
(subjectLIKEHello, SimpleOne))
// Error: Condition query is invalid |
Parameter(s):
Name | Type | Mandatory | Default value |
---|
condition | String | Y | N Info |
---|
For the REM attributes use the following pattern: '<sys_id>:<attr_name>' where sys_id is the ID of the model that contains the attribute, and attr_name is the system name of the REM attribute. |
|
Return:
Type | Description |
---|
Void | This method does not return a value. |
Examples:
Code Block |
---|
|
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getAttributesaddEncodedQuery() |
---|
linenumbers | true |
---|
|
const userRecordcurrentUser = ss.getUser();
ss.info(userRecord.getAttributes());
// Info: {"sys_id":"155931135900000001","sys_created_at":"2019-09-30 00:00:00","sys_updated_at":"2021-06-28... |
getClassDisplayValue()
This method returns the table title. If the title is not set, it returns the name.
Return:
Type | Description |
---|
String | A title or a name. |
const reciever = new SimpleRecord('employee');
reciever.addQuery('active', true);
if (currentUser.company.class === 'internal') {
reciever.addEncodedQuery(`(company=${currentUser.getValue('company')})`);
} else {
reciever.addEncodedQuery(`%28sys_db_table_id%3D158645243815904649%5Esys_created_byDYNAMIC156957117519820256%29`);
}
ss.info('Decoded condition: ' + reciever.getConditionQuery());
reciever.query();
// Info: Decoded condition: (active=1)^((sys_db_table_id=158645243815904649^sys_created_byDYNAMIC156957117519820256)) |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getClassDisplayValueaddEncodedQuery() with REM attributes |
---|
linenumbers | true |
---|
|
const currentreceier = new SimpleRecord('task');
currentreceiver.getaddQuery('163663310116371174''active', true);
receiver.addEncodedQuery('%28sys_db_table_id%3D158645243815904649%5E166972638116358001%3AdescriptionLIKEwork`);
ss.info(current.getClassDisplayValue'Decoded condition: ' + receiver.getConditionQuery());
receiver.query();
// Info: Task |
getConditionQueryDecoded condition: (active=1)^((sys_db_table_id=158645243815904649^166972638116358001:descriptionLIKEwork)) |
canCreate()
This method returns current query condition
Use this method to check whether the current user can create records in the specified table according to the Access Control Rule (ACL).
Return:
String query conditionmethod returns true if this operation is permitted; otherwise, it returns false. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getConditionQuerycanCreate() |
---|
linenumbers | true |
---|
|
const task = new SimpleRecord('task');
const condition = task.addQuery('state', '7');
condition.addOrCondition('priority', '<', '3');
ss.info('Condition before query: ' + task.getConditionQuery());
task.query();
ss.info('Condition after query: ' + task.getConditionQuery());
// Info: Condition before query: (state=7)^OR(priority<3)
// Info: Condition after query: |
getDisplayValue(property) canDelete()
Use the method to check whether the current user can delete records in the specified table according to the Access Control Rule (ACL).
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 |
---|
|
current.canDelete(); |
canRead()
Use the method to check whether the current user can read records in the specified table according to the Access Control Rule (ACL).
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 |
---|
|
current.canRead(); |
canUpdate()
Use this method to check whether the current user can edit records in the specified table according to the Access Control Rule (ACL).
Anchor |
---|
getDisplayValue() | getDisplayValue() | This method returns the value of the display_by_ref field or a record value. For example, for the reference field the entity name is returned, not the ID.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
Property | String | N | NULLReturn:
String | A field or a record valueBoolean | The method returns true if this operation is permitted; otherwise, it returns false. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getDisplayValuecanUpdate() |
---|
linenumbers | true |
---|
|
const current = new SimpleRecord('task');
current.get('163663310116371174');
ss.info(current.getDisplayValue('caller'));
ss.info(current.getValue('caller'));
// Info: John Doe
// Info: 155931135900000001 |
getErrors() Anchor |
---|
getErrors() | getErrors() | This method displays an error message in case of a failure of a record creating, updating or deleting.
Use this method for control purposes if there are any validation errors within your scripts.
Warning |
---|
Some validation errors may not be displayed within the debug process, so it is highly recommended to use this method. For example, errors in the condition queries passed by the methods like addEncodedQuery(condition) or similar methods can be displayed by calling this method. |
Return:
Type | Description |
---|
Array | An error value. |
deleteMultiple()
Use this method to delete multiple records form the selection. The attachments of the deleted records are not deleted.
Note |
---|
Do not use this method for the tables that have dependencies. Always delete each record separately. |
Return:
Type | Description |
---|
Boolean | This method returns true if records are deleted successfully; otherwise, it returns false. |
Example:
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getErrorsdeleteMultiple() |
---|
linenumbers | true |
---|
|
const record = new SimpleRecord('usersys_activity_feed_item');
const insertedRecordId = record.insert(addQuery('content', 'isempty');
if (insertedRecordId == 0) {
record.query();
ss.info(record.getErrorsgetRowCount());
}
/ss.info(record.deleteMultiple());
// Info: ["The \"\"First Name\" [first_name]\" field is mandatory. (record id: )",... |
getLabel(property) deleteRecord(id)
Use this method to delete a record.
When the method is called in a selection of records with the parameter set, the record with a specific ID is deleted. If id in not specified in the parameter, the method deletes the current record.
Parameter
Anchor |
---|
getLabel() | getLabel() | This method gets the field title.
Info |
---|
The getLabel() method cannot be used with the REM attributes. Instead, use the getTitle() method. |
Parameter(s):
Return:
String | A field nameBoolean | This method returns true if the record is deleted successfully; otherwise it returns false. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getLabeldeleteRecord() |
---|
linenumbers | true |
---|
|
const currenttask = ss.getUser(new SimpleRecord('task');
const fieldLabel = current.getLabeltask.get('username155931135900000000');
ss.addErrorMessage('Field "' + fieldLabelif (!task.sys_id) {
return;
}
const isDeleted = task.deleteRecord();
if (isDeleted) {
ss.info('Task with ID ' + task.sys_id + '" cannot be blankwas deleted!');
// Field "Login" cannot be blank |
getReModelId() Anchor |
---|
getremodelid | getremodelid | This method retrieves the ID of the RE model related to the current record. To set a new model ID use the setReModelId method.
Return:
Type | Description |
---|
String | The method returns the ID of the model. If the model is not found, the method returns 'null'. |
return;
}
ss.error(task.getErrors()); |
get(propertyOrValue, value)
Use this method to load an object from a database by the field value, or, in a specific case, by the ID. The propertyOrValue parameter is the ID value of the record or the property name. If the value is the property name, the value parameter is mandatory.
Note |
---|
When you pass the null value or an empty string in the propertyOrValue parameter, the system throws an exception: Argument 1 passed to "get()" must not be empty.
|
Parameter(s):
Name | Type | Mandatory | Default value |
---|
propertyOrValue | | Y | N |
value | String | N | null |
Return:
Type | Description |
---|
SimpleRecord object | This method returns a SimpleRecord object from the table specified in the query. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | get() |
---|
linenumbers | true |
---|
|
const current |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getReModelId |
---|
linenumbers | true |
---|
|
(function executeRule(current, previous = null /*not null only when action is update*/) {
if (current.getReModelId()) {
const model = new SimpleRecord('sys_rmc_modeltask');
modelcurrent.get(current.getReModelId()); // current model
current.$$service = model.getValue('cmdb_service_id'); // pass service if field exists
}
})(current, previous); |
getRowCount()
This method gets the amount of the items in a row.
Returns:
Type | Description |
---|
Integer | A number of the items in a row . |
Info |
---|
It is possible to pass the value of the Reference field as current.{reference_field_name} instead of the record ID as the get() method value. The script example |
Example: Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title |
---|
|
| getRowCountPass SimpleRecord as an argument | linenumbers | true |
---|
collapse | true |
---|
| const task = new SimpleRecord('task');
task.setLimit(1);
task.query();
| ss.addInfoMessage('All Tasks Count: ' + task.getRowCount());
// All Tasks Count: 2 |
getTableName()
if (!task.next()) {
ss.info('No tasks found!');
return;
}
const user = new SimpleRecord('user');
user.get(task.caller);
user.language_id = '156628684306541141'; // English
ss.info(user.update());
// Info: 167515292501757147 |
|
getAttributes()
Use the method to return an object with the current record attributes as the keys and key valuesThis method gets the current table name.
Return:
String | The current table nameObject | This method returns аn object with the record's attributes and their values. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getTableNamegetAttributes() |
---|
linenumbers | true |
---|
|
const currentuserRecord = ss.getUser();
ss.info('/list/' + current.getTableName() + '/' + current.sys_iduserRecord.getAttributes());
// Info: /list/user/155931135900000001 |
getTitle(attribute) {"sys_id":"155931135900000001","sys_created_at":"2019-09-30 00:00:00","sys_updated_at":"2021-06-28... |
getClassDisplayValue()
Use this method to return the title of the current table.
Anchor |
---|
getTitle() | getTitle() | This method returns the title of the defined RE attribute.
Parameter:
Name | Type | Mandatory | Default Value |
---|
column | String | Y | N |
Return:
Type | Description |
---|
String | This method returns the a title of the attributerecord table. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getTitlegetClassDisplayValue() |
---|
linenumbers | true |
---|
|
const current = new SimpleRecord('task');
current.get('163638951512716126163663310116371174');
if ss.info(current.sys_id) {
ss.info(current.rem_attr.getTitle('reviewed'));
}
// Info: Review completed |
Info |
---|
To return column, titles which are not part of REM, use the getLabel() method. |
getValue(property) Anchor |
---|
getValue() | getValue() | 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.
Note |
---|
To speed up the script execution, use this method to get values of the fields of the Reference type instead of Dot-walking. For example, it is preferable to use the current.getValue('reference_field') structure instead of current.reference_field.sys_id one. |
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
property | String | Y | N |
Return:
Type | Description |
---|
Mixed | The string value of the object property. |
getClassDisplayValue());
// Info: Task |
getConditionQuery()
Use this method to return the current query condition.
Return:
Type | Description |
---|
String | This method returns the query condition. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getConditionQuery() |
---|
linenumbers | true |
---|
|
const task = new SimpleRecord('task');
const condition = task.addQuery('state', '7');
condition.addOrCondition('priority', '<', '3');
ss.info('Condition before query: ' + task.getConditionQuery());
task |
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getValue |
---|
linenumbers | true |
---|
|
const current = ss.getUser();
const user = new SimpleRecord('user');
user.addQuery('timezone_id', current.getValue('timezone_id'));
user.selectAttributes('sys_id');
user.query();
ss.info(user.getRowCount() + 'Condition usersafter havequery: the' same timezone as you'+ task.getConditionQuery());
// Info: 24Condition usersbefore have the same timezone as you |
hasAttachment()
This method checks whether the record specified has an attachment or not.
Return:
Type | Description |
---|
Boolean | The method returns 'true' if the record has an attachment; otherwise, it returns 'false'. |
query: (state=7)^OR(priority<3)
// Info: Condition after query: |
getDisplayValue(property)
Anchor |
---|
| getDisplayValue() |
---|
| getDisplayValue() |
---|
|
Use this method to return the displayed value of the record parameter. For example, for the Reference field the record name is returned, not the ID.
With no parameter specified, the method returns the display value of the record from the field with the Display by ref checkbox selected.
Find the values represented in the server scripts according to the field types in the table.
Parameter(s):
Name | Type | Mandatory | Default value |
---|
property | String | N | null |
Return:
Type | Description |
---|
String | This method returns the display value of the record or field. |
Example:
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | hasAttachmentgetDisplayValue() |
---|
linenumbers | true |
---|
|
const current = new SimpleRecord('task');
current.get('163663310116371174');
const hasAttach = ss.info(current.hasAttachmentgetDisplayValue('caller'));
if (!hasAttach) {
ss.addErrorMessageinfo('File should be attached'current.getValue('caller'));
// Info: John return;
}
current.state = '2'; // Open
current.update(); |
initialize()
This method populates all active empty fields with their predefined default values.
It works only for new records that have never been saved and cannot be called repeatedly.
This method is called automatically and implicitly at the first set operation (also known as "the setter")Doe
// Info: 155931135900000001 |
getErrors()
Use this method to get an error message in case of failure of a record creating, updating or deleting.
Use this method to control the execution of an operation with a record in a script.
Warning |
---|
It is highly recommended to use this method as some validation errors may not be displayed within the debug process. For example, errors in the condition queries passed using the addEncodedQuery(condition) or similar methods can be retrieved by calling getErrors. |
Return:
VoidArray of Strings | This method |
does not return a valuereturns the error values. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | initializegetErrors() |
---|
linenumbers | true |
---|
|
const taskRecordrecord = new SimpleRecord('taskuser');
ss.info(taskRecord.getAttributes().callerconst insertedRecordId = record.insert();
taskRecord.initialize();
if (insertedRecordId == 0) {
ss.info(taskRecordrecord.getAttributesgetErrors().caller);
}
// Info:
// Info: 155931135900000001 |
insert()
This method uses the field values of the current record to insert into a new one.
If a record is not inserted, method returns '0' (zero) and adds an informative error message, which can be obtained with the getErrors() method.
["The \"\"Login\" [username]\" field is mandatory. (record id: )",... |
getLabel(property)
Use this method to get the field title.
Info |
---|
The getLabel() method cannot be used with the REM attributes. Instead, use the getTitle() method. |
Parameter(s):
Name | Type | Mandatory | Default value |
---|
property | String | Y | N |
Return:
Integer | If record was not inserted, the method returns '0' and you can get a message containing a list of errors.If a record was inserted, the method returns a unique ID of the inserted recordString | This method returns a field name. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | insertgetLabel() |
---|
linenumbers | true |
---|
|
const newTaskcurrent = new SimpleRecord('task');
newTask.subject = 'Subtask'ss.getUser();
const inserterTaskIDfieldLabel = newTaskcurrent.insertgetLabel('username');
ss.info(`/record/task/${inserterTaskID}`);
// Info: /record/task/163675231910113745 |
isTableVcsEnabled()
addErrorMessage('Field "' + fieldLabel + '" cannot be blank');
// Field "Login" cannot be blank |
getReModelId()
Use this method to retrieve the ID of the RE model related to the current record. To set a new model ID use the setReModelId methodThis method checks whether the VCS enabled attribute is enabled against the specified table.
Return:
BooleanThis value is_vcs_enabled attribute of the record tablemodel. If the model is not found, the method returns null. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | isTableVcsEnabledgetReModelId() |
---|
linenumbers | true |
---|
|
const(function executeRule(current, previous = new SimpleRecord('user');
ss.info(current.isTableVcsEnabled());
// Info: false |
matchesCondition(condition)
This method checks whether the current record meets the condition in the current state.
Name | Type | Mandatory | Default Value |
---|
condition | String | N | '' |
Return:
Type | Description |
---|
null /*not null only when action is update*/) {
if (current.getReModelId()) {
const model = new SimpleRecord('sys_rmc_model');
model.get(current.getReModelId()); // current model
current.$$service = model.getValue('cmdb_service_id'); // pass service if field exists
}
})(current, previous); |
getRowCount()
Use this method to get the number of the items in a selection.
Returns:
Type | Description |
---|
Integer | The method returns a number of the items in a selection. |
Example:
Boolean | This method returns 'true' if the record meets the condition specified; otherwise; it returns 'false'. Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | matchesConditiongetRowCount() |
---|
linenumbers | true |
---|
|
const task = new SimpleRecord('task');
task.description = 'emaio'query();
ss.info(task.matchesConditionaddInfoMessage('descriptionLIKEemail')); // false
task.description = 'email';
ss.info(task.matchesCondition('descriptionLIKEemail')); // true |
next()
This method returns the next record in the query. All Tasks Count: ' + task.getRowCount());
// All Tasks Count: 2 |
getTableName()
Use this method to get the name of the current table.
Return:
Record or Boolean | If this is the first call, this String | The method returns the |
first record in the query. If the query is empty, this method returns 'false'.Example:
system name of the current table. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | nextgetTableName() |
---|
linenumbers | true |
---|
|
const usercurrent = new SimpleRecord('user');
user.setLimit(1ss.getUser();
userss.query();
user.next();
ss.info(userinfo('/list/' + current.getTableName() + '/' + current.sys_id);
// Info: 100000000000000000 |
Note |
Until the method is called, the values of a SimpleRecord object are not available, and the 'Current record is not set'
message appears. See the example/list/user/155931135900000001 |
getTitle(attribute)
Use this method to get the title of the defined RE attribute.
Parameter:
Name | Type | Mandatory | Default value |
---|
column | String | Y | N |
Return:
Type | Description |
---|
String | This method returns the title of the REM attribute. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getTitle() |
---|
linenumbers | true |
---|
|
const taskcurrent = new SimpleRecord('task');
taskcurrent. setLimitget( 1'163638951512716126');
task.query();
// task.next();
ss.info(task.number);
// Error: Current record is not set. |
orderBy(column)
This method sorts the 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:
if (current.sys_id) {
ss.info(current.rem_attr.getTitle('reviewed'));
}
// Info: Review completed
const current = new SimpleRecord('task');
current.get('163638951512716126');
if (current.sys_id) {
ss.info(current.rem_attr.getTitle('reviewed'));
}
// Info: Review completed |
Info |
---|
To return the columns, the titles of which are not a part of REM, use thegetLabel()method. |
getValue(property)
Use this method to return the value of the specified object attribute.
If the field is of the Reference or List types, the method returns its IDvalue.
Find the values represented in the server scripts according to the other field types in the table.
Note |
---|
Use this method to get values of the Reference type fields instead of dot-walking. For example, use the current.getValue('reference_field') structure instead of the current.reference_field.sys_id one. |
Parameter(s):
Name | Type | Mandatory | Default value |
---|
property | String | Y | N |
Return:
Type | Description |
---|
Any | This method returns the value of the specified object attribute |
Type | Description |
---|
Void | This method does not return a valueExample:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | orderBygetValue() |
---|
linenumbers | true |
---|
|
const current = ss.getUser();
const firstLoguser = new SimpleRecord('sys_loguser');
firstLoguser.orderByaddQuery('systimezone_created_at'); // oldest record first
firstLog.addQuery('message', 'like', 'Connection');
firstLog.setLimit(1);
firstLog.selectAttributes(['message', 'sys_created_at']);
firstLog.query();
firstLog.nextid', current.getValue('timezone_id'));
user.selectAttributes('sys_id');
user.query();
ss.info(firstLog.sys_created_atuser.getRowCount() + ' - ' + firstLog.message users have the same timezone as you');
// Info: 2021-06-03 06:34:02 - IMAP IMAP (Default): Connection error: ... |
orderByDesc(column)
This method sorts the records in the descending order.
Parameter(s):
24 users have the same timezone as you |
Info |
---|
You can also directly interact with the value of a reference field using the context processing with the '$$' operator. It allows you to check for additional fields and get their values. See the Dot-walking in Scripts article to learn more. |
hasAttachment()
Use this method to check whether the specified record has an attachment or not.
Name | Type | Mandatory | Default Value |
---|
column | String | Y | N |
Return:
VoidThis method does not return a valueThe method returns true if the record has an attachment; otherwise, it returns false. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | orderByDeschasAttachment() |
---|
linenumbers | true |
---|
|
const lastCommentcurrent = new SimpleRecord('sys_activities_stream_fieldtask');
lastCommentcurrent.orderByDescget('sys_created_at163663310116371174');
const //hasAttach newest record first
lastComment.setLimit(1);
lastComment.selectAttributes(['value', 'sys_created_by']);
lastComment.query();
lastComment.next();
ss.info(lastComment.sys_created_by.display_name + ': ' + lastComment.value);
// Info: John Doe: test |
query()
This method applies the query to the database selection. After this, it fills in the record set.= current.hasAttachment();
if (!hasAttach) {
ss.addErrorMessage('File should be attached');
return;
}
current.state = '2'; // Open
current.update(); |
initialize()
Use this method to populate all available fields with their predefined default values.
This method is applicable only for the new records that have never been saved.
This method is called automatically when a record is created.
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | queryinitialize() |
---|
linenumbers | true |
---|
|
const taskstaskRecord = new SimpleRecord('task');
tasksss.addQuery('sys_created_at', '>', '2020-01-01');
tasks.orderBy('sys_created_at');
tasks.setLimit(2);
tasks.query();
while (tasks.next()) {
ss.info('Task number: ' + tasks.number);
}
info(taskRecord.getAttributes().caller);
taskRecord.initialize();
ss.info(taskRecord.getAttributes().caller);
// Info:
// Info: Task number: TSK0000001
// Info: Task number: TSK0000003 |
selectAttributes(attributesinsert()
Use this method tooptimize the database queries, especially when it is necessary to obtain only several object fields, not the whole object.
Warning |
---|
to create a new record with the field values of an object.
If a record is not created, method returns '0' (zero) and generates an error message, which you can get with the getErrors() method.
Return:
Type | Description |
---|
String | - If record was not created, the method returns '0' and generates a message that contains a list of errors.
- If a record was created, the method returns a unique ID of the created record.
|
Do not use this method to select records that can be updated or deleted after selecting. Otherwise, some of the record field values may be lost when these records are updated or deleted. The action performed may also throw an exception similar to:
Info |
---|
You cannot save an incomplete record. |
Name | Type | Mandatory | Default Value |
---|
attributes | String or Array | Y | N |
Info |
---|
It makes sense to pass a single attribute name as a string. But if you need to pass more than one attribute names, use Array type (as shown in code example below). |
Return:
Type | Description |
---|
SimpleRecord object | This method returns a SimpleRecord object containing attributes and values. Note | Regardless of the initial attribute set content, the returned object always contains the sys_id attribute. See code examples below. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | selectAttributes insert(String) |
---|
linenumbers | true |
---|
|
const recordnewTask = new SimpleRecord('usertask');
record.selectAttributes('email');
record.query();
record.nextnewTask.subject = 'Subtask';
const insertedTaskID = newTask.insert();
ss.info(record.getAttributes()`/record/task/${insertedTaskID}`);
// Info: {"email":"john.doe@email.com","sys_id":"162423321917274937"} |
Example:
/record/task/163675231910113745 |
isTableVcsEnabled()
Use this method to verify whether the Is VCS enabled checkbox is selected in the specified table.
Return:
Type | Description |
---|
Boolean | This method returns the value of the Is vcs enabled attribute of the table record. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | isTableVcsEnabled() |
---|
linenumbers | true |
---|
|
const current |
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | selectAttributes (Array) |
---|
linenumbers | true |
---|
|
const record = new SimpleRecord('user');
recordss.selectAttributes(['email', 'username']);
record.query();
record.next();
ss.info(record.getAttributes());
// Info: {"email":"john.doe@email.com","username":"john.doe","sys_id":"162423321917274937"} |
setAbortAction(flag)
This method is used in business rules and sets a flag, indicating that the current operation (insert/update/delete) will be interrupted.
Note |
---|
Please note that the code will not be executed if it is typed after calling this method in the script body. |
Note |
---|
info(current.isTableVcsEnabled());
// Info: false |
matchesCondition(condition)
Use this method to verify whether the current record meets the specified condition.
Parameter(s):
Name | Type | Mandatory | Default value |
---|
condition | String | N | '' |
It is not recommended to use thismethod with async business rules. It may cause unpredictable system behavior.Parameter(s):
Name | Type | Mandatory | Default Value |
---|
flag | Boolean | Y | NReturn:
Void does not return a valuereturns true if the record meets the specified condition; otherwise; it returns false. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | setAbortActionmatchesCondition() |
---|
linenumbers | true |
---|
|
const currenttask = new SimpleRecord('task');
current.get('163663310116371174');
const hasAttach = current.hasAttachment();
if (!hasAttach) {
ss.addErrorMessage('File should be attached!');
current.setAbortAction(true);
}
current.state = '2'; // Open
current.update(); |
setLimit(maxNumRecords)
This method limits the number of records selected by SimpleRecord query methods.
Parameter(s):
task.description = 'emaio';
ss.info(task.matchesCondition('descriptionLIKEemail')); // false
task.description = 'email';
ss.info(task.matchesCondition('descriptionLIKEemail')); // true |
next()
Use this method to get the next record in the query.
Name | Type | Mandatory | Default Value |
---|
maxNumRecords | Integer | Y | NReturn:
Void | This method does not return a valueSimpleRecord object or Boolean | If this is the first call, this method returns the first record in the query. If the query is empty, this method returns false. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | setLimitnext() |
---|
linenumbers | true |
---|
|
const recorduser = new SimpleRecord('user');
recorduser.setLimit(31);
recorduser.query();
user.next();
ss.info(record.getRowCount())user.sys_id);
// Info: 3100000000000000000 |
setMultipleValueorderBy(
property,valuecolumn)
This
Use this method
sets the properties values for every entry in the current selectionto sort the records in the ascending order.
Tip |
---|
Call this method several times to order by multiple columns. |
Parameter(s):
Valueproperty | String | Y | N |
value Return:
Type | Description |
---|
Void | This method does not |
return a Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | setMultipleValueorderBy() |
---|
linenumbers | true |
---|
|
const taskfirstLog = new SimpleRecord('tasksys_log');
taskfirstLog.addQueryorderBy('state', '7'sys_created_at'); // Draft
task.query(oldest record first
firstLog.addQuery('message', 'like', 'Connection');
ssfirstLog.info(task.getRowCount()setLimit(1);
taskfirstLog.setMultipleValueselectAttributes(['statemessage', '2sys_created_at']); // Open
// task.updateMultiple
firstLog.query(); |
setReModelId(reModelId) Anchor |
---|
setremodelid | setremodelid | This method sets the ID of the defined RE model. To get the model ID, use the getReModelId method
firstLog.next();
ss.info(firstLog.sys_created_at + ' - ' + firstLog.message);
// Info: 2021-06-03 06:34:02 - IMAP IMAP (Default): Connection error: ... |
orderByDesc(column)
Use this method to sort the records in the descending order.
Tip |
---|
Call this method several times to order by multiple columns. |
Parameter(s):
If the reModelId parameter is equal to 'null', the REM, related to the record, will be detached. Return:
Type | Description |
---|
Void | This method does not |
return a Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getReModelId |
---|
linenumbers | true |
---|
|
const task = new SimpleRecord('task');
task.get('163352033916904699');
if (task.getValue('service') === '164069027812962298') { // Email Server Service
task.setReModelId('158569205818704980'); // Email Server Access Request
} else {
task.setReModelId(null);
}
task.update(); |
orderByDesc() | linenumbers | true |
---|
|
const lastComment = new SimpleRecord('sys_activities_stream_field');
lastComment.orderByDesc('sys_created_at'); // newest record first
lastComment.setLimit(1);
lastComment.selectAttributes(['value', 'sys_created_by']);
lastComment.query();
lastComment.next();
ss.info(lastComment.sys_created_by.display_name + ': ' + lastComment.value);
// Info: John Doe: Test comment |
query()
Use this method to apply a query to retrieve a selection from a database. The selection will be stored in the object for which this method was called.
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | query() |
---|
linenumbers | true |
---|
|
const tasks = new SimpleRecord('task');
tasks.addQuery('sys_created_at', '>', '2020-01-01');
tasks.orderBy('sys_created_at');
tasks.setLimit(2);
tasks.query();
while (tasks.next()) {
ss.info('Task number: ' + tasks.number);
}
// Info: Task number: TSK0000001
// Info: Task number: TSK0000003 |
selectAttributes(attributes)
Use this method to optimize the database queries, especially when it is necessary to get only several object fields, not the whole object.
Warning |
---|
Do not use this method to select records that can be updated or deleted after the selection. Otherwise the system throws an exception: Info |
---|
You cannot update the record with the set of shortened attributes. Remove the selectAttributes method call and update again. |
|
Parameter(s):
Name | Type | Mandatory | Default value |
---|
attributes | String/Array | Y | N |
Info |
---|
Pass a single attribute name as a string. If you need to pass more than one attribute names, use the Array type as shown in code example below. |
Return:
Type | Description |
---|
SimpleRecord object | This method returns a SimpleRecord object containing attributes and values. Note |
---|
Regardless of the initial attribute set content, the returned object always contains the ID attribute. See the code examples below. |
|
Examples:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | selectAttributes (String) |
---|
linenumbers | true |
---|
|
const record = new SimpleRecord('user');
record.selectAttributes('email');
record.query();
record.next();
ss.info(record.getAttributes());
// Info: {"email":"john.doe@email.com","sys_id":"162423321917274937"} |
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | selectAttributes (Array) |
---|
linenumbers | true |
---|
|
const record = new SimpleRecord('user');
record.selectAttributes(['email', 'username']);
record.query();
record.next();
ss.info(record.getAttributes());
// Info: {"email":"john.doe@email.com","username":"john.doe","sys_id":"162423321917274937"} |
setAbortAction(flag)
Use this method to interrupt the current operation.
Note |
---|
- Note that the script is not executed if it is written after calling this method in the script body.
- It is not recommended to use thismethod with the async business rules as it may cause unpredictable system behavior.
|
Parameter(s):
Name | Type | Mandatory | Default value |
---|
flag | Boolean | Y | N |
message | String | N | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | setAbortAction() |
---|
linenumbers | true |
---|
|
const current = new SimpleRecord('task');
current.get('163663310116371174');
const hasAttach = current.hasAttachment();
if (!hasAttach) {
ss.addErrorMessage('File should be attached!');
current.setAbortAction(true);
}
current.state = '2'; // Open
current.update(); |
setLimit(maxNumRecords)
Use this method to limit the number of the records in a selection done according to a condition.
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 |
---|
|
const record = new SimpleRecord('user');
record.setLimit(3);
record.query();
ss.info(record.getRowCount());
// Info: 3 |
setMultipleValue(property,value)
Use this method to set the field values for each record in the current selection.
Parameter(s):
Name | Type | Mandatory | Default value |
---|
property | String | Y | N |
value | Any | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | setMultipleValue() |
---|
linenumbers | true |
---|
|
const task = new SimpleRecord('task');
task.addQuery('state', '7'); // Draft
task.query();
ss.info(task.getRowCount());
task.setMultipleValue('state', '2'); // Open
// task.updateMultiple(); |
setReModelId(reModelId)
Use this method to specify the ID of a particular RE model. To get the model ID, use the getReModelId method.
Parameter(s):
Name | Type | Mandatory | Default value |
---|
reModelId | String | Y | N |
If the reModelId parameter is set to null, the REM related to the record will be detached.
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getReModelId() |
---|
linenumbers | true |
---|
|
const task = new SimpleRecord('task');
task.get('163352033916904699');
if (task.getValue('service') === '164069027812962298') { // Email Server Service
task.setReModelId('158569205818704980'); // Email Server Access Request
} else {
task.setReModelId(null);
}
task.update(); |
Note |
---|
- When calling the method on a SimpleRecord instance, the values of its attributes bound to the previous model will be reset.
- After calling the method and updating the сurrent record, the attribute values bound to the previous model will be lost.
|
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | setReModelId() |
---|
linenumbers | true |
---|
|
(function executeRule(current, previous = null /*not null only when action is update*/ ) {
// before rule triggered by service change
ss.importIncludeScript('getRemAttributes');
const rmc = new SimpleRecord('sys_rmc_model');
rmc.addQuery('cmdb_service_id', current.getValue('service'));
rmc.addQuery('active', true);
rmc.selectAttributes('sys_id');
rmc.setLimit(1);
rmc.query();
if (rmc.next()) {
const previousModelAttributes = getRemAttributes(current);
current.setReModelId(rmc.sys_id);
const currentModelAttributes = getRemAttributes(current);
Object.keys(previousModelAttributes).forEach(attributeName => {
if (currentModelAttributes.hasOwnProperty(attributeName)) {
current.rem_attr[attributeName] = previousModelAttributes[attributeName];
}
})
} else {
current.setReModelId(null);
}
})(current, previous); |
Note |
---|
When calling the method on a SimpleRecord() instance, the values of its attributes bound to the previous model will be reset. After calling the method and updating the сurrent record, the attribute values bound to the previous model will be lost. |
setValue(property, value)
This method sets the Use this method to set a field value of the field in the current record.
Parameter(s):
Valuevalue |
---|
property | String | Y | N |
value |
String Return:
Type | Description |
---|
Void | This property does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | setValue() |
---|
linenumbers | true |
---|
|
const task = new SimpleRecord('task');
task.setValue('subject', 'mail');
task.insert(); |
silentMode(enable)
This Use this method is intended to update the a record without executing any entities related to this record implementing the business logic , such as that is implemented with the business rules, notifications, workflows, etc workflows and others.
Return:
Type | Description |
---|
Void | This property does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | silentMode() |
---|
linenumbers | true |
---|
|
const task = new SimpleRecord('task');
task.addQuery('active', false);
task.addQuery('approval_state', 'isempty');
task.query();
ss.info(task.getRowCount());
task.silentMode();
task.setMultipleValue('approval_state', 'not_requested'); // set Default value Value
//task.updateMultiple(); |
update()
This method updates a database recordUse this method to update a record in the database.
Info |
---|
This Use this method is used for existing records. - If the record existed beforeexists, the changes are applied.
- If the record did does not exist before, the getErrors() method method will return this the error:
"Unable to update new record. Use `insert()` instead. (record id: )"
|
Return:
Integer was then - the method returns '0' and
|
you can get - generates a message containing a list of errors
|
;As a normal case, an ID - .
- The method returns an ID of the updated record
|
returns Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | update() |
---|
linenumbers | true |
---|
|
const current = new SimpleRecord('user');
current.get(ss.getUserId());
current.timezone_id = '156076775207670452'; // UTC
ss.info(current.update());
ss.info(current.getErrors());
// Info: 155931135900000001
// Info: [] |
updateMultiple()
This Use this method updates to update all the records in the selection entries.
Return:
Void or Integer occurred was then method returns '0' and you can get - the method returns false and generates a message containing a list of errors
|
;Normally, this method does not return a value.- The method returns true if no errors occur.
|
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | updateMultiple() |
---|
linenumbers | true |
---|
|
const task = new SimpleRecord('task');
task.addQuery('state', '0'); // Open
task.query();
ss.info(task.getRowCount());
task.setMultipleValue('state', '10'); // Canceled
// task.updateMultiple(); |