Client-side Scripting Flashcards
The following are examples of when to use what?
- Place the cursor in a form field on form load
- Generate alerts, confirmations, and messages
- Populate a form field in response to another fields value
- Highlight a form field
- Validate form data
- Modify choice list options
- Hide/Show fields or sections
Client side scripts (execute within a user’s browser and are used to manage forms and fields)
When should an onLoad client script be used?
Use onLoad Client Scripts to manipulate a form’s appearance or content. For example, setting field or form-level messages based on the presence of a value. Use onLoad Client Scripts sparingly as they impact form load times.
When should an onChange client script be used?
onChange Client Scripts execute script logic when a particular field’s value changes. Use onChange Client Scripts to respond to field values of interest and to modify another field’s value or attributes. For example, if the State field’s value changes to Closed Complete, generate an alert and make the Description field mandatory.
When should an onSubmit client script be used?
onSubmit Client Scripts execute script logic when a form is submitted. Use onSubmit Client Scripts to validate field values. For example, if a user submits a Priority 1 record, the script can generate a confirmation dialog notifying the user that the executive staff are copied on all Priority 1 requests.
What is the “onCellEdit” type of client script?
This is a fourth type of script that is used for lists rather than forms
What is the “Inherited” checkbox used for?
This determines if a script will apply to child tables. For example a client script on task table would also be inerited by the change, incident, problem table, etc.
Which type of client script(s) do/does not have any arguments passed in by default?
onLoad and onSubmit do not have any arguments passed in
Which type of client script(s) has/have arguments passed into them and what are those arguments?
onChange client scripts have the following arguments passed in:
- control
- field the Client Script is configured for
- oldValue
- value of the field when the form loaded and prior to the change
- newValue
- value of the field after the change
- isLoading
- boolean value indicating whether the change is occurring as part of a form load. Value is true if change is due to a form load. When forms load, all the field values on the form change as the record is loaded into the form
- isTemplate
- boolean value indicating whether the change occurred due to population of the field by a template. Value is true if change is due to population from a template
how does “oldValue” work on an onChange client script?
The oldValue is set from the database when the form loads and will not change until the next time the form loads no matter how many times it is changed in between or what client scripts change the value of the field in question
What is GlideForm?
The GlideForm API provides methods to customize forms.
GlideForm.js is the JavaScript class containing the methods. The global object g_form is used to access GlideForm methods. GlideForm methods are only used on the client. These methods are used to make custom changes to the form view of records.
Where can GlideForm methods be accessed and what is the appropriate syntax to do so?
Available only on the client side.
Accessed using the method:
g_form.
example:
alert(g_form.getValue(‘short_description’));
What is the GlideUser API?
What methods are available to the GlideUser API
The GlideUser API provides methods and non-method properties for finding information about the currently logged in user and their roles. The typical use cases are personalizing feedback to the user and inspecting user roles. Note that client-side validation in any web application is easily bypassed.
- Retrieve the user’s:
- First name
- Full name
- Last name
- User ID
- User name
- Determine if a user has a particular role assigned
Where is g_user API available?
Client Scripts only!
what do the following scripts do:
g_user.hasRole(‘client_script_admin’);
g_user.hasRoleExactly(‘client_script_admin’);
The first script will return a value of true if the current user has the role listed or any role that contains that role (such as admin)
The second script will return a value of true if the current user has the exact role mentioned in the script (inherited roles still return false)
What are UI policies, how do they differ from client scripts?
they are client-side logic that governs form and form field behavior.
Unlike Client Scripts, UI policies do not always require scripting