Versions Compared

Key

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

This class provides methods to configure forms. These methods These methods can only be used on the client side only.

You can also use these methods to configure the dependencies between fields and values. For example, changing values in of the fields or clear clearing the fields.

SimpleForm(table, sys_id)


Instantiates a new SimpleForm object.

NameTypeMandatoryDefault Value
tableStringYN
sys_idStringYN


Code Block
languagejs
themeEclipse
titleSimpleForm
linenumberstrue
const formObject = new SimpleForm(s_form.table, s_form.sysId);

Return:

TypeDescriptionObjectThis method returns a form object.

s_form.addErrorMessage(message)

This method displays the error toast message in the bottom right corner.

Parameter(s):

NameTypeMandatoryDefault ValuemessageStringYN

Return:

TypeDescriptionVoidThis method does not return a value.
window.s_widget_custom.submit = async function () {
  await s_widget.serverUpdate();
  const tableName = s_widget.getFieldValue('table_name');
  const recordId = s_widget.getFieldValue('record_id');

  const builtInForm = new SimpleForm(tableName, recordId);
  
  await builtInForm.save().then(s_form.save());
  s_modal.setShow(false);
  s_go.reloadWindow();
}


Example:

Code Block
languagejs
themeEclipse
titleaddErrorMessage
linenumberstrue
s_form.addErrorMessage('Need more information');

s_form.addInfoMessage(message, durationMilliseconds)

This method displays an informational toast message in the bottom right corner. The message is expirable, its expire period (in milliseconds) should be specified by second parameter.

Parameter(s):

NameTypeMandatoryDefault ValuemessageStringYNdurationMillisecondsNumberYN

Return:

TypeDescription
Void
ObjectThis method
does not return a value.

Example:

Code Block
languagejs
themeEclipse
titleaddInfoMessage
linenumberstrue
s_form.addInfoMessage('Record successfully created', 1000);

s_form.addOption(fieldName, choiceValue)

This method adds a choice option to the end of the choice list field (if option with passed choiceValue defined for fieldName for current table options set).

NotePlease note that this method is asynchronous; for better performing, use the await keyword like shown in the code example below
returns a form object.

Global variable usage


Within any record form, you can use predefined global variables.

Variable

Description

currentFieldLabel

Defines a link to a Wrapper object for a field. The variable is used with the getColumnId() method.
For example, window.currentFieldLabel.getColumnId().

One of the usage cases of this variable is the field context menu call. 

Image Added

currentUiAction

Contains an object with an ID of the UI action record. It is used when the context menu is called.

One of the usage cases is receiving information about UI actions when calling the context menu.

Image Added

s_form.addErrorMessage(message)


This method displays the error toast message in the bottom right corner.


Parameter(s):

NameTypeMandatoryDefault Value
fieldName
messageStringYN
choiceValueString
YN


Return:

TypeDescription
VoidThis method does not return
a
value.


Example:

