GlideForm
g_form aka GlideForm
g_form is used very heavily all over in ServiceNow.\ As such it has a lot of documented and undocumented functions.\ Below I go over all of them;
Property / Method | Desktop | Mobile/SP | Documented |
---|---|---|---|
activateTab | Desktop | No | |
addAttribute | Desktop | No | |
addDecoration | Desktop | Mobile | Both |
addErrorMessage | Desktop | Mobile | Desktop |
addGlideUIElement | Desktop | No | |
addInfoMessage | Desktop | Mobile | Desktop |
addNameMapEntry | Desktop | No | |
addOption | Desktop | Mobile | Desktop |
addSecurityReadOnlyFields | Desktop | No | |
addToCart | Desktop | No | |
addValidator | Desktop | No | |
addWarningMessage | Desktop | No | |
allChangedFieldsFilter | Desktop | No | |
changedFieldsFilter | Desktop | No | |
changeElementParent | Desktop | No | |
changeElementStyle | Desktop | No | |
clearMessages | Desktop | Mobile | Desktop |
clearOptions | Desktop | Mobile | Desktop |
clearValue | Desktop | Mobile | Desktop |
disable | Desktop | No | |
disableAttachments | Desktop | Desktop | |
enable | Desktop | No | |
enableAttachments | Desktop | Desktop | |
enableOption | Desktop | No | |
enableUIPolicyFields | Desktop | No | |
fieldChanged | Desktop | No | |
findV2RelatedListName | Desktop | No | |
flash | Desktop | Desktop | |
getAction | Desktop | No | |
getActionName | Desktop | Mobile | Desktop |
getBooleanValue | Desktop | Mobile | Desktop |
getControl | Desktop | Desktop | |
getControlByForm | Desktop | No | |
getDecimalValue | Desktop | Mobile | Desktop |
getDerivedFields | Desktop | No | |
getDisplayBox | Desktop | No | |
getDisplayValue | Desktop | Mobile | No |
getEditableFields | Desktop | No | |
getElement | Desktop | Desktop | |
getEncodedRecord | Mobile | No | |
getFieldNames | Mobile | No | |
getFormElement | Desktop | Desktop | |
getGlideUIElement | Desktop | No | |
getHelpTextControl | Desktop | Desktop | |
getIntValue | Desktop | Mobile | Desktop |
getLabel | Desktop | Mobile | Mobile |
getLabelOf | Desktop | Desktop | |
getMissingFields | Desktop | No | |
getNiBox | Desktop | No | |
getOption | Desktop | Desktop | |
getOptionControl | Desktop | No | |
orderNow | Desktop | No | |
getField | Mobile | No | |
getParameter | Desktop | No | |
getPrefixHandler | Desktop | No | |
getReference | Desktop | Mobile | Desktop |
getRelatedListNames | Desktop | Mobile | No |
getScope | Desktop | No | |
getSectionNames | Desktop | Mobile | Desktop |
getSections | Desktop | Desktop | |
getSysId | Mobile | No | |
getTableName | Desktop | Mobile | Desktop |
getTabNameForField | Desktop | No | |
getTitle | Desktop | No | |
getUniqueValue | Desktop | Mobile | Desktop |
getValue | Desktop | Mobile | Desktop |
getViewName | Desktop | Mobile | No |
hasAttribute | Desktop | No | |
hasField | Desktop | Mobile | Both |
hasFieldMsgs | Desktop | No | |
hideAllFieldMsgs | Desktop | Mobile | Desktop |
hideErrorBox | Desktop | Mobile | Desktop |
hideFieldMsg | Desktop | Mobile | Desktop |
hideRelatedList | Desktop | Mobile | Desktop |
hideRelatedLists | Desktop | Mobile | Desktop |
isDatabaseView | Desktop | No | |
isDisabled | Desktop | No | |
isDisplayNone | Desktop | No | |
isEditableField | Desktop | No | |
isInteger | Desktop | No | |
isLiveUpdating | Desktop | Desktop | |
isMandatory | Desktop | Mobile | Desktop |
isNewRecord | Desktop | Mobile | Desktop |
isNumeric | Desktop | No | |
isReadOnly | Desktop | Mobile | No |
isSectionVisible | Desktop | Desktop | |
isTemplateCompatible | Desktop | No | |
isUserPersonalizedField | Desktop | No | |
isVisible | Desktop | Mobile | No |
mandatoryCheck | Desktop | No | |
onSubmit | Desktop | No | |
registerHandler | Desktop | No | |
registerPrefixHandler | Desktop | No | |
removeAllDecorations | Desktop | No | |
removeContextItem | Desktop | No | |
removeCurrentPrefix | Desktop | No | |
refreshSlushbucket | Desktop | Desktop | |
removeDecoration | Desktop | Mobile | Both |
removeItem | Desktop | No | |
removeOption | Desktop | Mobile | Desktop |
resetPersonalizeHiddenFields | Desktop | No | |
resolveLabelNameMap | Desktop | No | |
resolveNameMap | Desktop | No | |
resolvePrettyNameMap | Desktop | No | |
save | Desktop | Mobile | Desktop |
serialize | Desktop | Mobile | No |
serializeChanged | Desktop | No | |
serializeChangedAll | Desktop | No | |
serializeTargetFields | Desktop | No | |
setAction | Desktop | No | |
setDisabled | Desktop | Mobile | No |
setDisabledControl | Desktop | No | |
setDisplay | Desktop | No | |
setFieldPlaceholder | Mobile | No | |
setLabel | Mobile | Mobile | |
setLabelOf | Desktop | Mobile | Desktop |
setLiveUpdating | Desktop | No | |
setMandatory | Desktop | Mobile | Desktop |
setMandatoryOnlyIfModified | Desktop | No | |
setReadOnly | Desktop | Mobile | Desktop |
setReadonly | Desktop | Mobile | No |
setRequiredChecked | Desktop | No | |
setScope | Desktop | No | |
setSectionDisplay | Desktop | Mobile | No |
setSensitiveDisplayValue | Desktop | No | |
setStreamJournalFieldsDisplay | Desktop | No | |
setTemplateValue | Desktop | No | |
setUserDisplay | Desktop | No | |
setValidation | Desktop | No | |
setValue | Desktop | Mobile | Desktop |
setVariablesReadOnly | Desktop | No | |
setVisible | Desktop | Mobile | Desktop |
showErrorBox | Desktop | Mobile | Desktop |
showFieldMsg | Desktop | Mobile | Desktop |
showRelatedList | Desktop | Mobile | Desktop |
showRelatedLists | Desktop | Mobile | Desktop |
submit | Desktop | Mobile | Desktop |
validate | Desktop | No |
These methods I've found in the script that dictates it's available on the portal/mobile clients.\ At the time of this writing that is service-now.com/scripts/sn/common/clientScript/glideFormFactory.js
Mobile addDecoration
Adds an icon on a field's label. This method is available starting with the Fuji release. Icons available here Adding the same item twice is prevented; however, you can add the same icon with a different title.
Mobile getLabel
Mobile hasField
Mobile removeDecoration
Mobile setLabel
Mobile Undocumented
Mobile addErrorMessage
Displays an error message at the top of the form
Mobile addInfoMessage
Displays an informational message at the top of the form
Mobile addOption
Adds a choice to a choice list field If the index is not specified, the choice is added to the end of the list.
Optional: Use the index field to specify a particular place in the list
Mobile clearMessages
Removes all informational and error messages from the top of the form.
Removes informational and error messages added with
g_form.addInfoMessage()
and g_form.addErrorMessage()
.
Mobile clearOptions
Removes all options from a choice list
Mobile clearValue
Removes any value(s) from the specified field
Mobile getActionName
Returns the most recent action name or, for a client script, the sys_id of the UI Action clicked Note: not available to Wizard Client Scripts
Mobile getBooleanValue
Returns false if the field's value is false or undefined, otherwise true is returned. Useful with checkbox fields Returns true when the checkbox is checked
Mobile getDecimalValue
Mobile getDisplayValue
Mobile getEncodedRecord
Mobile getField
This is undocumented and I havent been able to find or test this yet, however it comes from this source; https://community.servicenow.com/community?id=community_question&sys_id=2a151ed0db262b4011762183ca961957$answer_fe97e3bfdb4ef304f21f5583ca961964#answer_fe97e3bfdb4ef304f21f5583ca961964
Mobile getFieldNames
Mobile getIntValue
Mobile getLabelOf
Mobile getReference
Mobile getRelatedListNames
Mobile getSectionNames
Mobile getSysId
Mobile getTableName
Mobile getUniqueValue
Mobile getValue
Mobile getViewName
Mobile hideAllFieldMsgs
Mobile hideErrorBox
Mobile hideFieldMsg
Mobile hideRelatedList
Mobile hideRelatedLists
Mobile isMandatory
Mobile isNewRecord
Mobile isReadOnly
Mobile isVisible
Mobile removeOption
Mobile save
Mobile serialize
Mobile setDisabled
Mobile setDisplay
Mobile setFieldPlaceholder
Mobile setLabelOf
Mobile setMandatory
Mobile setReadOnly
Mobile setReadonly
Mobile setSectionDisplay
Mobile setValue
Mobile setVisible
Mobile showErrorBox
The showErrorBox()
and hideErrorBox()
are still available but simply
call the new methods with type of error. You should use the new methods.
Mobile showFieldMsg
Mobile showRelatedList
Mobile showRelatedLists
Mobile submit
Desktop
Desktop Documented
Desktop addDecoration
Adds an icon on a field's label. This method is available starting with the Fuji release. Icons available here Adding the same item twice is prevented; however, you can add the same icon with a different title.
Note: This method is not supported by Service Catalog.
Desktop addErrorMessage
Displays the error message at the top of the form.
Desktop addInfoMessage
Displays an informational message at the top of the form
Desktop addOption
Adds a choice to a choice list field If the index is not specified, the choice is added to the end of the list.
Optional: Use the index field to specify a particular place in the list
Desktop clearMessages
Removes all informational and error messages from the top of the form.
Removes informational and error messages added with
g_form.addInfoMessage()
and g_form.addErrorMessage()
.
Desktop clearOptions
Removes all options from a choice list
Desktop clearValue
Removes any value(s) from the specified field
Desktop disableAttachments
Prevents new file attachments from being added Hides the paperclip icon. See also: enableAttachments()
Desktop enableAttachments
Allows new file attachments to be added Shows the paperclip icon. See also: disableAttachments()
Desktop flash
Flashes the specified color the specified number of times in the field. Used to draw attention to a particular field.
This method is not supported by Service Catalog.
This method is not available on the mobile platform. If this method is run on a mobile platform, no action occurs.
The third parameter operates with the following inputs;
Input | Action |
---|---|
2 | 1 second flash |
0 | 2 second flash |
-2 | 3 second flash |
-4 | 4 second flash |
Desktop getActionName
Returns the most recent action name or, for a client script, the sys_id of the UI Action clicked Note: not available to Wizard Client Scripts
Desktop getBooleanValue
Returns false if the field's value is false or undefined, otherwise true is returned. Useful with checkbox fields Returns true when the checkbox is checked
Desktop getControl
Returns the HTML element for the specified field Compound fields may contain several HTML elements. Generally not necessary as there are built-in methods that use the fields on the form
Desktop getDecimalValue
Returns the decimal value of the specified field
Desktop getElement
Returns the HTML element for the field specified via the ID Compound fields may contain several HTML elements. Generally not necessary as there are built-in methods that use the fields on the form
Desktop getFormElement
Returns the HTML element for the form.
This method is not available in mobile scripts or Service Portal scripts.
Desktop getHelpTextControl
Returns the HTML element of the help text for the specified field.
This method is applicable to service catalog variables only.
Desktop getIntValue
Returns the value of the specified field as an integer An empty value returns 0
Desktop getLabelOf
Gets the plain text value of the field label. This method is available starting with the Fuji release
Desktop getOption
Returns the <option>
element for a select box named fieldName and
where choiceValue matches the option value Returns null if the field is
not found or the option is not found
Desktop getReference
Returns the GlideRecord for a specified field getReference() accepts a second parameter, a callback function Warning: This requires a call to the server so using this function will require additional time and may introduce latency to your page
Desktop getSectionNames
Returns all section names, whether visible or not, in an array This method is available starting with the Fuji release
Desktop getSections
Returns the elements for the form's sections in an array
Desktop getTableName
Returns the name of the table this record belongs to
Desktop getUniqueValue
Returns the sys_id of the record displayed in the form
Desktop getValue
Returns the value of the specified field
Desktop hideAllFieldMsgs
Hides all field messages. <type>
paramter is optional
Desktop hideErrorBox
Hides the error message placed by showErrorBox()
Whenever possible, use hideFieldMsg() rather than this method whenever possible.
Desktop hideFieldMsg
Hides the message placed by showFieldMsg();
Desktop hideRelatedList
Hides the specified related list on the form
Desktop hideRelatedLists
Hides all related lists on the form
Desktop isLiveUpdating
Desktop isMandatory
Returns true while a live update is being done on the record the form is showing.
This can be used in an onChange() client script to determine if a change to the record is because of a live update from another session. The client script can then decide what action to take, or not to take. This applies to systems using UI16 with live forms enabled.
Desktop isNewRecord
Returns true if the record has never been saved Returns false if the record has been saved
Desktop isSectionVisible
Returns true if the section is visible Returns false if the section is not visible or does not exist. This method is available starting with the Fuji release
Desktop refreshSlushbucket
You can update a list collector variable.
Desktop removeDecoration
Removes the icon from the specified field that matches the icon and title. Note: This method is not supported by Service Catalog.
Desktop removeOption
Removes a specific option from a choice list
Desktop save
Saves the record without navigating away from the record (update and stay)
Desktop setDisabled
Grays out field and makes it unavailable
Desktop setDisplay
Displays the field if true. Hides the field if false. This method cannot hide mandatory fields with no value. If the field is hidden, the space is used to display other items
Desktop setLabelOf
Sets the plain text value of the field label. This method is available starting with the Fuji release
Desktop setMandatory
Makes the field required if true. Makes the field optional if false. Best Practice: Use UI Policy rather than this method whenever possible
Desktop setReadOnly
Makes the field read-only if true Makes the field editable if false. Note: Both setReadOnly and setReadonly are functional. Best Practice: Use UI Policy rather than this method whenever possible
Desktop setSectionDisplay
Shows or hides a section Works in both tab and flat modes. This method is available starting with the Fuji release
Desktop setValue
Sets the value and the display value of a field Will display value if there is no displayValue
Desktop setVisible
Displays the field if true. Hides the field if false. If the field is hidden, the space is left blank. This method cannot hide mandatory fields with no value
Desktop showErrorBox
Displays an error message under the specified form field (either a control object or the name of the field). If the control or field is currently scrolled off the screen, it will be scrolled to. A global property (glide.ui.scroll_to_message_field) is available that controls automatic message scrolling when the form field is offscreen (scrolls the form to the control or field). The showFieldMsg() method is a similar method that requires a 'type' parameter
Desktop showFieldMsg
Displays either an informational or error message under the specified form field (either a control object or the name of the field). Type may be either 'info' or 'error.' If the control or field is currently scrolled off the screen, it will be scrolled to. A global property (glide.ui.scroll_to_message_field) is available that controls automatic message scrolling when the form field is offscreen (scrolls the form to the control or field)
Desktop showRelatedList
Displays the specified related list on the form
Desktop showRelatedLists
Displays all related lists on the form
Desktop submit
Saves the record User will be taken away from the form, returning them to where they were previously
Desktop Undocumented
Desktop activateTab
Desktop addAttribute
Desktop addGlideUIElement
Desktop addNameMapEntry
Desktop addSecurityReadOnlyFields
Desktop addToCart
This seems to be referenced by an error when using g_form.submit()
from a catalog in a catalog client script.
Desktop addValidator
Desktop
Desktop allChangedFieldsFilter
Desktop changedFieldsFilter
Desktop changeElementParent
Desktop changeElementStyle
Desktop disable
Desktop enable
Desktop enableOption
Desktop enableUIPolicyFields
Desktop fieldChanged
Desktop findV2RelatedListName
Desktop getAction
Desktop getControlByForm
Desktop getDerivedFields
Desktop getDisplayBox
Desktop getDisplayValue
Desktop getEditableFields
If the form is read only, just return.
Desktop getGlideUIElement
Desktop getLabel
Desktop getMissingFields
Desktop getNiBox
Desktop getOptionControl
We can access the option control to get the name of the operation.
Desktop orderNow
This seems to be referenced by an error when using g_form.submit()
from a catalog in a catalog client script.
Desktop getParameter
Desktop getPrefixHandler
Desktop getRelatedListNames
Desktop getScope
Desktop getTabNameForField
Desktop getTitle
Desktop getViewName
Desktop hasAttribute
Desktop hasField
Desktop hasFieldMsgs
Desktop isDatabaseView
Desktop isDisabled
If the user can't set the field, we shouldn't touch it.
Desktop isDisplayNone
Desktop isEditableField
Desktop isInteger
Desktop isNumeric
Desktop isReadOnly
Desktop isTemplateCompatible
Desktop isUserPersonalizedField
Desktop isVisible
Desktop mandatoryCheck
If we have unfilled mandatory fields then do not progress.