Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This server class provides methods to operate with database records.

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):

NameTypeMandatoryDefault Value
propertyStringYN
operatorOrValueChoice (=, Like), etc.YN
operatorOrValueMixedYN
valueMixedNNULL


Return:

TypeDescription
SimpleRecordAn object performing the request to the method.


Example:

Code Block
languagejs
titleaddOrCondition
let incident = new SimpleRecord('incident');
incident.addQuery('contact_type','email' ).addOrCondition('number','INC0000006');
incident.query();


addQuery(property, operatorOrValue, value)


This method adds a condition for the selection from the database.


Parameter(s):

NameTypeMandatoryDefault Value
propertyStringYN
operatorOrValueChoice (=, Like), etc.YN
operatorOrValueMixedYN
valueMixedNNULL


Return:

TypeDescription
SimpleRecordAn object performing the request to the method.


Example:

Code Block
languagejs
titleaddQuery
let incident = new SimpleRecord("incident");
incident.addQuery( "active", true );
incident.addQuery( "subject" , "LIKE" , "сеть" );
incident.addQuery( "sys_created_at" , "<" , "2019-04-01 00:00:00" );
incident.query();


addEncodedQuery(condition)


Adds encoded query to other queries already created.


Parameter(s)

NameTypeMandatoryDefault Value
conditionStringYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

Code Block
languagejs
themeEclipse
titleaddEncodedQuery
let incident = new SimpleRecord('incident');
incident.addEncodedQuery(‘active = 1 ’);


canCreate()


This method determines if the Access Control Rules permit inserting new records in this table.


Return:

TypeDescription
BooleanThe method returns TRUE if this operation is permitted; otherwise it returns FALSE.


Example:

Code Block
languagejs
titlecanCreate
let incident = new SimpleRecord('incident');
ss.info( incident.canCreate() );

canDelete()


This method determines if the Access Control Rules permit deleting records in this table.


Return:

TypeDescription
BooleanThe method returns TRUE if this operation is permitted; otherwise it returns FALSE.


Example:

Code Block
languagejs
titlecanDelete
let incident = new SimpleRecord('incident');
ss.info( incident.canDelete() );

canRead()


This method determines if the Access Control Rules permit reading records in this table.


Return:

TypeDescription
BooleanThe method returns TRUE if this operation is permitted; otherwise it returns FALSE.


Example:

Code Block
languagejs
titlecanRead
let incident = new SimpleRecord('incident');
ss.info( incident.canRead() );


canUpdate()


This method determines if the Access Control Rules permit updating records in this table.


Return:

TypeDescription
BooleanThe method returns TRUE if this operation is permitted; otherwise it returns FALSE.


Example:

