Client-side script use cases
-
- UpdatedMar 13, 2025
- 8 minutes to read
- Yokohama
- API implementation
Use cases for client-side scripts include displaying field messages, changing form colors, adding fields, and creating UI routing actions.
Add a field to the service catalog checkout
This is an example of adding a Company field to the checkout below the Requested for field using non-cart layout macros, that is, glide.sc.use_cart_layouts is false.
Before you begin
Role required: Admin
About this task

This field passes a provided value to the Company field of the Service Catalog Request.
This example makes the following assumptions:
- The instance using two-step checkout. If two-step checkout is not enabled, enable it before beginning. For more information, see Service Catalog checkout models.
- This example populates the Company field on the Service Catalog Request form. If the field does not appear on the form, configure the form before beginning. For instructions, see Personalize a form.
Procedure
Result
Add autofill functionality
Add autofill functionality is also called incident template, auto assignments, quick calls, call script, or auto populate.
- Create a lookup table.
- Populate the key field, Subcategory.
- Populate the auto-filled field, Short Description.
You can populate many fields or pull in call script questions into the Comments field so call center personnel gather good information to pass on to a technician.
- Setting a field to password reset
-
Lookup table has a record with the following key and auto-fill settings:
- Subcategory = Password
- Short Description = Password Reset
Change form color on state change
Changes color of a form field of the form on state change. The script can easily be changed to adjust any property of any object on the page accessible via the HTML DOM.
Name: Change Form Color on State Change
Type: Client script
Description: Changes color of a form field of the form on state change. The script can easily be changed to adjust any property of any object on the page accessible via the HTML DOM.
Create a UI routing action
This solution enables you to create a record with the service desk without knowing whether it is an incident or request item; the service desk can then route the record to the appropriate table.
Before you begin
Role required: Admin
Procedure
Display field messages
Rather than use JavaScript alert(), for a cleaner look, you can display an error on the form itself. The methods showFieldMsg() and hideFieldMsg() can be used to display a message just below the field itself.
showFieldMsg and hideFieldMsg are methods that can be used with the g_form object.
These methods are used to change the form view of records (Incident, Problem, and Change forms). These methods may also be available in other client scripts, but must be tested to determine whether they work as expected.
When a field message is displayed on a form on load, the form scrolls to ensure that the field message is visible. Ensuring that users do not miss a field message because it was off the screen.
The global property glide.ui.scroll_to_message_field controls automatic message scrolling when the form field is offscreen (scrolls the form to the control or field).
Method Detail | Parameters | Example |
---|---|---|
showFieldMsg(input, message, type, [scrollform]) |
|
Error Message Informational Message |
hideFieldMsg(input) |
|
Removing a Message |
Legacy support
The showErrorBox() and hideErrorBox() methods are not recommended.
Using client and server code in a UI action
You can use a script to validate input upon a UI Action click on the client side before updating the record on the server side. The user will not have to click the button twice to validate the required fields and update the record.
The script calls the client function for client-side validation, and the UI action completes the task if it passes. The code that runs without onclick
statement ensures that the server-side function does not run
until the client function is no longer running. If successful, the server-side function runs and updates the record.
gsftSubmit(String control, Object form, String action_name)
Submits a form as if the user had clicked a UI Action after checking for required fields and executing onSubmit() client scripts. Enables calling client-side code and server-side code and in a single UI action.
Name | Type | Description |
---|---|---|
control | String | Name of a form button on which you want to simulate a user click. Use null otherwise. |
form | Object | Optional. The form element that contains the submitted input. You can retrieve this value by calling the g_form.getFormElement() method. |
action_name | String | Action name. This value is provided in the record listed in the UI Actions [sys_ui_action] table. For example, |
On this page
Related Content
- GlideForm - getFormElement()
Returns the HTML element for the form.
- Scoped GlideSystem - eventQueue(String name, Object instance, String parm1, String parm2, String queue)
Queues an event for the event manager.
- GlideUser - Client
The GlideUser API provides methods that access information about the current user and current user roles. Using this API avoids the need to use the slower GlideRecord queries to get user information.
- Defining UI actions