‣ Hide/Display Variable
g_form.setDisplay(<field_name>, true/false);
‣ Disable a field
g_form.setDisable(<field_name>, true/false);
‣ Make Field Read-only
g_form.setReadOnly(<field_name>, true/false);
‣ Clear Value from Field
g_form.clearValue(<field_name>);
‣ Change Label of Field
g_form.setLabelOf(<field_name>, New Label Here) ‣ Make Field Mandatory
g_form.setMandatory(<field_name>, true/false);
‣ Set Value of Field
g_form.setValue(<field_name>, New Value Here) ‣ Get Value of Field
g_form.getValue(<field_name>)
‣ Add Info Message
gs.addInfoMessage(<field_name>, Message Here) ‣ Add Error Message
gs.addErrorMessage(<field_name>, Message Here) ‣ Add Form Message
gs.addFormMessage((Message Here, type)Example: gs.addFormMessage('Be sure to save when you're done filling out the form', 'info');
‣ Clear All Form Messages
g_form.clearAllFormMessages(); ‣ Show Error and Scroll to Field
g_form.showErrorBox(<field_name>, true/false);
‣ Show Field Mesage
g_form.showFieldMsg(<field_name>, message, type);
Example: g_form.showFieldMsg(start_date, 'Date must be in the past', 'info');
‣ Hide Field Mesage
g_form.hideFieldMsg(<field_name>);
‣ Add Options to Choice field
g_form.addOption(<field_name>, value, label, index);
‣ Remove Options from Choice Field
g_form.removeOption(<field_name>, Options To Remove Here) ‣ Clear all Options from Choice Field
g_form.clearOptions(<field_name>);
‣ Get Reference for a Field
g_form.getReference(<field_name>, callbackFunction);
‣ Flash a Field
g_form.flash(<table_name>.<field_name>, color, count);
Example: g_form.flash(incident.number, #FFFFFF, 1);
‣ Get Integer Value of Field
g_form.getIntValue(<field_name>);
‣ Get Decimal Value of Field
g_form.getDecimalValue(<field_name>);
Related List Methods:
‣ Show Related List
g_form.showRelatedList(<related_list_table_name>);
‣ Hide Related List
g_form.hideRelatedList(<related_list_table_name>);
‣ Show All Related Lists
g_form.showRelatedLists(); ‣ Hide All Related Lists
g_form.hideRelatedLists();
Section-based Methods:
‣ Show/Hide a Section
g_form.setSectionDisplay(<section_name>, true/false);
‣ Get All Sections*
g_form.getSectionNames(); ‣ Get All Sections**
g_form.getSections(); ‣ Check whether Section is Visible
g_form.isSectionVisible(<section_name>);
* Returns all the sections including the invisible ones,
** Not available on Mobile Platform
<section_name> - the Section Name in ServiceNow is found by taking the section name, replacing the 1st space with
an underscore, and then removing rest of the spaces. For example :if a section on a Form is called
"Section Specific API" then section name is "section_specificapi"
Decoration Methods:
‣ Add decorations (does not apply to Catalog Client Scripts)
g_form.addDecoration(<field_name>, value, icon, title);
Example: g_form.addDecoration('Date', icon-calendar, 'Choose Date');
Supported Icons: icon-user, icon-user-group, icon-lightbulb, icon-home,
icon-mobile, icon-comment, icon-mail, icon-locked, icon-database, icon-book,
icon-drawer, icon-folder, icon-catalog, icon-tab, icon-cards, icon-tree-right,
icon-tree, icon-book-open, icon-edit, icon-trash, icon-image, icon-search, icon-power,
icon-cog, icon-star, icon-star-empty, icon-new-ticket, icon-dashboard, icon-cart-full,
icon-label, icon-filter, icon-calendar, icon-script, icon-add, icon-delete, icon-help,
icon-info, icon-check-circle, icon-alert, icon-console, icon-list, icon-form,
icon-sort-ascending, icon-paperclip, icon-view, and icon-livefeed
‣ Remove decorations (does not apply to Catalog Client Scripts)
g_form.removeDecoration(<field_name>, value, icon, title);
Example: g_form.removeDecoration('Date', icon-calendar, 'Choose Date');
‣ Check if LiveUpdate is Running on the Form*
g_form.isLiveUpdating()(<field_name>);
* Live update can detect any change of the data on the form from another session.
HTML-based Methods:
‣ Control a Field
g_form.getControl(<field_name>);
‣ Get HTML Element from Parameter*
g_form.getElement(<parameter>);
‣ Get HTML Element of an Option**
g_form.getOption(<field_name>, value);
‣ Get HTML Element of Form
g_form.getFormElement();
‣ Get HTML Element of Help Text
g_form.getHelpTextControl(<field_name>);
* Not available in the Mobile and Service Portal
** The method will not work on read-only fields, and if the field is not present on the form it will result in null.
Action Methods:
‣ Submit a Form
g_form.submit(action_name);
‣ Save a Form
g_form.save();
Looking for something else? Check out our Other Cheat Sheets below!
Interested in making more money as a ServiceNow developer? We're here to help. We're launching a set of courses, 1:1 mentorship and a community to help you increase your earnings.