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.
Name | Type | Mandatory | Default Value |
---|---|---|---|
table | String | Y | N |
sys_id | String | Y | N |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const formObject = new SimpleForm(s_form.table, s_form.sysId); |
Return:
s_form.addErrorMessage(message)
This method displays the error toast message in the bottom right corner.
Parameter(s):
Return:
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();
} |
Return:
Type | Description |
---|---|
Object | This method 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. One of the usage cases of this variable is the field context menu call.
|
currentUiAction |
s_form.addErrorMessage(message)
This method displays the error toast message in the bottom right corner.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
message | String |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
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):
Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return |
value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
s_form.addInfoMessageaddErrorMessage('RecordPlease successfully created', 1000enter a valid email address using the following format: joe@example.com'); |
s_form.
addOptionaddInfoMessage(
fieldNamemessage,
choiceValuedurationMilliseconds)
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 performing, use the await keyword like shown in the code example below. |
Parameter(s):
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):
Name | Type |
---|
Mandatory | Default Value |
---|
message | String | Y | N |
durationMilliseconds |
Number |
N | N |
Return:
Type | Description |
---|---|
Void | This method does not return |
value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| const states = ['-1', '0', '2', '5'];
||||||||
s_form.addInfoMessage('Link copied to clipboard', 2000); |
s_form.
clearOptions('state'); states.forEach(stateValue => { await s_form.addOption('state', stateValue); }addSuccessMessage(message, durationMilliseconds)
This 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):
Name | Type | Mandatory | Default Value |
---|---|---|---|
message | String | Y | N |
durationMilliseconds | Number | N | N |
Return:
s_form.clearMessages()
This method is used to close all kinds of messages (both informational and error) in the form.
Return:
Type |
---|
Description | |
---|---|
Void | This method does not return |
value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
s_i18nform.getMessageaddSuccessMessage('EndRecord datewas time cannot be less than start date timesuccessfully added!', (response) => { 3000); |
s_form.
clearMessagesaddWarningMessage(
); s_form.addErrorMessage(response); return false; // abort form submit });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
s_form.clearOptions(fieldName)
Using this method, you can remove all options from the choice list.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
message | String | Y | N |
durationMilliseconds | Number | N | N |
Return:
Type | Description |
---|---|
Void | This method does not return |
value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
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 'true' 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.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):
Name | Type | Mandatory | Default Value |
---|---|---|---|
fieldName | String | Y | N |
choiceValue | |||
Name | Type | Mandatory | Default Value |
String | Y | N |
Return:
Type | Description |
---|
Promise | This method returns |
a Promise object. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
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.
isFieldChangedclearMessages(
fieldName)
This method 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'. That is, it is not necessary that the change is made by a user, the form can be changed by a script. |
Parameter(s):
Return:
This method returns 'true' if the specified field has been changed; otherwise returns 'false'.
close all kinds of messages (both informational and error) in the form.
Return:
Type | Description |
---|---|
Void | This method does not return value. |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
s_i18n.getMessage('End date time cannot be less than start date time', (response) => {
s_form.clearMessages();
s_form.addErrorMessage(response);
});
return false; // abort form submit |
s_form.clearOptions(fieldName)
Using this method, you can remove all options from the choice list.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
fieldName | String | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
if (s_form.isFieldChanged('state') && s_form.getValue('state') != 'new') {
return false;
} |
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.
Return:
Type
Description
. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const urlchoices = new URL(`${API_BASE_URL}/export/excel`); if (typeof s_form !== "undefined") { url.searchParams.set('form_id', s_form.formId); } window.open(url, "_blank"[ "Phone", "Email", "Self-service" ]; s_form.clearOptions('contact_type'); choices.forEach(async (choiceValue) => { await s_form.addOption('contact_type', choiceValue); }); |
s_form.
getChangesclearValue(fieldName) Anchor s_form.clearValue s_form.clearValue
s_form.clearValue | |
s_form.clearValue |
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. That is, it is not necessary that the change is made by a user, it can be done by a script. |
Return:
This method returns an array of objects with field changes. Object contains field name, previous value and the current value.
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.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
fieldName | String | Y | N |
Return:
Type | Description |
---|---|
Boolean | This method returns the boolean value ('true' or 'false') in the cases described above. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
if (!s_form.getValue('sprint')) {
s_form.clearValue('points');
} |
s_form.isFieldChanged(fieldName)
This method 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(
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
if (s_form.isChanged()) {
const changedFields = s_form.getChanges();
let payload = {};
changedFields.forEach((field) => {
payload[field.fieldName] = field.currentValue;
});
SimpleStorage.setItem('payload', payload);
} |
s_form.getLabelOf(fieldName)
The method returns the label text value.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
fieldName | String | Y | N |
Return:
Type | Description |
---|
Boolean | This method returns |
'true' if the specified field has been changed; otherwise returns 'false'. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
if (s_form.getValueisFieldChanged('namestate').match(/[\/|_*]/g) && s_form.getValue('state') != 'new') { s_form.addErrorMessage(`Field "${s_form.getLabelOf('name')}" contains invalid characters.`);return false; // abort form submit } |
s_form.
getREMDisplayValue(fieldName)formId
This
method gets the displayable REM attribute value.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.
Parameter(s):
Name
Type
Mandatory
Default Value
Return:
Type | Description |
---|---|
String | This method returns attribute displayable valuethe record form view ID (ID of the record in the UI Forms (sys_ui_form) dictionary). |
Example:
Code Block | |||||||||
---|---|---|---|---|---|---|---|---|---|
| |||||||||
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.addErrorMessage(`Service "${s_form.getREMDisplayValue('service')}" is not available`); |
s_form.
getREMLabelOfgetChanges(
fieldName)
This method gets the label text value of the REM attribute.
Parameter(s):
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. |
Name
Type
Mandatory
Default Value
Return:
Type | Description | String
---|---|
Array | This method returns | string containing attribute label value.
an array of objects with field changes. Object contains field name, previous value and the current value. |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
if (!!s_form.getValue('phone').match(/[^\+\s\d\(\)\-]/gisChanged()) { const s_form.addErrorMessage(`Field "${changedFields = s_form.getREMLabelOfgetChanges('phone')}" contains invalid characters.`); } |
s_form.getREMValue(fieldName)
);
let payload = {};
changedFields.forEach((field) => {
payload[field.fieldName] = field.currentValue;
});
SimpleStorage.setItem('payload', payload);
} |
s_form.getLabelOf(fieldName)
The method returns the label text This method gets the REM attribute value.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
fieldName | String | Y | N |
Return:
Type | Description |
---|---|
String | This method returns a string containing the |
attribute label value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
if (!!const FIELD_LABEL = s_form.getREMValuegetLabelOf('modelusername')) { s_form.hideFieldMsg('model'); }; s_form.addErrorMessage(`Field "${FIELD_LABEL}" contains invalid characters.`); |
s_form.
getSectionsgetREMDisplayValue(fieldName)
Using this method, you can get an array of sections.
This method gets the displayable REM attribute value.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
fieldName | String | Y | N |
Return:
Type | Description |
---|
s_form.getSectionNames()
This method allows returning an array, which will contain the names of all sections, visible or not.
Return:
String | This method returns the attribute displayable value. |
Example:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
s_form.addErrorMessage(`Service "${s_form.getREMDisplayValue('service')}" is not available`); |
s_form.
getTableNamegetREMLabelOf(fieldName)
This method returns the table name to which the specified record relates.
The method returns system table name, not the table title. Example:
gets the label text value of the REM attribute.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
fieldName | String | Y | N |
Return:
Type | Description |
---|---|
String | System table nameThis method returns a string containing the attribute label value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
if (['article', 'model'].includes(const FIELD_LABEL = s_form.getTableNamegetREMLabelOf())) { 'phone'); s_form.setSectionMandatory('Review', true); } else { s_form.setSectionMandatory('Review', false); }addErrorMessage(`Field "${FIELD_LABEL}" contains invalid characters.`); |
s_form.
getUniqueValuegetREMValue(fieldName)
This method returns the unique record ID (sys_id).gets the REM attribute value.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
fieldName | String | Y | N |
Return:
Type | Description |
---|---|
String | This method returns the |
database value of the specified field. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const sysId = if (s_form.getUniqueValuegetREMValue(); const currentRecord = new SimpleRecord('model')) { s_form.tablehideFieldMsg('model'); currentRecord.get(sysId, ()=> { if (currentRecord.type == 'unavailable') { return false; // abort form submit } });} |
s_form.getSections()
Using this method, you can get an array of sections.
Return:
Type | Description |
---|---|
Array of HTML elements | The form sections. |
s_form.getSectionNames()
This method allows returning an array, which will contain the names of all sections, visible or not.
Return:
Type | Description |
---|---|
Array of strings | This method returns an array containing section names. |
s_form.
getValuegetTableName(
fieldName)
This method returns the
database value oftable name to which the specified
fieldrecord relates.
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):
Note | ||||
---|---|---|---|---|
The method returns the system table name, not the table title. Example:
|
Return:
Type | Description |
---|---|
String |
System table name. |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const callerIdTABLE_NAME = s_form.getValuegetTableName('caller_id'); console.log(TABLE_NAME); |
s_form.getUniqueValue()
This method returns the unique record ID (sys_id).
Return:
Type | Description |
---|---|
String | This method returns the record ID; otherwise, returns NULL. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const TABLE_NAME = s_form.getTableName(); const RECORD_ID = s_form.getUniqueValue(); const currentRecord = new SimpleRecord(TABLE_NAME); currentRecord.get(RECORD_ID, ()=> { if (currentRecord.sys_id === RECORD_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'currentRecord.sys_created_at); } }); } |
s_form.
getDisplayValuegetValue(fieldName)
This method returns the
displayeddatabase value of the specified field.
Parameter(s):
Name | Type | Mandatory | Default |
---|
Value | |||
---|---|---|---|
fieldName | String | Y | N |
Return:
Type | Description |
---|---|
String |
This method returns the database value of the specified field. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
s_form.addInfoMessage(`Service "${const callerId = s_form.getDisplayValuegetValue('service')}" is no available`); |
s_form.goBack()
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).
Return:
Type
Description
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
if (s_form.isChanged()) { s_form.save().then(() => s_form.goBack()); 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.goBack(addInfoMessage('Users schedule is not defined'); } }); } |
s_form.
isChangedgetDisplayValue(fieldName)
This method allows to get information whether a record form has been changed or not.
Return:
returns the displayed value of the field.
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
fieldName | String | Y | N |
Return:
Type | Description |
---|---|
String | The displayed value of the specified field |
Type
Description
. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
if (s_form.isChangedaddInfoMessage())`Service "${ s_form.savegetDisplayValue().then(() => 'service')}" is not available`); |
s_form.goBack()
); } else { s_form.goBack(); }s_form.hideFieldMsg(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):
Return:
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.
Return:
Type | Description |
---|---|
Void | This method does not return value. |
ExampleExample:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
if (!!s_form.getValueisChanged('state')) { s_form.hideFieldMsg('state'); }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 not
Using this method, you can hide all related lists on the form.
Return:
Type | Description |
---|
Boolean |
The method returns 'true' if any changes were made on the record form; otherwise, it returns 'false'. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
if (s_form.getValueisChanged('type')) == 'internal'){ s_form.save().then(() => s_form.goBack()); } else { s_form.hideRelatedListsgoBack(); } |
s_form.
isMandatoryhideFieldMsg(fieldName)
This method is used to check if the specified field is mandatory or not, as opposed to the s_form.showFieldMsg() method, allows hidding informational or error messages in the specified form field.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
fieldName | String | Y | N |
Return:
Type | Description |
---|
Void | This method |
does not return value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
if (s_form.isMandatory('state') && !s_form.getValue('state')) { s_form.addInfoMessagehideFieldMsg('State cannot be Nonestate'); } |
s_form.
hideRelatedListhideRelatedLists(
relListTitle)
Using this method, you can specify a related list you want to hide.
Parameter(s):
hide all related lists on the form.
Return:
Type | Description |
---|---|
Void | This method does not return |
value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
if (s_form.getValue('type') == 'externalinternal') { s_form.hideRelatedListhideRelatedLists('Customer'); } |
s_form.
isNewRecordisMandatory(fieldName)
If the record was never saved, this method returns 'true'; otherwise, it returns 'false'.This method is used to check if the specified field is mandatory or not.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
fieldName | String | Y | N |
Return:
Type | Description |
---|---|
Boolean |
This method returns 'true' |
if the field is mandatory; otherwise returns 'false'. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
if (!!s_form.isNewRecordisMandatory()'state') { await && !s_form.setValuegetValue('state', 'new');)) { s_form.setReadOnlyaddInfoMessage('state', trueState cannot be None'); } |
s_form.
isReadonlyhideRelatedList(
fieldNamerelListTitle)
This method is used to check if the specified field is editable or read-onlyUsing this method, you can specify a related list you want to hide.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
relListTitle | String | Y | N |
Return:
Type | Description |
---|
Void | This method |
does not return value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
if (!s_form.isReadonlygetValue('statetype')) { await== 'external') { s_form.setValuehideRelatedList('state', 'new'Customer'); } |
s_form.
isSectionVisibleisNewRecord(
sectionName)
This method defines if a specified section is visible or not.
Parameter(s):
If the record was never saved, this method returns 'true'; otherwise, it returns 'false'.
Return:
Type | Description |
---|---|
Boolean |
If the record was never saved then this method returns 'true' |
; |
otherwise, it returns 'false'. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
if (s_form.isSectionVisibleisNewRecord('Instructions')) { await s_form.addInfoMessagesetValue('state'Check out the "Instructions" section, 'new'); s_form.setReadOnly('state', 5000true); } |
s_form.
isValidisReadonly(fieldName)
This method is used to check if the specified form field is valid editable or not.read-only.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
fieldName | String | Y | N |
Return:
Type | Description |
---|---|
Boolean | This method returns 'true' if the form field is validread-only; otherwise , returns 'false'. |
Note |
---|
It makes sense to use this method if a 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. |
Example:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
Code Block | ||||||||
| ||||||||
if (!s_form.isValidisReadonly('state')) { await s_form.addErrorMessagesetValue('This form is invalidstate', 'new'); } |
s_form.
isVisibleisSectionVisible(
fieldNamesectionName)
This method is used to check if the specified field defines if a specified section is visible or not.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
sectionName |
string | Y | N |
Return:
Type | Description |
---|---|
Boolean |
This method returns 'true' if the |
section is visible; otherwise, it returns 'false'. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
if (s_form.isVisibleisSectionVisible('stateInstructions')) { s_form.setSectionDisplayaddInfoMessage('ControlsCheck out the "Instructions" section', true5000); } |
s_form.
removeOptionisValid(
fieldName, choiceValue)
Using this method, you can specify and delete an option from the list.
Parameter(s):
This method is used to check if the specified form is valid or not.
Return:
Type | Description |
---|---|
Boolean | This 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 |
. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const serviceId = if (!s_form.getValueisValid('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 (just updating).)) {
s_form.addErrorMessage('This form is invalid');
} |
s_form.isVisible(fieldName)
This method is used to check if the specified field is visible or not.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
fieldName | String | Y | N |
Return:
Type | Description |
---|
Boolean |
The method returns 'true' if the field is visible; otherwise returns 'false'. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
if (s_form.saveisVisible('state').finally(__resolveServerResponse);) { s_form.setSectionDisplay('Controls', true); } |
s_form.
setLabelOfrefreshUiActions(
fieldName, value)
This method sets the text value of the field label.
Parameter(s):
reloads all UI actions on the form and recalculates the server condition defined for these UI actions without refreshing the page.
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
ifconst stateValue = (s_form.tablegetValue('state'); if (stateValue == 'userin-progress') { s_form.setLabelOf('email', 'Email'refreshUiActions(); } else { s_ |
s_form.
setLabelOf('email', 'Personal Email'); }removeOption(fieldName, choiceValue)
Using this method, you can specify and delete an option from the list.
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):
Name | Type | Mandatory | Default Value |
---|---|---|---|
fieldName | String | Y | N |
choiceValue |
String | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return |
value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const mandatoryColumnserviceId = (scriptType == 'onChange' || scriptType == 'onCellEdit'); 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.
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.
Parameter(s):
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:
Type | Description |
---|---|
String | This method returns the ID of the saved record. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
if (!!const sysId = await s_form.getValue('any_tables')){ save().finally(__resolveServerResponse); await s_formuser.setReadOnly('table_id'setPreference(preferenceApplicationName, truepackApplicationId); await s_formuser.setMandatory('table_id'setPreference(preferenceLocalPackName, falsesysId); await s_formpref.setVisible('table_id', falserefresh(); } |
s_form.
setREMLabelOfsetLabelOf(fieldName, value)
This message method sets the plain text value of the REM attribute field label.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
fieldName | String | Y | N |
value | String | Y | N |
Return:
Type | Description |
---|
Void | This method does not return |
value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
if (s_form.getTableName() == 'user'"employee") { s_form.setLabelOf("email", s"Personal Email"); s_form.setREMLabelOfsetLabelOf('"manager.email'", "Manager's Email'"); } else { s_form.setREMLabelOfsetLabelOf('"email'", 'Personal "Email'"); } |
s_form.
setREMMandatorysetMandatory(fieldName, mandatory)
This method allows is used to make change a field specified by REM attribute mandatoryspecified field to a mandatory field, i.e., it cannot be null.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
fieldName | String | Y | N |
mandatory | Boolean |
N |
true |
Return:
Type | Description |
---|---|
Boolean | This method returns 'true' if its execution has been successful; otherwise, it returns 'false'. |
Example:
This method returns false in the following cases:
|
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const scriptType = | ||||||||
Code Block | ||||||||
| ||||||||
const isDeliveryFilled = !!s_form.getValue('delivery''type'); const mandatoryColumn = ['onChange', 'onCellEdit'].includes(scriptType); s_form.setREMMandatorysetVisible('phonecolumn_id', isDeliveryFilledmandatoryColumn); 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
This method allows to make a field specified by REM attribute read-only.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
fieldName | String | Y | N |
readOnly | Boolean |
N |
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:
|
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
if (!!s_form.isNewRecordgetValue('any_tables')) { s_form.setMandatory('table_id', false); s_form.setREMValuesetReadOnly('statetable_id', 'new'true); s_form.setREMReadOnlysetVisible('statetable_id', truefalse); } |
s_form.
setREMValuesetREMLabelOf(fieldName,
databaseValuevalue)
This method allows to set a message sets the plain text value of the REM attribute label.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
fieldName | String | Y | N |
databaseValuevalue | ObjectString | Y | N |
Return:
Type | Description |
---|
String | This method |
returns the set value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
if (!!s_form.isNewRecordgetTableName() == 'user') { s_form.setREMValuesetREMLabelOf('stateemail', 'newEmail'); } else { s_form.setREMLabelOf('email', 'Personal Email'); } |
s_form.
setREMVisiblesetREMMandatory(fieldName,
displaymandatory)
This method allows to define visibility of making the field specified by REM attribute mandatory.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
fieldName | String | Y | N |
mandatory | Boolean | Y |
'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:
|
Example:
Code Block | |||||||||
---|---|---|---|---|---|---|---|---|---|
| |||||||||
const isDeliveryFilled = !!s_form.setREMVisiblegetValue('additional_info', !delivery'); s_form.isNewRecord())setREMMandatory('phone', isDeliveryFilled); |
s_form.
setSectionDisplaysetREMReadOnly(
sectionNamefieldName,
displayreadOnly)
Using this method, you can specify a section you want to hideThis method allows making the field specified by REM attribute read-only.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
fieldName | String | Y | N |
readOnly | Boolean | Y |
'true' |
Return:
Type | Description |
---|
Boolean | This method |
Example:
returns 'true' if its execution has been successful; otherwise, it returns 'false'. This method returns false in the following cases:
|
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
Code Block | ||||||||
| ||||||||
if (s_form.getValueisNewRecord('state') == '7') { // Completed s_form.setSectionDisplaysetREMValue('Closure Informationstate', true'new'); s_form.setSectionMandatorysetREMReadOnly('Closure Informationstate', 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.setSectionMandatory('Closure Information', false); }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 |
---|---|---|---|
fieldName | String | Y | N |
databaseValue | Any | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
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 |
---|---|---|---|
fieldName | String | Y | N |
display | Boolean | Y | N |
s_form.setValue(fieldName, databaseValue)
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. |
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):
Return:
Example:
Code Block | |||||||||
---|---|---|---|---|---|---|---|---|---|
| |||||||||
await s_form.setValuesetREMVisible('stateadditional_info', '7'); // Completed await s!s_form.setValue('closure_notes', articleBodies.join('\n'isNewRecord()); 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); }) });setSectionDisplay(sectionName, display)
Using this method, you can specify the section you want to hide.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
sectionName | String | Y | N |
display | Boolean | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
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):
Name | Type | Mandatory | Default Value |
---|---|---|---|
fieldName | String | Y | N |
databaseValue | String | Y | N |
Return:
Type | Description |
---|---|
Void | This method returns a Promise object. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
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);
})
}); |
s_form.setVisible(fieldName, display)
This method 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. |
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
fieldName | String | Y | N |
display | Boolean | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
if (!s_form.isNewRecord()) {
s_form.setVisible('subject', true);
s_form.setVisible('reason', false);
} |
s_form.showFieldMsg(fieldName, message, type)
This method is used to display a message containing 'info', 'error', or 'warning' value under the specified form field.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
fieldName | String | Y | N |
message | String | Y | N |
type | String | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
s_form.showFieldMsg('subject', 'Cannot be empty', 'info'); |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
s_form.showFieldMsg('subject', 'Cannot be empty', 'warning'); |
s_form.setVisible(fieldName, display)
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):
Return:
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
if (!s_form.isNewRecord()) { s_form.setVisible('subject', true); showFieldMsg('subject', 'Cannot be empty', 'error'); |
s_form.
setVisible('reason', false); }showRelatedLists()
This method allows displaying all lists related to the form.
Return:
Type | Description |
---|---|
Void | This method does not return value. |
s_form.
showFieldMsg(fieldName, message, typeshowRelatedList(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):
Return:
Name | Type | Mandatory | Default Value |
---|---|---|---|
listTitle | String | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
s_form.showRelatedList('UI Action'); |
s_form.submit()
This method allows submitting the record form.
Return:
Type | Description |
---|---|
Void | This 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 |
---|---|---|---|
fieldName | String | Y | N |
Return:
Type | Description |
---|---|
Boolean | This method returns 'true' if the specified field has been changed; otherwise, it returns 'false'. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
s_form.showFieldMsg('subject', 'Cannot be empty', 'info'); |
language | js |
---|---|
theme | Eclipse |
title | showFieldMsg |
linenumbers | true |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
s_formconsole.showFieldMsg('subject', 'Cannot be empty', 'error'); |
s_form.showRelatedLists()
This method allows displaying all lists related to the form.
Return:log(s_form.fieldHasChanges('state')); |
s_form.
showRelatedListhasChanges(
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. |
listTitle
Return:
Type | Description |
---|
Boolean | The method returns 'true' if any changes were made on the record form; otherwise, it returns 'false'. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
if (s_form.showRelatedListhasChanges('UI Action');)) { s_form.save().then(() => s_form. |
goBack( |
This method allows to submit the record form.
Return:
));
} else {
s_form.goBack();
} |
Table of Contents | ||
---|---|---|
|