Académique Documents
Professionnel Documents
Culture Documents
GlideForm (g form):
Overview:
GlideForm.js is the Javascript class used to customize forms.
g_form is a global object in the GlideForm class.
GlideForm.js and g_form are only used on the client (for instance, the
web browser).
g_form accesses:
Display Settings
Field Information
Change Field
Change Choice List
Form Information
Form Action
Where To Use:
These methods are used to make custom changes to the form view of records. All
validation of examples was done using Client Scripts. Some of these methods can also be
used in other client scripts (such as Catalog Client Scripts or Wizard Client Scripts), but
must first be tested to determine whether they will work as expected.
Display Settings
Flash
Syntax:
void flash(widgetName, color, count)
Flashes the specified color the specified number of times in the field.
Used to draw attention to a particular field.
Parameters:
widgetName - specifies the field with <table name>.<fieldname>.
color - RGB color or acceptable CSS color like "blue" or "tomato."
count - integer that determines how long the label will flash.
use 2 for a 1-second flash
use 0 for a 2-second flash
use -2 for a 3-second flash
use -4 for a 4-second flash
Returns:
void
Example:
g_form.flash("incident.number", "#FFFACD", 0);
hideFieldMsg
void hideFieldMsg(input, [clearAll])
Hides the message placed by showFieldMsg().
Parameters:
input - specifies the name of the field.
clearAll (optional) - boolean parameter indicating whether to clear all messages. If true,
all
messages for the field will be cleared; if false or empty, only the last message will be
removed.
Returns:
void
Example:
g_form.hideFieldMsg('impact', true);
setDisplay
void setDisplay(fieldName, boolean)
Displays the field if true. Hides the field if false. This method cannot hide mandatory
fields.
If the field is hidden, the space is used to display other items.
Best Practice: Use UI Policy rather than this method whenever possible.
Parameters:
fieldName - specifies the field to be displayed or hidden.
boolean - true to display the field, false to hide the field.
Returns:
void
Example:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
//If the page isn't loading
if (!isLoading) {
//If the new value isn't blank
if (newValue != '') {
g_form.setDisplay('priority', false);
}
else
g_form.setDisplay('priority', true);
}
}
"Priority" Field Displayed
getElement
HTMLElement getElement(id)
Returns the HTML element for the field specified by 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.
Parameters:
id - specifies the field ID.
Returns:
HTMLElement - the specified HTML element(s).
getReference
GlideRecord getReference(fieldName, callback)
Returns the GlideRecord for a specified field. Note that this method does not return userdefined fields.
getReference() accepts a second parameter, a callback function.
Callback function support for ServiceCatalogForm.getReference is available.
Warning: This requires a call to the server so using this function will require additional
time and may
introduce latency to your page. Use with caution. See Avoid Server Lookups.
Parameters:
fieldName - specifies the field.
Returns:
GlideRecord - the GlideRecord object for the specified field. See GlideRecord for more
information.
If a callback function is present, this routine runs asynchronously, and browser (and
script) processing will
continue normally until the server returns the reference value, at which time the callback
function will be
invoked.
If a callback function is not present, this routine runs synchronously and processing will
halt (causing the
browser to appear to hang) while waiting on a server response. It is strongly
recommended that a callback
function be used on any supported versions.
Example: with a callback (recommended)
function onChange(control, oldValue, newValue, isLoading) {