Code Block
languagejs
themeEclipse
titleaddOptionaddErrorMessage
linenumberstrue
const states = ['-1', '0', '2', '5'];
s_form.clearOptionsaddErrorMessage('state');
states.forEach(stateValue => {
    await s_form.addOption('state', stateValue);
}Please enter a valid email address using the following format: joe@example.com');

s_form.

clearMessages

addInfoMessage(message, durationMilliseconds)


This method is used to close all kinds of messages (both informational and error) in the form.displays an informational toast message at the bottom right corner. The message disappears after a certain period of time. Specify this period in milliseconds in the second parameter.


Parameter(s):

NameTypeMandatoryDefault Value
messageStringYN
durationMillisecondsNumberNN


Return:

TypeDescription
VoidThis method does not return
a
value.


Example:

Code Block
languagejs
themeEclipse
titleclearMessages()addInfoMessage
linenumberstrue
s_i18nform.getMessageaddInfoMessage('EndLink datecopied time cannot be less than start date time', (response) => {
  s_form.clearMessages();
  s_form.addErrorMessage(response);
  return false; // abort form submit
});to clipboard', 2000);

s_form.

clearOptions

addSuccessMessage(

fieldName

message, durationMilliseconds)


Using this method, you can remove all options from the choice listThis method displays a message about a successul action in the bottom right corner. The message disappears after a certain period of time. Specify this period in milliseconds in the second parameter.


Parameter(s):

NameTypeMandatoryDefault Value
fieldName
messageStringYN
durationMillisecondsNumberNN


Return:

TypeDescription
VoidThis method does not return
a
value.


Example:

Code Block
languagejs
themeEclipse
titleclearOptionsaddSuccessMessage
linenumberstrue
const choices =
  {
    "Phone": "10",
    "Email": "20",
    "Self-service": "30"
  };
const choicesArray = Object.keys(choices);
s_form.clearOptions('contact_type');
choicesArray.forEach((choiceValue) => {
  s_form.addOption('contact_type', choices[choiceValue]);
});

s_form.clearValue(fieldName)

This method is used to clear out any field, i.e., delete its value.

Using this method you can select a value and remove it from the field.

It returns TRUE if it is able to clear the value from the field.

It returns FALSE in the following cases:

  • if the column_type is either Boolean or Record Class;
  • if the column_name is equal to 'sys_id';
  • if the column_type is Choice and it does not have a default value.

If the method returns FALSE, then the field. will not be cleared.

Parameter(s):

s_form.addSuccessMessage('Record was successfully added!', 3000);

s_form.addWarningMessage(message, durationMilliseconds)


This method displays a warning message in the bottom right corner. The message disappears after a certain period of time. Specify this period in milliseconds in the second parameter.

Parameter(s):

NameTypeMandatoryDefault Value
messageStringYN
durationMillisecondsNumberNN


Return:

TypeDescription
VoidThis method does not return value.


Example:

Code Block
languagejs
themeEclipse
titleaddWarningMessage
linenumberstrue
s_form.addWarningMessage('This record has been modified by another user', 3000);

s_form.addOption(fieldName, choiceValue)


This method adds a choice option to the end of the choice list field if option with passed choiceValue defined for fieldName for current table options set.

Note

Please note that this method is asynchronous; for better performance, use the await keyword as shown in the code example below.


Parameter(s):

NameTypeMandatoryDefault Value
fieldNameStringYN
choiceValue
NameTypeMandatoryDefault Value
fieldNameStringYN


Return:

TypeDescription
Boolean
PromiseThis method returns
the boolean value (TRUE or FALSE) in the cases described above
a Promise object.


Example:

Code Block
languagejs
themeEclipse
titleclearValueaddOption
linenumberstrue
if (!s_form.getValue('sprint')) const states = ['-1', '0', '2', '5'];

s_form.clearOptions('state');
states.forEach(async (stateValue) => {
  await s_form.clearValueaddOption('pointsstate', stateValue);
})

s_form.

formId

This class property returns the current form ID for the current user. The form view ID is an ID of the record in the UI Forms (sys_ui_form) dictionary.

clearMessages()


This method is used to close all kinds of messages (both informational and error) in the form.


ReturnReturn:

TypeDescription
StringReturns the record form view ID (ID of the record in the UI Forms (sys_ui_form) dictionary).

Example:

VoidThis method does not return value.


Code Block
languagejs
themeEclipse
titleformIdclearMessages()
linenumberstrue
const url = new URL(`${API_BASE_URL}/export/excel`);
if (typeof s_form !== "undefined")s_i18n.getMessage('End date time cannot be less than start date time', (response) => {
  url.searchParams.set('form_id',s_form.clearMessages();
  s_form.formIdaddErrorMessage(response);
}
window.open(url, "_blank"););
return false; // abort form submit

s_form.

getLabelOf

clearOptions(fieldName)


The method returns the label text valueUsing this method, you can remove all options from the choice list.


Parameter(s):

NameTypeMandatoryDefault Value
fieldNameStringYN


Return:

TypeDescription
StringThe label text
VoidThis method does not return a value.


Example:

Code Block
languagejs
themeEclipse
titlegetLabelOfclearOptions
linenumberstrue
if (const choices = [
  "Phone",
  "Email",
  "Self-service"
];

s_form.getValueclearOptions('namecontact_type').match(/[\/|_*]/g));
choices.forEach(async (choiceValue) => {
  s_form.addErrorMessage(`Field "await s_form.getLabelOfaddOption('name')" contains invalid characters.`contact_type', choiceValue);
});

s_form.

getREMDisplayValue

clearValue(fieldName) 

This method gets the displayable REM attribute value.

Parameter(s):

Return:

Name

Type

Mandatory

Default Value

fieldNameStringYN

Type

Description

StringMethod returns attribute displayable value.
Anchor
s_form.clearValue
s_form.clearValue


This method is used to clear out any field, i.e., delete its value.

Using this method you can select a value and remove it from the field.

It returns 'false' if it is unable to clear the value of the field in the following cases:

  • if the column_type is either Boolean or Record Class.
  • if the column_name is equal to 'sys_id'.
  • if the column_type is Choice and it does not have a default value.

If the method returns 'true', then the field will be cleared

Example:

Code Block
languagejs
themeEclipse
titlegetREMDisplayValue
s_form.addInfoMessage(`Service "${s_form.getREMDisplayValue('service')}" is not available`);

s_form.getREMLabelOf(fieldName)

This message gets the plain text value of the REM attribute label.


Parameter(s):

NameTypeMandatoryDefault Value
fieldNameStringYN


Return:

TypeDescription
String
BooleanThis method returns
string containing attribute label value.
the boolean value ('true' or 'false') in the cases described above.


Example:

Code Block
languagejs
themeEclipse
titlegetREMLabelOfclearValue
linenumberstrue
if (!s_form.getValue('name').match(/[\/|_*]/gsprint')) {
  s_form.addErrorMessage(`Field "s_form.getREMLabelOf('name')" contains invalid characters.`clearValue('points');
}

s_form.

getREMValue

isFieldChanged(fieldName)


This method gets the attribute value.

Parameter(s):

is used to check if the specified field has been changed or not.


Info

If there is a client script running on the specified form and changing it, this method will return 'true'. It is not necessary that the change is made by a user, the form can be changed by a script.

Parameter(s):

Name

Type

NameType
MandatoryDefault Value
fieldNameStringYN


Return:

TypeDescription
Object
Boolean

This method returns

the current attribute object

'true' if the specified field has been changed; otherwise returns 'false'.


Example:

Code Block
languagejs
themeEclipse
titlegetREMValues_form.isFieldChanged
linenumberstrue
if (!!s_form.getREMValueisFieldChanged('state')) {
&&  s_form.hideFieldMsggetValue('state') != 'new') {
  return false; // abort form submit
}

s_form.formId


This class property returns the current form

.getSections()Using this method, you can get an array of sections

ID for the current user. The form view ID is an ID of the record in the UI Forms (sys_ui_form) dictionary.

Return:

Type

Description

Array of HTML elementsThe form sections.

s_form.getSectionNames()

This method allows returning an array, which will contain the names of all sections, visible or not.

Return:

TypeDescriptionArray of stringsThis method returns array containing section names.
StringThis method returns the record form view ID (ID of the record in the UI Forms (sys_ui_form) dictionary).


Example:

Code Block
languagejs
themeEclipse
titleformId
linenumberstrue
const url = new URL(`${API_BASE_URL}/export/excel`);
if (typeof s_form !== "undefined") {
  url.searchParams.set('form_id', s_form.formId);
}
window.open(url, "_blank");

s_form.getChanges()


This method is used to retrieve information about changed fields: field name, previous value, current value.

Info

If there is a client script running on this form and changing it, the getChanges() method will include such fields in the array. It is not necessary that the change is made by a user, it can be done by a script.

s_form.getTableName()

This method returns the table name to which the specified record relates.

Note

The method returns system table name, not the table title. Example:

Table nameitsm_incidentTable titleIncidents

Return:

TypeDescriptionStringSystem table name.Example:
Code Block
languagejs
themeEclipse
titlegetTableName
linenumberstrue
if (['article', 'model'].includes(s_form.getTableName())) {
    s_form.setSectionMandatory('Review', true);
} else {
    s_form.setSectionMandatory('Review', false);
}

s_form.getUniqueValue()

This method returns the unique record ID (sys_id).

Return:

TypeDescription
StringReturns the record ID; otherwise, returns NULL.
Example:
Array

This method returns an array of objects with field changes. Object contains field name, previous value and the current value.


Code Block
languagejs
themeEclipse
titlegetUniqueValues_form.getChanges
linenumberstrue
const sysId = if (s_form.getUniqueValueisChanged()); {
  const currentRecordchangedFields = new SimpleRecord(s_form.tablegetChanges();
currentRecord.get(sysId, ()  let payload = {};
  changedFields.forEach((field) => {
  if (currentRecord.type  payload[field.fieldName] == 'unavailable') { field.currentValue;
  });
  return false; // abort form submit
  }
});SimpleStorage.setItem('payload', payload);
}


s_form.

getValue

getLabelOf(fieldName)


This The method returns the internal (written down to the database) value of the specified field.

Warning

IsDisplayValue parameter was maintained in earlier versions but has been deprecated from version 1.1 and no longer valid. Avoid using it in your scripts. To get a displayed value of a field, use the s_form.getDisplayValue method.

Parameter(s):

NameTypeMandatoryDefault ValuefieldNameStringYN

Return:

TypeDescriptionString

This method returns the internal (written down to the database) value of the specified field.

label text value.


Parameter(s):

NameTypeMandatoryDefault Value
fieldNameStringYN


Return:

TypeDescription
StringThis method returns a string containing the attribute label value.


Example:

Code Block
languagejs
themeEclipse
titlegetLabelOf
linenumberstrue
const FIELD_LABEL = s_form.getLabelOf('username');
s_form.addErrorMessage(`Field "${FIELD_LABEL}" contains invalid characters.`);

s_form.getREMDisplayValue(fieldName)


This method gets the displayable REM attribute value.


Parameter(s):

Example:

Code Block
languagejs
themeEclipse
titlegetValue
linenumberstrue
const callerId = s_form.getValue('caller_id');
if (!callerId) {
  const callerRecord = new SimpleRecord('employee');
  callerRecord.get(callerId, ()=> {
    if (!!callerRecord.sys_id &&
      callerRecord.personal_schedule) {
      await s_form.setValue('schedule', callerRecord.personal_schedule);
    } else {
      s_form.addInfoMessage('Users schedule is not defined');
    }
  });
}

s_form.getDisplayValue(fieldName)

This method returns the displayed value of the field.

Parameter(s):

value

Name

Type

Mandatory

Default

Value

fieldNameStringYN

Return:

Type

Description

String
The displayed value of the specified field
This method returns the attribute displayable value.

Example:

Code Block
languagejs
themeEclipse
titlegetDisplayValuegetREMDisplayValue
linenumberstrue
s_form.addInfoMessageaddErrorMessage(`Service "${s_form.getDisplayValuegetREMDisplayValue('service')}" is nonot available`);


s_form.

goBack

getREMLabelOf(fieldName)


This method allows to perform redirect to the previous page; if not possible then redirect direction is a list view of the current essence (for example, to a list of incidents out of a incident record).gets the label text value of the REM attribute.


Parameter(s):

Name

Type

Mandatory

Default Value

fieldNameStringYN


Return:

Type

Description

VoidStringThis method does not return a returns a string containing the attribute label value.

Example:

Code Block
languagejs
themeEclipse
titlegoBackgetREMLabelOf
linenumberstrue
ifconst (s_form.hasChanges()) {
    FIELD_LABEL = s_form.savegetREMLabelOf().then(() => 'phone');
s_form.goBack());
} else {
    s_form.goBack();
}addErrorMessage(`Field "${FIELD_LABEL}" contains invalid characters.`);

s_form.

hasChanges

getREMValue(fieldName)


This method allows to get information whether a record form has been changed or not.gets the REM attribute value.

Parameter(s):

Name

Type

Mandatory

Default Value

fieldNameStringYN

Return:

Type

Description

Boolean
String
The
This method returns
'true' if any changes were made on the record form; otherwise, it returns 'false'
the database value of the specified field.

Example:

Code Block
languagejs
themeEclipse
titlehasChangesgetREMValue
linenumberstrue
if (s_form.hasChangesgetREMValue('model')) {
    s_form.savehideFieldMsg().then(() => 'model');
}

s_form.

goBack()); } else { s_form.goBack(); }

getSections()


Using this method, you can get an array of sections.


Return:

TypeDescription
Array of HTML elementsThe form sections.

s_form.

hideFieldMsg

getSectionNames(

input

)


This method , as opposed to the s_form.showFieldMsg() method, allows to hide informational or error messages on the specified form field.

Parameter(s):

allows returning an array, which will contain the names of all sections, visible or not.


Return:

TypeDescription
Array of stringsThis method returns an array containing section names.

s_form.getTableName()


This method returns the table name to which the specified record relates.

Note

The method returns the system table name, not the table title. Example:

Table nameitsm_incident
Table titleIncidents


NameTypeMandatoryDefault ValueinputStringYN

Return:

TypeDescription
VoidThis method does not return a value.
StringSystem table name.


Example:
Code Block
languagejs
themeEclipse
titlehideFieldMsggetTableName
linenumberstrue
if (!!const TABLE_NAME = s_form.getValuegetTableName('state')) {
  s_form.hideFieldMsg('state');
});
console.log(TABLE_NAME);

s_form.

hideRelatedLists

getUniqueValue()


Using this method, you can hide all related lists on the formThis method returns the unique record ID (sys_id).


Return:

TypeDescription
Void
StringThis method
does not return a value.
returns the record ID; otherwise, returns NULL.


Example:

Code Block
languagejs
themeEclipse
titlehideRelatedListgetUniqueValue
linenumberstrue
if (const TABLE_NAME = s_form.getValuegetTableName('type') == 'internal') {
  ;
const RECORD_ID = s_form.hideRelatedListsgetUniqueValue();
}

s_form.hideRelatedList(relListTitle)

Using this method, you can specify a related list you want to hide.

Parameter(s):

const currentRecord = new SimpleRecord(TABLE_NAME);
currentRecord.get(RECORD_ID, ()=> {
  if (currentRecord.sys_id === RECORD_ID) {
    s_form.addInfoMessage(currentRecord.sys_created_at);
  }
});

s_form.getValue(fieldName)


This method returns the database value of the specified field.


Parameter(s):

NameNameTypeMandatoryDefault Value
relListTitlefieldNameStringYN


Return:

TypeDescription
Void
String

This method

does not return a value

returns the database value of the specified field.


Example:

Code Block
languagejs
themeEclipse
titlehideRelatedListgetValue
linenumberstrue
ifconst callerId = (s_form.getValue('typecaller_id') == 'external';
if (!callerId) {
  const  s_form.hideRelatedListcallerRecord = new SimpleRecord('Customeremployee');
}

s_form.isNewRecord()

If the record was never saved, this method returns TRUE; otherwise, it returns FALSE.

Return:

TypeDescriptionBooleanIf the record was never saved then this method returns TRUE; otherwise, it returns FALSE.

Example:

Code Block
languagejs
themeEclipse
titleisNewRecord
linenumberstrue
if (!!s_form.isNewRecord()  callerRecord.get(callerId, ()=> {
    if (callerRecord.sys_id &&
      callerRecord.personal_schedule) {
      await s_form.setValue('stateschedule', 'new');
  callerRecord.personal_schedule);
    } else {
      s_form.setReadOnlyaddInfoMessage('state', trueUsers schedule is not defined');
    }
  });
}

s_form.

isSectionVisible

getDisplayValue(

sectionName

fieldName)


This method defines if a specified section is visible or notreturns the displayed value of the field.


Parameter(s):

NameTypeMandatoryDefault
Value
value
sectionName
fieldName
string
StringYN


Return:

TypeDescription
BooleanThis method returns TRUE if the section is visible; otherwise, it returns FALSE.
StringThe displayed value of the specified field.


Example:

Code Block
languagejs
themeEclipse
titlegetSectionNamesgetDisplayValue
linenumberstrue
if (s_form.isSectionVisible('Instructions')) {
  addInfoMessage(`Service "${s_form.addInfoMessagegetDisplayValue('service'Check)}" outis the "Instructions" section', 5000not available`);
}

s_form.

removeOption

goBack(

fieldName, choiceValue

)

Using this method, you can specify and delete an option from the list.

Parameter(s):


This method allows performing redirect to the previous page; if not possible then redirect to the list view of the current essence, for example, to a list of incidents out of a incident record.


NameTypeMandatoryDefault ValuefieldNameStringYNchoiceValueStringYN

Return:

Type

Description

VoidThis method does not return
a
value.


Example:

Code Block
languagejs
themeEclipse
titleremoveOptiongoBack
linenumberstrue
const serviceId = if (s_form.getValueisChanged('service');
if (!!serviceId) {
  const service = new SimpleRecord('sys_cmdb_ci_service');
  service.get(serviceId, ()=> {
    if (service.business_criticality > '1') {
      s_form.removeOption('impact', 'low');
      s_form.removeOption('urgency', 'low');
    }
  });
}

s_form.save()

s_form.save().then(() => s_form.goBack());
} else {
  s_form.goBack();
}


s_form.isChanged()


This method allows to get information whether a record form has been changed or notThis method saves the record without leaving its form (just updating).


Return:

Type

Description

Object
Boolean
This method returns a promise containing specific data.
The method returns 'true' if any changes were made on the record form; otherwise, it returns 'false'.


Example:

Code Block
languagejs
themeEclipse
titlesave()isChanged
linenumberstrue
if (s_form.saveisChanged().finally(__resolveServerResponse);) {
  s_form.save().then(() => s_form.goBack());
} else {
  s_form.goBack();
}

s_form.

setLabelOf

hideFieldMsg(fieldName

, value

)


This method sets the text value of the field labelmethod, as opposed to the s_form.showFieldMsg() method, allows hidding informational or error messages in the specified form field.


Parameter(s):

NameTypeMandatoryDefault Value
fieldName
StringYN
value
StringYN


Return:

TypeDescription
VoidThis method does not return
a
value.


Example:

Code Block
languagejs
themeEclipse
titlesetLabelOfhideFieldMsg
linenumberstrue
if (s_form.table == 'user') {  
  s_form.setLabelOf('email', 'Email'); 
} elsegetValue('state')) {
  s_form.setLabelOfhideFieldMsg('email', 'Personal Email'state'); 
}

s_form.

setSectionMandatory

hideRelatedLists(

sectionName, mandatory

)

This method allows making the specified section mandatory.

Parameter(s):

NameTypeMandatoryDefault ValuesectionNameStringYNmandatoryBooleanYN

Return:


Using this method, you can hide all related lists on the form.


Return:

TypeDescription
VoidThis method does not return
TypeDescriptionVoidThis method does not return a
value.


Example:

Code Block
languagejs
themeEclipse
titlesetSectionMandatoryhideRelatedList
linenumberstrue
if (s_form.getValue('statetype') == '7internal') { // Completed
  s_form.setSectionDisplay('Closure Information', truehideRelatedLists();
  }

s_form.

setSectionMandatory('Closure Information', true); s_form.setMandatory('closure_code', true); s_form.setMandatory('closure_notes', true); }

isMandatory(fieldName)


This method is used to check if the specified field is mandatory or not.

Parameter(s)

s_form.setMandatory(fieldName, mandatory)

This method is used to change a specified field to mandatory field, i.e., it cannot be null.

Parameter(s):

NameTypeMandatoryDefault Value
fieldNameStringYN
mandatory
BooleanYN

Return:

TypeDescription
Void
BooleanThis method
does not return a value
returns 'true' if the field is mandatory; otherwise returns 'false'.

Example:

Code Block
languagejs
themeEclipse
titlesetMandatorys_form.isMandatory
linenumberstrue
const mandatoryColumn =
  (scriptType == 'onChange' || scriptType == 'onCellEdit');
if (s_form.isMandatory('state') && !s_form.getValue('state')) {
  s_form.setMandatoryaddInfoMessage('column_id', mandatoryColumn);State cannot be None');
}

s_form.

setReadOnly

hideRelatedList(

fieldName, readOnly

relListTitle)

This method is used to change a specified field to read-only or editable.

If the field is mandatory, it cannot be set to read-only. First, use the s_form.setMandatory() method and then make it read-only.


Using this method, you can specify a related list you want to hide.


Parameter(s):

NameTypeMandatoryDefault Value
fieldName
relListTitleStringYN
readOnlyBooleanYN


Return:

TypeDescription
VoidThis method does not return
a
value.


Example:

Code Block
languagejs
themeEclipse
titlesetReadOnlyhideRelatedList
linenumberstrue
if (!!s_form.getValue('any_tablestype') == 'external') {
  s_form.setReadOnlyhideRelatedList('table_id', trueCustomer');
  }

s_form.

setMandatory('table_id', false); s_form.setVisible('table_id', false); }

isNewRecord()


If the record was never saved, this method returns 'true'; otherwise, it returns 'false'.


Return:

TypeDescription
BooleanIf the record was never saved then this method returns 'true'; otherwise, it returns 'false'

s_form.setREMLabelOf(fieldName, value)

This method allows changing the displayable attribute label.

Parameter(s):

Name

Type

Mandatory

Default Value

fieldNameStringYNvalueStringYN

Return:

Type

Description

StringThis method returns new value of the attribute label
.


Example:

Code Block
languagejs
themeEclipse
titlesetREMLabelOfisNewRecord
linenumberstrue
if (s_form.table == 'user'isNewRecord()) {
  
await  s_form.setREMLabelOfsetValue('emailstate', 'Emailnew');
} else {
  s_form.setREMLabelOfsetReadOnly('emailstate', 'Personal Email'true);
}

s_form.

setREMMandatory

isReadonly(fieldName

, mandatory

)


This method allows to make a field specified by REM attribute mandatoryis used to check if the specified field is editable or read-only.


Parameter(s):

NameTypeMandatoryDefault Value
fieldNameStringYN
mandatoryBooleanY
'true'


Return:

TypeDescription
BooleanThis method returns
"
'true
" if its execution has been successful; otherwise, it returns "false"
' if the field is read-only; otherwise returns 'false'.


Example:

Code Block
languagejs
themeEclipse
titlesetREMMandatorys_from.isReadonly
linenumberstrue
const mandatoryColumn =
  (scriptType == 'onChange' || scriptType == 'onCellEdit');
if (!s_form.isReadonly('state')) {
  await s_form.setREMMandatorysetValue('column_idstate', mandatoryColumn'new');
}

s_form.

setREMReadOnly

isSectionVisible(

fieldName, readonly

sectionName)


This method allows to make defines if a field specified by REM attribute read-onlyspecified section is visible or not.


Parameter(s):

NameTypeMandatoryDefault Value
fieldName
sectionName
String
stringYN
readonlyBooleanY'true'


Return:

TypeDescription
BooleanThis method returns
"
'true
" if its execution has been successful
' if the section is visible; otherwise, it returns
"
'false
"
'.
Example:


Code Block
languagejs
themeEclipse
titlesetREMReadOnlygetSectionNames
linenumberstrue
if (!!s_form.isNewRecordisSectionVisible('Instructions')) {
  s_form.setValueaddInfoMessage('state', 'new');
  s_form.setREMReadOnly('state', trueCheck out the "Instructions" section', 5000);
}

s_form.

setREMValue

isValid(

fieldName, databaseValue

)


This method allows to set a value of the REM attribute label.

Parameter(s):

Name

Type

Mandatory

Default Value

fieldNameStringYNdatabaseValueObjectYN

Return:

Type

Description

Void

is used to check if the specified form is valid or not.


Return:

TypeDescription
BooleanThis method returns 'true' if the form is valid; otherwise, returns 'false'.


Note

It makes sense to use this method if the form contains fields of the Date, Date/Time and Date/Time Specific types, due the method does not support validation checks for fields of other types

This method does not return a value

.


Example:

Code Block
languagejs
themeEclipse
titlesetREMValues_form.isValid
linenumberstrue
if (!!s_form.isNewRecordisValid()) {
  s_form.setREMValueaddErrorMessage('name', 'Name created by systemThis form is invalid');
}

s_form.

setREMVisiblle

isVisible(fieldName

, display

)


This method allows to define visibility of the field specified by REM attributeis used to check if the specified field is visible or not.

Parameter(s):

NameTypeMandatoryDefault Value
fieldNameString
YNdisplay
Boolean
YN

Return:

TypeDescription
Void
Boolean
This method does not return a value
The method returns 'true' if the field is visible; otherwise returns 'false'.

Example:

Code Block
languagejs
themeEclipse
titlesetREMvisible
s_form.setREMVisible('chronology', !s_form.isNewRecord());

s_form.setSectionDisplay(sectionName, display)

Using this method, you can specify a section you want to hide
Eclipse
titles_form.isVisible
linenumberstrue
if (s_form.isVisible('state')) {
  s_form.setSectionDisplay('Controls', true);
}

s_form.refreshUiActions()


This method reloads all UI actions on the form and recalculates the server condition defined for these UI actions without refreshing the page.

Return:

TypeDescription
VoidThis method does not return a value.


Code Block
languagejs
themeEclipse
titles_form.refreshUiActions()
linenumberstrue
const stateValue = s_form.getValue('state');
if (stateValue == 'in-progress') {
    s_form.refreshUiActions();
}


s_form.removeOption(fieldName, choiceValue)


Using this method, you can specify and delete an option from the list.


Parameter(s):

NameTypeMandatoryDefault Value
fieldNameStringYN
choiceValueStringYN


Return:

TypeDescription
VoidThis method does not return value.


Example:

Code Block
languagejs
themeEclipse
titleremoveOption
linenumberstrue
const serviceId = s_form.getValue('service');
if (serviceId) {
  const service = new SimpleRecord('sys_cmdb_ci_service');
  service.get(serviceId, ()=> {
    if (service.business_criticality > '1') {
      s_form.removeOption('impact', 'low');
      s_form.removeOption('urgency', 'low');
    }
  });
}


s_form.save()


This method saves the record without leaving its form.


Return:

TypeDescription
StringThis method returns the ID of the saved record.


Example:

Code Block
languagejs
themeEclipse
titlesave()
linenumberstrue
const sysId = await s_form.save().finally(__resolveServerResponse);
await s_user.setPreference(preferenceApplicationName, packApplicationId);
await s_user.setPreference(preferenceLocalPackName, sysId);
await s_pref.refresh();


s_form.setLabelOf(fieldName, value)


This method sets the text value of the field label.


Parameter(s):

NameTypeMandatoryDefault Value
fieldNameStringYN
valueStringYN


Return:

TypeDescription
VoidThis method does not return value.


Example:

Code Block
languagejs
themeEclipse
titlesetLabelOf
linenumberstrue
if (s_form.getTableName() == "employee") {  
  s_form.setLabelOf("email", "Personal Email");
  s_form.setLabelOf("manager.email", "Manager's Email");
} else {
  s_form.setLabelOf("email", "Email");
}


s_form.setMandatory(fieldName, mandatory)


This method is used to change a specified field to a mandatory field, i.e., it cannot be null.


Parameter(s):

NameTypeMandatoryDefault Value
fieldNameStringYN
mandatoryBooleanNtrue


Return:

TypeDescription
Boolean

This method returns 'true' if its execution has been successful; otherwise, it returns 'false'.

This method returns false in the following cases:

  • If a field is read-only and does not contain any value.
  • If a field is mandatory, it is impossible to clear the Mandatory checkbox with the s_form.setMandatory('some_field', false) method.



Example:

Code Block
languagejs
themeEclipse
titlesetMandatory
linenumberstrue
const scriptType = s_form.getValue('type');
const mandatoryColumn = ['onChange', 'onCellEdit'].includes(scriptType);
s_form.setVisible('column_id', mandatoryColumn);
s_form.setMandatory('column_id', mandatoryColumn);

s_form.setReadOnly(fieldName, readOnly)


This method is used to change a specified field to read-only or editable.


Parameter(s):

NameTypeMandatoryDefault Value
fieldNameStringYN
readOnlyBooleanNtrue


Return:

TypeDescription
Boolean

This method returns 'true' if its execution has been successful; otherwise, it returns 'false'.

This method returns false in the following cases:

  • If a field is read-only, it is impossible to clear the Read Only checkbox with the s_form.setReadOnly('some_field', false) method.
  • If a mandatory field is empty and read-only.

Example:

Code Block
languagejs
themeEclipse
titlesetReadOnly
linenumberstrue
if (s_form.getValue('any_tables')){
  s_form.setMandatory('table_id', false);
  s_form.setReadOnly('table_id', true);
  s_form.setVisible('table_id', false);
}

s_form.setREMLabelOf(fieldName, value)


This message sets the plain text value of the REM attribute label.


Parameter(s):

Name

Type

Mandatory

Default Value

fieldNameStringYN
valueStringYN


Return:

Type

Description

StringThis method returns the set value.


Example:

Code Block
languagejs
themeEclipse
titlesetREMLabelOf
linenumberstrue
if (s_form.getTableName() == 'user') {
  s_form.setREMLabelOf('email', 'Email');
} else {
  s_form.setREMLabelOf('email', 'Personal Email');
}


s_form.setREMMandatory(fieldName, mandatory)


This method allows making the field specified by REM attribute mandatory.


Parameter(s):

Name

Type

Mandatory

Default Value

fieldNameStringYN
mandatoryBooleanY'true'


Return:

Type

Description

Boolean

This method returns 'true' if its execution has been successful; otherwise, it returns 'false'.

This method returns false in the following cases:

  • If a field is read-only and does not contain any value.
  • If a field is mandatory, it is impossible to clear the Mandatory checkbox with the s_form.setMandatory('some_field', false) method.


Example:

Code Block
languagejs
themeEclipse
titlesetREMMandatory
linenumberstrue
const isDeliveryFilled = !!s_form.getValue('delivery');
s_form.setREMMandatory('phone', isDeliveryFilled);


s_form.setREMReadOnly(fieldName, readOnly)


This method allows making the field specified by REM attribute read-only.


Parameter(s):

Name

Type

Mandatory

Default Value

fieldNameStringYN
readOnlyBooleanY'true'


Return:

Type

Description

Boolean

This method returns 'true' if its execution has been successful; otherwise, it returns 'false'.

This method returns false in the following cases:

  • If a mandatory field is empty and set to read-only.
  • If a field is read-only, it is impossible to clear the Read Only checkbox with the s_form.setReadOnly('some_field', false) method.

Example:

Code Block
languagejs
themeEclipse
titlesetREMReadOnly
linenumberstrue
if (s_form.isNewRecord()) {
  s_form.setREMValue('state', 'new');
  s_form.setREMReadOnly('state', true);
}

s_form.setREMValue(fieldName, databaseValue)


This method allows setting the value of the REM attribute label.

Note

Please note that this method is asynchronous; for better performance, use the await keyword as shown in the code example below.

Parameter(s):

Name

Type

Mandatory

Default Value

fieldNameStringYN
databaseValueAnyYN


Return:

Type

Description

VoidThis method does not return a value.

Example:

Code Block
languagejs
themeEclipse
titlesetREMValue
linenumberstrue
await s_form.setREMValue('state', 'new');
s_form.save();


s_form.setREMVisible(fieldName, display)


This method allows defining visibility of the field specified by REM attribute.


Parameter(s):

Name

Type

Mandatory

Default Value

fieldNameStringYN
displayBooleanYN


Return:

Type

Description

VoidThis method does not return value.


Example:

Code Block
languagejs
themeEclipse
titlesetREMVisible
s_form.setREMVisible('additional_info', !s_form.isNewRecord());

s_form.setSectionDisplay(sectionName, display)


Using this method, you can specify the section you want to hide.


Parameter(s):

NameTypeMandatoryDefault Value
sectionNameStringYN
displayBooleanYN


Return:

TypeDescription
VoidThis method does not return value.


Example:

Code Block
languagejs
themeEclipse
titlesetSectionDisplay
linenumberstrue
if (s_form.getValue('state') == '7') { // Completed
  s_form.setSectionDisplay('Closure Information', true);
  s_form.setMandatory('closure_code', true);
  s_form.setMandatory('closure_notes', true);
} else {
  s_form.setMandatory('closure_code', false);
  s_form.setMandatory('closure_notes', false);
  s_form.setSectionDisplay('Closure Information', false);
}

s_form.setValue(fieldName, databaseValue)


This method sets the field value. 


Note

Use s_form.clearValue() method for field clearing instead of setting an empty string value.

Also please note that this method is asynchronous; for better performance, use the await keyword as shown in the code example below.


Parameter(s):

NameTypeMandatoryDefault Value
sectionName
fieldNameStringYN
display
databaseValue
Boolean
StringYN


Return:

TypeDescription
VoidThis method
does not return a value
returns a Promise object.


Example:

Code Block
languagejs
themeEclipse
titlesetSectionDisplaysetValue
linenumberstrue
ifawait (s_form.getValuesetValue('state'), == '7') {; // Completed
  s_form.setSectionDisplay('Closure Information', true);
  s_form.setSectionMandatory('Closure Information', true);
  
await s_form.setMandatorysetValue('closure_codenotes', truearticleBodies.join('\n'));
await  s_form.setMandatorysetValue('closure_notescode', true'1');
} else// {
Solved 1st Level
s_form.setMandatory('closure_code', false);save()
  .then(() => {
    s_form.setMandatory('closure_notes', false);
  i18n.getMessage(`The typical solution is applied`, (e) => {
      s_form.setSectionDisplay('Closure Information', falseaddInfoMessage(e);
  s_form.setSectionMandatory('Closure Information', false});
  });

s_form.

setValue

setVisible(fieldName,

databaseValue

display)


This method sets the field value. 

Warning

IsDisplayValue parameter has been maintained in earlier versions but will be deprecated after version 1.1. Avoid using it in your scripts.

manage displaying of the fields that were added to the form through the Form Layout. With this method, you can hide or show the field. The hidden field state is similar as if this field has been removed from the form view.

Note

Hiding a field for which the mandatory attribute is set on a column level (including the mandatory override described in the Column Overriding article) will lead to validation errors after the form is submitted from the client-side

Note

Use s_form.clearValue() method for field clearing instead of setting an empty string value.

Also please note that this method is asynchronous; for better performing, use the await keyword like shown in the code example below.


Parameter(s):

NameTypeMandatoryDefault Value
fieldNameStringYN
databaseValue
display
String
BooleanYN


Return:

TypeDescription
VoidThis method
returns a Promise object
does not return value.


Example:

Code Block
languagejs
themeEclipse
titlesetValue
linenumberstrue
Eclipse
titlesetVisible
linenumberstrue
if (!s_form.isNewRecord()) {
  s_form.setVisible('subject', true);
await s_form.setValue('state', '7'); // Completed
await s_form.setValue('closure_notes', articleBodies.join('\n'));
await s_form.setValue('closure_code', '1'); // Solved 1st Level
s_form.save()
  .then(() => {
    s_i18n.getMessage(`The typical solution is applied`, (e) => {
      s_form.addInfoMessage(e);
    })
  });setVisible('reason', false);
}

s_form.

setVisible

showFieldMsg(fieldName, message,

display

type)


This method allows to manage displaying of the fields that were added to the form through the Form Layout. With this method, you can hide or show the field. The hidden field state is similar as if this field has been removed from the form view. 

Note

Hiding a field for which the mandatory attribute is set on a column level (including mandatory override described in the Column Overriding article) will lead to validation errors after the form submitting from the client-side.

Parameter(s):

NameTypeMandatoryDefault ValuefieldNameStringYNdisplayBooleanYN

Return:

TypeDescriptionVoidThis method does not return a value.

is used to display a message containing 'info', 'error', or 'warning' value under the specified form field. 


Parameter(s):

NameTypeMandatoryDefault Value
fieldNameStringYN
messageStringYN
typeStringYN


Return:

TypeDescription
VoidThis method does not return value.


Example:

Code Block
languagejs
themeEclipse
titleshowFieldMsg
linenumberstrue
s_form.showFieldMsg('subject', 'Cannot be empty', 'info');


Code Block
languagejs
themeEclipse
titleshowFieldMsg
linenumberstrue
s_form.showFieldMsg('subject', 'Cannot be empty', 'warning');
Example:


Code Block
languagejs
themeEclipse
titlesetVisibleshowFieldMsg
linenumberstrue
if (!s_form.isNewRecord()) {
  showFieldMsg('subject', 'Cannot be empty', 'error');

s_form.

setVisible('subject', true); s_form.setVisible('reason', false); }

showRelatedLists()


This method allows displaying all lists related to the form.


Return:

TypeDescription
VoidThis method does not return value.

s_form.

showFieldMsg(fieldName, message, type

showRelatedList(listTitle)


This method is used to display a message containing 'info', 'error', or 'warning' value under the specified form field. allows displaying the specified lists related to the form.


Parameter(s):

NameTypeMandatoryDefault Value
fieldName

listTitle

StringYN
messageStringYNtypeStringYN

Return:

TypeDescriptionVoidThis method does not return a value.


Return:

TypeDescription
VoidThis method does not return value.


Example:

Code Block
languagejs
themeEclipse
titleshowRelatedList
linenumberstrue
s_form.showRelatedList('UI Action');

s_form.submit()


This method allows submitting the record form.


Return:

TypeDescription
VoidThis method does not return value.


Deprecated methods


This subsection contains methods that are not recommended to use in application design. They are deprecated as the platform evolves; new methods are developed instead of each of them.

s_form.fieldHasChanges(fieldName)


This method is used to check if the specified field has been changed or not.

Warning

This method is deprecated and not recommended to use. Use the s_form.isFieldChanged(fieldName) method instead.


Info

If there is a client script running on the specified form and changing it, the s_form.fieldHasChanges(fieldname) method returns 'true'. That is, it is not necessary that the change is made by a user, the form can be changed by a script.

Parameter(s):

Name

Type

Mandatory

Default Value

fieldNameStringYN

Return:

Type

Description

Boolean

This method returns 'true' if the specified field has been changed; otherwise, it returns 'false'.

Example:

Code Block
languagejs
themeEclipse
titleshowFieldMsg
linenumberstrue
s_form.showFieldMsg('subject', 'Cannot be empty', 'info');
Code Block
languagejs
themeEclipse
titleshowFieldMsg
linenumberstrue
s_form.showFieldMsg('subject', 'Cannot be empty', 'warning');


Code Block
languagejs
themeEclipse
titleshowFieldMsgfieldHasChanges
linenumberstrue
console.log(s_form.showFieldMsgfieldHasChanges('subject', 'Cannot be empty', 'error');

s_form.showRelatedLists()

This method allows displaying all lists related to the form.

Return:TypeDescriptionVoidThis method does not return a value.
state'));

s_form.

showRelatedList

hasChanges(

listTitle

)


This method allows displaying the specified lists related to the form.

Parameter(s):

getting information whether a record form has been changed or not.

Warning

This method is deprecated and not recommended to use. Use the s_form.isChanged() method instead.


NameTypeMandatoryDefault Value

listTitle

StringYN

Return:

Type

Description

Void
Boolean
This method does not return a value
The method returns 'true' if any changes were made on the record form; otherwise, it returns 'false'.

Example:

Code Block
languagejs
themeEclipse
titleshowRelatedListhasChanges
linenumberstrue
if (s_form.showRelatedListhasChanges('UI Action');)) {
  s_form.save().then(() => s_form.
submit()

This method allows to submit the record form.

Return:

TypeDescriptionVoidThis method does not return a value.
goBack());
} else {
  s_form.goBack();
}


Table of Contents
absoluteUrltrue