Code Block
languagejs
titlecanUpdate
let incident = new SimpleRecord('incident');
ss.info( incident.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:

TypeDescription
BooleanThis method returns TRUE  if deleted successfully; otherwise returns false.


Example:

Code Block
languagejs
titledeleteMultiple
let incident = new SimpleRecord('incident');
incident.addQuery( 'subject' , "LIKE" , "network" );
incident.query();
incident.deleteMultiple();


deleteRecord(recordSetId)


This method deletes the current record.


Parameter(s):

NameTypeMandatoryDefault Value
recordSetIdIntegerN-1


Return:

TypeDescription
BooleanThis method returns TRUE if the record is deleted successfully; otherwise it returns FALSE.


Example:

Code Block
languagejs
titledeleteRecord
let incident = new SimpleRecord('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):

NameTypeMandatoryDefault Value
propertyOrValuename (value must be specified as well).YN
propertyOrValuemixedYN
valuemixedNNULL


Return:

TypeDescription
VoidThis method does not return a value.


Example:

Code Block
languagejs
titleget
let incident = new SimpleRecord("incident");
incident.get( "subject" , "Network does not work" )
getClassDisplayValue


getAttributes()

This method returns

the table title. If the title is not set, then returns name

an object with current record properties as keys and properties values as key values.


Return:

TypeDescription
StringTitle or name.
Example:
ObjectThe array containing attributes.


Code Block
languagejs
themeEclipse
titlegetClassDisplayValuegetAttributes
letconst incidentrec = new SimpleRecord("incident"'sys_db_table');
ssrec.info( incident.getClassDisplayValue() );

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):

NameTypeMandatoryDefault ValuePropertyStringNNULL
get(some_id);
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:

TypeDescription
Mixed
String
A field
Title or
record value
name.


Example:

Code Block
languagejs
titlegetDisplayValuegetClassDisplayValue
let incident = new SimpleRecord("incident");

incident.get(5236);
ss.info( incident.getDisplayValue( "caller_id" getClassDisplayValue() );
getErrors


getDisplayValue(property)

If the record creating, updating or deleting will fail, then this method will display error message.

Return:


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):

NameTypeMandatoryDefault Value
PropertyStringNNULL


Return:

TypeDescription
MixedA field or record
TypeDescriptionArrayThe error
value.


Example:

Code Block
languagejs
titlegetErrorsgetDisplayValue
let recincident = new SimpleRecord('sys_db_table'"incident");
rec
incident.get('name', 'task'5236);
if (!rec.deleteRecord()) {
	let errors = rec.getErrors();
 	errors.forEach(function(error) {
		ss.addErrorMessage(error);
	})
}

getLabel(property)

This method returns the field title.

Parameter(s):

NameTypeMandatoryDefault Value
ss.info( incident.getDisplayValue( "caller_id" ) );

getErrors()


If the record creating, updating or deleting will fail, then this method will display error message.

propertyStringYN

Return:

TypeDescription
Mixed
ArrayThe
field title
error value.


Example:

Code Block
languagejs
titlegetLabelgetErrors
let incidentrec = new SimpleRecord("incident"'sys_db_table');

incidentrec.get(5236'name', 'task');
ss.info( incident.getLabel( "caller_id" ) );
getTableName(
if (!rec.deleteRecord()) {
	let errors = rec.getErrors();
 	errors.forEach(function(error) {
		ss.addErrorMessage(error);
	})
}


getLabel(property)


This method returns the

current table name

field title.Return:


Parameter(s):

NameType
Description
MandatoryDefault Value
propertyString
The current table name.
YN


Return:

TypeDescription
MixedThe field title.


ExampleExample:

Code Block
languagejs
titlegetTableNamegetLabel
let incident = new SimpleRecord('"incident'");

incident.get(5236);
ss.info( incident.getTableName(getLabel( "caller_id" ) ); // incident
getValue


getTableName(

property

)


This method returns the value of the object property based on its name.

Parameter(s):

NameTypeMandatoryDefault ValuePropertyStringYN

current table name.


Return:

TypeDescription
Mixed
StringThe
value of the field
current table name.


Example:

Code Block
languagejs
titlegetValuegetTableName
let incident = new SimpleRecord('incident');

incident.query();
whiless.info( incident.nextgetTableName() ){
  ss.info(; // incident.


getValue(

'number') ); }initialize(

property)


This method

creates an empty object for the new database record.

returns the value of the object property based on its name.

Parameter(s):

Name
Return:
Type
Description
Mandatory
VoidThis method does not return a value.
Example:
Default Value
PropertyStringYN


Return:

TypeDescription
MixedThe value of the field.


Code Block
languagejs
titleinitializegetValue
let incident = new SimpleRecord("'incident"');
incident.initializequery();
while( incident.subject = "Network does not work";
incident.insert();next() ){
  ss.info( incident.getValue('number') );
}


insert()


This method creates a database record.


Return:

TypeDescription
IntegerThe Sys_id of the record created.


Example:

Code Block
languagejs
titleinsert
let incident = new SimpleRecord('incident');

incident.insert();
next

matchesCondition(condition)

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:

TypeRecord or Boolean

This method checks whether the current record meets the condition being in the current state.


NameTypeMandatoryDefault Value
conditionStringN''


TypeDescription
VoidThis method does not return a value.
Example:


Code Block
languagejs
themeEclipse
titlenextmatchesCondition
rec.descriptionlet incident = new SimpleRecord("incident")'dsc';

incidentrec.querymatchesCondition('descriptionLIKEesc');

while ( incident.next() ){

ss.info( incident.sys_id);

}

orderBy(column)

This method specifies an orderBy column.

Call this method several times to order by multiple columns.

The results are arranged in ascending order. To arrange the records in descending order, use the orderByDesc method
// 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:

Code Block
languagejs
titlenext
let incident = new SimpleRecord("incident");

incident.query();

while ( incident.next() ){

ss.info( incident.sys_id);

}


orderBy(column)


This method specifies an orderBy column.

Call this method several times to order by multiple columns.

The results are arranged in ascending order. To arrange the records in descending order, use the orderByDesc method.


Parameter(s):

NameTypeMandatoryDefault Value
columnStringYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

Code Block
languagejs
titleorderBy
let incident = new SimpleRecord('incident');
incident.orderBy('subject');
incident.query();


orderByDesc(column)


This method sorts the records in the descending order.


Parameter(s):

NameTypeMandatoryDefault Value
columnStringYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

Code Block
languagejs
titleorderByDesc
let incident = new SimpleRecord('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:

TypeDescription
VoidThis method does not return a value.


setAbortAction(flag)


This method sets a flag, indicating that will be current operation (insert/update/delete) interrupted. It used in business-rules.


Parameter(s):

NameTypeMandatoryDefault Value
column
flag
String
BooleanYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

Code Block
languagejs
titleorderBysetAbortAction
current.setAbortAction(truelet incident = new SimpleRecord('incident');
incident.orderBy('subject');
incident.query();
orderByDesc

setLimit(

column

maxNumRecords)


This method sorts the records in the descending orderSets a limit for a number of records are fetched by SimpleRecord query.


Parameter(s):

NameTypeMandatoryDefault Value
column
maxNumRecords
String
IntegerYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

Code Block
languagejs
titleorderByDescsetLimit
let incident = new SimpleRecord('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:

TypeDescriptionVoidThis method does not return a value.
incident');
incident.setLimit(30);
incident.query();


setMultipleValue(property,value)

This method sets the properties values for every entry in the current selection

setAbortAction(flag)

This method sets a flag, indicating that will be current operation (insert/update/delete) interrupted. It used in business-rules.


Parameter(s):

NameTypeMandatoryDefault Value
flagBooleanYN

Return:

TypeDescriptionVoidThis method does not return a value.

Example:

Code Block
languagejs
titlesetAbortAction
current.setAbortAction(true);

setLimit(maxNumRecords)

Sets a limit for a number of records are fetched by SimpleRecord query
propertyStringYN
valueMixedYN

Return:

TypeDescription
VoidThis property does not returns a value.


Code Block
languagejs
themeEclipse
titlesetMultipleValue
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):

NameTypeMandatoryDefault Value
maxNumRecordsInteger
propertyStringYN
valueMixedYN


Return:

TypeDescription
VoidThis
method
property does not
return
returns a value.


Example:

Code Block
languagejs
titlesetLimitsetValue
let incident = new SimpleRecord('incident');

incident.setLimit(30setValue("subject" , "Help me");

incident.queryinsert();
setValue


update(

property, value

reason)


This method

sets the value of the field in the current

updates a database record.


Parameter(s):

NameTypeMandatoryDefault Value
property
reasonString
YN
N
valueMixedY
''


Return:

TypeDescription
VoidThis property does not returns a value
IntegerSys_id of the updated record.


Example:

Code Block
languagejs
titlesetValueupdate
let incident = new SimpleRecord('incident');
incident.get(5246);
incident.setValue("subject" ,+= "Help me(repair)");

incident.insertupdate();
update


updateMultiple(

reason

)

This method updates a database record.

Parameter(s):

NameTypeMandatoryDefault ValuereasonStringN''

all the selection entries.

Return:

TypeDescription
IntegerSys_id of the updated record.
Example:
VoidThis property does not returns a value.


Code Block
languagejs
themeEclipse
titleupdateupdateMultiple
letconst incidentrec = new SimpleRecord('task');
rec.addQuery('state', 'incidentCreated');
incidentrec.getquery(5246);
incident.subject += " (repair)";
incident.updaterec.setMultipleValue('state', 'Confirmed');
rec.updateMultiple();


Table of Contents
absoluteUrltrue
classfixedPosition