Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
This server class provides methods to operate the database records limited by considering the ACL rules of a particular the user.
- If the user attempts to create a field he has no access to with a script, the method getErrors does not return any errors, the record is created but the prohibited field are empty.
- If the user attempts to write/delete the data he has no access to, the method getErrors returns the corresponding error.
- If the user attempts to read the data he has no access to, the response does not include this data (for example, a column or the whole string can be empty).
SimpleRecordSecure(tableName)
Use the constructor to instantiate an object of the SimpleRecordSecure class for a particular table.
Parameter(s):
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const taskRecord = new SimpleRecordSecure('task'); |
REM attribute object
The SimpleRecord class has a special object for Record Extended Models – rem_attr that contains information about the REM attributes. Use it to read and edit REM attribute values of the current record with the methods as shown below.
Tip |
---|
rem_attr has a number of methods similar to the methods of the SimpleRecordSecure: Example:
|
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const record = new SimpleRecordSecure('task');
record.get('160638931615274614');
if (record.getReModelId()) {
ss.info(record.rem_attr.description);
} |
addOrCondition(property, operator, value)
Use 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 necessary 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):
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. |
Return:
Examples:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const record = new SimpleRecordSecure('task');
record.addQuery('subject', 'like', 'not work')
record.addOrCondition('description', 'like', 'not work');
ss.info('Condition query: ' + record.getConditionQuery());
record.query();
// Info: Condition query: (subjectLIKEnot work)^OR(descriptionLIKEnot work) |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
let record = new SimpleRecordSecure('task');
record.addQuery('subject', 'like', 'not work')
record.addOrCondition('166972638116358001:description', 'contains', 'not work');
ss.info('Condition query: ' + record.getConditionQuery());
record.query();
// Info: Condition query: (subjectLIKEnot work)^OR(166972638116358001:descriptionLIKEnot work) |
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:
Code Block | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
const task = new SimpleRecordSecure('task');
task.setLimit(1);
task.query();
if (!task.next()) {
ss.info('No tasks found!');
return;
}
const relatedTask = new SimpleRecordSecure('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):
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. |
Return:
Examples:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const task = new SimpleRecordSecure('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 | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
let record = new SimpleRecordSecure('task');
record.addQuery('166972638116358001:description', 'not work');
record.query();
ss.info("Total rows: " + record.getRowCount());
// Info: Total rows: 1 |
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:
Code Block | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
const task = new SimpleRecordSecure('task');
task.setLimit(1);
task.query();
if (!task.next()) {
ss.info('No tasks found!');
return;
}
const otherTask = new SimpleRecordSecure('task');
otherTask.addQuery('caller', task.caller);
otherTask.addQuery('sys_id', '!=', task.sys_id);
otherTask.query();
ss.info('Tasks count: ' + otherTask.getRowCount());
// Info: Tasks count: 720 |
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.
Code Block | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
const subject = 'Hello, SimpleOne)';
const task = new SimpleRecordSecure('task');
task.addEncodedQuery(`subjectLIKE${subject}`);
ss.info(task.getConditionQuery());
try {
task.query();
} catch (e) {
ss.error(e.message);
}
// Info: (subjectLIKEHello, SimpleOne))
// Error: Condition query is invalid |
Parameter(s):
N
Info |
---|
For the REM attributes use the following pattern: '<sys_id>:<attr_name>' where sys_id – the ID of the model that contains the attribute, and attr_name – the system name of the REM attribute. |
Return:
Examples:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const currentUser = ss.getUser();
const reciever = new SimpleRecordSecure('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)) |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const receier = new SimpleRecordSecure('task');
receiver.addQuery('active', true);
receiver.addEncodedQuery('%28sys_db_table_id%3D158645243815904649%5E166972638116358001%3AdescriptionLIKEwork`);
ss.info('Decoded condition: ' + receiver.getConditionQuery());
receiver.query();
// Info: Decoded condition: (active=1)^((sys_db_table_id=158645243815904649^166972638116358001:descriptionLIKEwork)) |
canCreate()
Use this method to check whether the current user can create records in the specified table according to the Access Control Rule (ACL).
Return:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
current.canCreate(); |
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:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
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:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
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).
Return:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
current.canUpdate(); |
deleteMultiple()
Use this method to delete multiple records form the selection. The attachments of the deleted records are not deleted. If the selection includes a record that the current user cannot delete because of the ACL, no records from the selection are deleted.
Note |
---|
Do not use this method for the tables that have dependencies. Always delete each record separately. |
Return:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const record = new SimpleRecordSecure('sys_activity_feed_item');
record.addQuery('content', 'isempty');
record.query();
ss.info(record.getRowCount());
ss.info(record.deleteMultiple());
// Info: 0
// Info: true |
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:
Return:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const task = new SimpleRecordSecure('task');
task.get('155931135900000000');
if (!task.sys_id) {
return;
}
const isDeleted = task.deleteRecord();
if (isDeleted) {
ss.info('Task with ID ' + task.sys_id + ' was deleted!');
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:
|
Parameter(s):
String
Return:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const current = new SimpleRecordSecure('task');
current.get('163663310116371174'); |
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:
Code Block | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
const task = new SimpleRecordSecure('task');
task.setLimit(1);
task.query();
if (!task.next()) {
ss.info('No tasks found!');
return;
}
const user = new SimpleRecordSecure('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 values.
Return:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const userRecord = 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()
Use this method to return the title of the current table.
Return:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const current = new SimpleRecordSecure('task');
current.get('163663310116371174');
ss.info(current.getClassDisplayValue());
// Info: Task |
getConditionQuery()
Use this method to return the current query condition.
Return:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const task = new SimpleRecordSecure('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: |
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):
Return:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const current = new SimpleRecordSecure('task');
current.get('163663310116371174');
ss.info(current.getDisplayValue('caller'));
ss.info(current.getValue('caller'));
// Info: John Doe
// Info: 155931135900000001 |
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:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const record = new SimpleRecordSecure('user');
const insertedRecordId = record.insert();
if (insertedRecordId == 0) {
ss.info(record.getErrors());
}
// Info: ["The \"\"Login\" [username]\" field is mandatory. (record id: )",... |
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):
Return:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const current = ss.getUser();
const fieldLabel = current.getLabel('username');
ss.addErrorMessage('Field "' + fieldLabel + '" cannot be blank');
// Field "Login" cannot be blank |
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 method.
Return:
String
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
(function executeRule(current, previous = null /*not null only when action is update*/) {
if (current.getReModelId()) {
const model = new SimpleRecordSecure('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:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const task = new SimpleRecordSecure('task');
task.query();
ss.addInfoMessage('All Tasks Count: ' + task.getRowCount());
// All Tasks Count: 2 |
getTableName()
Use this method to get the name of the current table.
Return:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const current = ss.getUser();
ss.info('/list/' + current.getTableName() + '/' + current.sys_id);
// Info: /list/user/155931135900000001 |
Use this method to get the title of the defined RE attribute.
Parameter:
Return:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const current = new SimpleRecordSecure('task');
current.get('163638951512716126');
if (current.sys_id) {
ss.info(current.rem_attr.getTitle('reviewed'));
}
// Info: Review completed
const current = new SimpleRecordSecure('task');
current.get('163638951512716126');
if (current.sys_id) {
ss.info(current.rem_attr.getTitle('reviewed'));
}
// Info: Review completed |
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):
Return:
This method returns the value of the specified object attribute.
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const current = ss.getUser();
const user = new SimpleRecordSecure('user');
user.addQuery('timezone_id', current.getValue('timezone_id'));
user.selectAttributes('sys_id');
user.query();
ss.info(user.getRowCount() + ' users have the same timezone as you');
// Info: 24 users have the same timezone as you |
hasAttachment()
Use this method to check whether the specified record has an attachment or not.
Return:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const current = new SimpleRecordSecure('task');
current.get('163663310116371174');
const hasAttach = 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:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const taskRecord = new SimpleRecordSecure('task');
ss.info(taskRecord.getAttributes().caller);
taskRecord.initialize();
ss.info(taskRecord.getAttributes().caller);
// Info:
// Info: 155931135900000001 |
insert()
Use this method 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:
- 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.
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const newTask = new SimpleRecordSecure('task');
newTask.subject = 'Subtask';
const insertedTaskID = newTask.insert();
ss.info(`/record/task/${insertedTaskID}`);
// Info: /record/task/163675231910113745 |
isTableVcsEnabled()
Use this method to verify whether the Is VCS enabled checkbox is selected in the specified table.
Return:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const current = new SimpleRecordSecure('user');
ss.info(current.isTableVcsEnabled());
// Info: false |
matchesCondition(condition)
Use this method to verify whether the current record meets the specified condition.
Parameter(s):
Return:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const task = new SimpleRecordSecure('task');
task.description = 'email';
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.
Return:
If the query is empty, this method returns false.
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const user = new SimpleRecordSecure('user');
user.setLimit(1);
user.query();
user.next();
ss.info(user.sys_id);
// Info: 100000000000000000 |
orderBy(column)
Use this method to sort the records in the ascending order.
Tip |
---|
Call this method several times to order by multiple columns. |
Parameter(s):
Return:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const firstLog = new SimpleRecordSecure('sys_log');
firstLog.orderBy('sys_created_at'); // oldest record first
firstLog.addQuery('message', 'like', 'Connection');
firstLog.setLimit(1);
firstLog.selectAttributes(['message', 'sys_created_at']);
firstLog.query();
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):
Return:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const lastComment = new SimpleRecordSecure('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:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const tasks = new SimpleRecordSecure('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.
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):
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:
This method returns a SimpleRecordSecure 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 | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const record = new SimpleRecordSecure('user');
record.selectAttributes('email');
record.query();
record.next();
ss.info(record.getAttributes());
// Info: {"email":"john.doe@email.com","sys_id":"162423321917274937"} |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const record = new SimpleRecordSecure('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.
Parameter(s):
Return:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const current = new SimpleRecordSecure('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):
Return:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const record = new SimpleRecordSecure('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):
Return:
This method does not return a value.
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const task = new SimpleRecordSecure('task');
task.addQuery('state', '7'); // Draft
task.query();
ss.info(task.getRowCount());
task.setMultipleValue('state', '2'); // Open
// task.updateMultiple(); |
Use this method to specify the ID of a particular RE model. To get the model ID, use the getReModelId method.
Parameter(s):
If the reModelId parameter is set to null, the REM related to the record will be detached.
Return:
This method does not return a value.
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const task = new SimpleRecordSecure('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 |
---|
|
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
(function executeRule(current, previous = null /*not null only when action is update*/ ) {
// before rule triggered by service change
ss.importIncludeScript('getRemAttributes');
const rmc = new SimpleRecordSecure('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); |
Use this method to set a field value of the current record.
Parameter(s):
Return:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const task = new SimpleRecordSecure('task');
task.setValue('subject', 'mail');
task.insert(); |
silentMode(enable)
Use this method to update a record without executing related business logic that is implemented with the business rules, notifications, workflows and others.
Return:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const task = new SimpleRecordSecure('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 //task.updateMultiple(); |
update()
Use this method to update a record in the database.
Info |
---|
Use this method for existing records.
|
Return:
- If the record is not updated, the method returns '0' and generates a message containing a list of errors.
- The method returns an ID of the updated record if no errors occur.
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const current = new SimpleRecordSecure('user');
current.get(ss.getUserId());
current.timezone_id = '156076775207670452'; // UTC
ss.info(current.update());
ss.info(current.getErrors());
// Info: 155931135900000001
// Info: [] |
updateMultiple()
Use this method to update all the records in the selection.
Return:
- If validation errors occur and the record is not updated, the method returns false and generates a message containing a list of errors.
- The method returns true if no errors occur.
Example:
language | js |
---|---|
theme | Eclipse |
title | updateMultiple() |
linenumbers | true |
All of the SimpleRecordSecure methods are the same as SimpleRecord methods but they are applied according to the ACL rules.
If a user attempts to perform one of the Create, Write, or Delete operations in the database to a record they have no access to, the operation is not completed, the method getErrors() called after the operation returns the corresponding error.
If a user attempts to perform a Read operation in the database to a record they have no access to, the data is not provided, the method getErrors() called after the operation does not return any errors.
The system response to the actions prohibited by the ACL
Prohibited action | Prohibition for the record | Prohibition for the field |
---|---|---|
Create | If a user adds a record via a script and uses the insert() method, the record is not created. | If a user fills in the field via a script and uses the insert() method, the record is added with an empty field or default value for the field if there is any. |
Write | If a user adds new value for the record fields via a script with the update()method, the record is not updated. If updateMultiple() is called, the records prohibited for changes are ignored, the rest are updated. | If a user adds new value for the field via a script with the update() / updateMultiple()method , the record is updated but the values of the fields prohibited for changes remain the same. |
Delete | If a user deletes a record via a script with the deleteRecord()method, the record is not deleted. If deleteMultiple() is called and the deletion of at least one of the records from the array is prohibited, none of the records are deleted. | - |
Read | If a user requests a record via a script, the response does not include the hidden data. The element is not included in the response. | If a user requests a field data via a script, the response does not contain the hidden data. The column with the prohibited field is empty. |
Table of Contents |
---|