Scripting class Flashcards

1
Q

Client side scripts are run on the browser and handle what kind of functions?

A

They can auto populate a field based on the value of another field

Show or hide form sections

They have access to data on forms and in lists

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Server side scripts are generally used for what purpose

A

These typicall modify a database record or generate an event

These have access to the actual database unlike client side scripts

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

MID server scripts are generally used for what purpose

A

to integrate to a 3rd party application

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The syntax editor uses color coding including Green, Purple, and Blue. What do each of these colors mean?

A

Green are comments

Purple are JavaScript commands

Blue are strings and reserved words

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the keyboard shortcut to display a list of valid elements at the cursor’s current position?

A

control + spacebar at the beginning of a line

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the keyboard shortcut to list methods for a class?

A

period after a valid class name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the keyboard shortcut to list expected parameters

A

Open parenthesis after a valid class, function, or method name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Do properties that have been locally declared appear in the context-sensitive help?

A

Yes they do

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Is the following class used on the client or server side:

GlideAjax

A

Client Side

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Is the following class used on the client or server side:

Glide Aggregate

A

Server - Side

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Is the following class used on the client or server side:

GlideForm

A

Client - Side

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Is the following class used on the client or server side:

GlideDateTime

A

Server Side

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Is the following class used on the client or server side:

GlideList

A

Client-side

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Is the following class used on the client or server side:

GlideElement

A

Server - side

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Is the following class used on the client or server side:

GlideRecord

A

Client - Side

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Is the following class used on the client or server side:

GlideRecord

A

Server - Side

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Is the following class used on the client or server side:

GlideUser

A

Client-Side

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Is the following class used on the client or server side:

GlideSystem

A

Server-Side

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Is the following class used on the client or server side:

spModal

A

Client-Side

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Is the following class used on the client or server side:

JSON

A

Server-Side

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Is the following class used on the client or server side:

Workflow

A

Server-side

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

A client script manages the behavior of forms, fields, and lists in real time including the following:

A
  • Make fields mandatory
  • set one field in response to another
  • modify choice of list options
  • hide/show form sections
  • display an alert
  • hide fields
  • prohibit list editing

These execute client side

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

When there are multiple client scripts executing what order do they go in?

A

This is only an issue if they are on the same table and they will execute based on their order number from lowest to highest.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

How does an onLoad() client script work

A

This script runs when a form loads and before control is given to the user. It is typically used to manipulate a form’s appearance or content on screen.

Users are not able to modify the form while an onLoad script executes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
How does an onSubmit() script work
This runs when a form is saved, updated, or submitted and is typically used for field validation
26
What does the following code do: ## Footnote function onSubmit() { if (!myCondition) { return false; else { //perform some logic here } }
This runs on form submission and will cancel the submission if "myCondition" isn't met. Return false is what cancels the process.
27
How does an onChange() script work
This script runs when a particular field value changes. It is typically used to respond to field values of interest, modify one field value in response to another. An onchange script can only watch one field at a time.
28
What are the five parameters automatically passed to an onChange client script and what do they do?
* control - name of the object(field\_name) whose value just changed. The object is identified in the Field name field on the Client Script form. * oldValue - value of the control field when the form loaded and prior to the change. The old value is always what it was when the form loaded no matter how many times it is changed * newValue - value of the control field after the change * isLoading - boolean value indicating whether the change is occuring as part of a form load. Value is true if chane is due to a form load. A form load means all of a form's field values changed * 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.
29
How does the onCellEdit() script work?
Script runs when a particular field value on a list changes. Applies to all records selected. This can be used to ensure data being controlled via scripts on a form has similar constraints on a list view. Does not apply to widgets on homepages or dashboards.
30
what parameters are automatically passed to an onCellEdit() Client Script
* sysIDs - sys\_id of the edited item(s) * table - the table name of the edited item(s) * oldValues - the old value of the edited cell(s) * newValue - the new value of the edited cell(s). Is the same for all edited items. * callback - a callback will continue the execution of other related cell edit scripts
31
what does the following function do:
This script defaults to save and close but if the new value of state is either resolved or closed the value of save and close is changed to false. When this happens the callback function that calls the variable gets the new value of false meaning it won't run and it also alerts the user that they are unable to make that change.
32
What are the three most popular client-side APIs
g\_form - object whose properties are methods used to manage a form and its fields in the record g\_user - object whose properties contain session information about the currently logged in user and their role(s) g\_scratchpad - object passed to a client script from a server-side script known as a display business rule. The object's properties and values are determined by the server side script.
33
What can you use to access GlideForm methods
g\_form global object for example: g\_form.setValue('impact',1); g\_form.showFieldMsg('state','Change is waiting approval','info');
34
What g\_form methods are used to: Draw attention to an area on the form
flash() - flashes a field's label to draw attention to it showFieldMsg() - displays a message under a form field
35
What g\_form methods are used to: Get field information
getValue() - retrieves a field's value getReference() - retrieves a reference object from the database
36
What g\_form methods are used to: Change a field value
setValue() - sets a field's value clearValue() - clears a field's value
37
What g\_form methods are used to: Change a choice list
addOption() - adds an option to the end of a Choice list clearOptions() - removes all options from a Choice list
38
What g\_form methods are used to: get form information
getSections() - retuns the elements of a form's section as an array isNewRecord() - returns true if a record has never been saved
39
What g\_form methods are used to: generate form actions
addInfoMessage() - displays an informational message at the top of a form clearMessages() - removes messags previously added to the form
40
What does g\_form.getValue retrieve and what is something that needs to be watched when using this method
This returns a string despite the data type of the field. If returning a number is important use the g\_form.getIntValue() or g\_form.getDecimalValue()
41
what does the g\_user object do?
This GlideUser API provides useful methods to access information about the currently logged in user
42
the following are examples of what: firstName lastName userID userName
these are g\_user properties
43
what is the try/catch syntax and what does it do
This is a debugging tool used to capture runtime errors and is written as follows: try { //code to execute goes here } catch(err) { //code to deal with error here }
44
What does the following script do: function onChange(control, oldValue, newValue, isLoading, isTemplate) { if (isLoading || newValue == '') { return; } var incState = g\_form.getValue('incident'); jslog(" The value of incState is: " + incState); if (incState == 1) { jslog(" LINE 11 EXECUTED!"); g\_form.addDecoration('state', 'icon-edit','Gathering initital details'); g\_form.flash('state', "teal", -4); }
First this code logs the value of incState from the form on change. If it finds that incState == 1 it will report the value to ou then add a decoration and a flash.
45
what debugging tools are only available to desktop
the JavaScript log and Field Watcher
46
the g\_form methods and alert arguments can be what?
strings, g\_form properties or methods, g\_user properties or methods, variables, JavaScript string escape characters such as \n (new line)(ignored for g\_form methods)
47
What occurs when a script requests a record on another table in the database
1. A client-side script requests a record from the database 2. The server retrieves the requested record from the database and passes the record back to the calling client-side script as an object 3. The callback function logic executes when the object returns from the server
48
What does a callback function do in a script
the g\_form.getReference() method runs asynchronously when a callback function is used. When the record is returned to the calling script, the logic in the callback function executes. If the callback function is omitted, the g\_form.getReference() method runs synchronously.
49
What is the difference between synchronous and asynchronous
Synchronous getReference() method calls lock the form until the requested record is returned from the database. Asynchronous execution allows uers to continue using the form while the method executes.
50
What kind of code is the following: var userRecord = g\_form.getReference('caller\_id',callerInfo); function callerInfo (userRecord) { alert("User ID: " + userRecord.user\_name + "\nLocked Out:" + userRecord.locked\_out); }
this is an Asynchronous code that first gets the user info and then puts it into a function
51
What do g\_form methods do?
These are client scripts that are used to manage the form and form fields
52
what do g\_user properties and methods do
These are part of a client script and are used to access information about the currently logged in user
53
What does a UI policy do
defines the behavior and visibility of fields on a form: mandatory visible read-only condition must be true for it to execute execute after client scripts
54
What data can you see in a UI policy
local variables declared in a script, predfined client-side global variables such as g\_form (glideForm) g\_user(GlideUser) g\_scratchpad(in conjunction with a Display Business Rule, Module 5)
55
What is a business rule
JavaScript that runs when - a record is: * displayed * inserted * updated * deleted or a table is queried
56
What kind of business rule would do the following: Prevent users from one location from seeing CIs from another
A before business rule as this would run before the query is sent to the database
57
what are the pre-defined server side global variables
* current - is an object that stores the current record's fields and values; new/modified values. A script can change a field's value many times, current will store the most recent value. For example: if (previous.priority == current.priority { return; } * previous - is an object that stores the record's fields and values before any changes were made; the original values when the form loaded. Reference this object using previous.. For example: if (previous.priority == 1) { //logic here } * g\_scratchpad - display business rules only, works in conjunction with a client-side script
58
What is dot walking
This is a way to allow direct access to fields for related records (reference objects) by traversing tables ..
59
What is the "Script tree"
This is a tool used for dot walking that can be expanded while writing scripts. A table icon indicates the field references another table. Expand the reference object to select the field of interest from that table. A blue circle indicates the field that resides on the current table A red square indicates the field resides on a parent table An index field icon indicates the field is part of one or more indexes
60
Glide system logging methods sending debugging information to the system log or the top of the form. What are they?
the system log debuggers include: * gs.log() * gs.error() * gs.info() * gs.warn() The top of the form debuggers include: * gs.addInfoMessage() * gs.addErrorMessage()
61
What do i do to pass data from the server side to the client side during a form load
Display business rules
62
What do user methods do and what are some examples of them
they return information about the currently logged in user Examples: * getUser() - returns a reference to the User object for the current user * getUserName() - returns the username of the current user (fred.luddy) * getUserID() - returns the sys\_id of the current user * getUserDisplayName() - returns the name field of the current user (Fred Luddy instead of fred.luddy) * hasRole() - returns true if the user has the specified role * hasRoleInGroup() - returns true if the user has the specified role within a specified group
63
What will the following script return: if(gs.hasRole('itil')){ * gs.addInfoMessage("getUser() returns: " + gs.getUser()); * gs.addInfoMessage("getUserName() returns: " + gs.getUserName()); * gs.addInfoMessage("getUserID() returns: " + gs.getUserID()); * gs.addInfoMessage("getUserDisplayName() returns: " + gs.getUserDisplayName()); }
* getUser() returns: come.glide.sys.User@36426f72 * getUserName() returns: beth.anglin * getUserID() returns: 4644a23a9fe19810012d100cca8066 * getUserDisplayName() returns: Beth Anglin addInfoMessage() - adds a blue informatial message to the top of a form or list addErrorMessage() - adds a red warning message to the top of a form or list
64
What are system methods and some examples of them
System methods primarily work with form objects, tables, fields, and logging. Examples include the following: * getProperty() - returns the value of a Glide property * getPreference() - gets a user preference * getDisplayColumn() - gets the display column for the table * tableExists() - determines if a database table exists * nil() - returns true if a field's value is null or an empty string("") * eventQueue() - queues an event for the event manager * print() - writes a message to the system log * log() - logs a message to the system log and saves it to the syslog table * logError () - logs an error to the system log and saves it to the syslog table * getMessage() - retrieves translated messages to display in the UI.
65
Date and Time methods work with date and time data. What are some examples of these methods?
beginningOfLastWeek() - date and time for the beginning of last week in GMT (yyyy-mm-dd hh:mm:ss) beginningOfNextMonth() - date and time for the beginning of next month in GMT dateDiff() - calculates the difference between two dates endOfLastWeek() - date and time for the end of last week in GMT endOfNextMonth() - date and time for the end of next month in GMT minutesAgo()/quartersAgo()/monthsAgo()/yearsAgo() - returns the date and time a specified number of minutes/quarters/months/years ago now() - current date nowDateTime() - current date and time in the user-defined format
66
What does the following code do? ## Footnote var firstDay = current.u\_hire\_date.getDisplayValue(); var lastDay = current.u\_last\_date.getDisplayValue(); if(firstDay && lastDay) { if(gs.dateDiff(firstDay, lastDay, true) \< 0) { gs. addErrorMessage("Add error message here"); current. u\_last\_date = ''; current. setAbortAction(true); } }
This checks to see if first day and last day have values, and if they do it makes sure the lastDay isn't before the firstday
67
What is a display business rule?
rules to pass data from the server-side to the client-side during a form load
68
What does the glide system API do
it's a collection of methods, executes server side, accesses system-level information such as: * logged in user * system * date and time
69
What do the following user methods do: getUser() getUserDisplayName() getUserID() getUserName() hasRole() hasRoleInGroup()
getUser() - returns a refernce to the user object for the current user. getUserDisplayName() - returns the name field of the current user (Fred Luddy instead of fred.luddy) getUserID() - returns the sys\_id of the current user getUserName() - returns the username of the current user (fred.luddy) hasRole() - returns true if the user has the specified role hasRoleInGroup() - reutrns true if the user has the specified role within a specified group
70
What are system methods
These primarily work with form objects, tables, fields, and logging examples: * getProperty(), getPreferece() * getDisplayColumn(), tableExists() * nil(), eventQueue() * print(), log(), logError(), getMessage()
71
What do the following system methods do: * getProperty() * getPreference() * getDisplayColumn() * tableExists() * nil() * eventQueue() * print() * log() * logError() * getMessage()
* getProperty() - returns the value of a Glide property * getPreference() - gets a user preference * getDisplayColumn() - gets the display column for the table * tableExists() - determines if a database table exists * nil() - returns true if a field's value is null or an empty string("") * eventQueue() - queues an event for the event manager * print() - writes a message to the system log * log() - logs a message to the system log and saves it to the syslog table * logError() - logs an error to the system log and saves it to the syslog table * getMessage() - retrieves translated messages to display in the UI
72
what are date and time methods
work with date and time data: examples: * beginningOfLastWeek()/endOfLastWeek(), beginningOfNextMonth()/endOfNextMonth() * dateDiff() * now(), nowDateTime() * minutesAgo(), quartersAgo(), monthsAgo(), yearsAgo()
73
what is a gliderecord
* used for database operations instead of writing SQL queries * an object containing zero or more records from the same table (ordered list) * properties are the table's field names (columns) * execute server-side any table row from any table can become a GlideRecord GlideRecord queries can be called client-side but this should be avoided due to performance impact. The getReference() method previously discussed in Module 3 - Client Scripts performs a GlideRecord query
74
What is the strategy for creating a new GlideRecord query
1. Create a GlideRecord object for the table of interest 2. Build the query condition(s) 3. Execute the query 4. Process returned records with script logic
75
What are the four steps to using a glide record and their code
1. Create a GlideRecord object for the table of interest * var myObj = new GlideRecord('table\_name'); 2. Build the query condition(s) * myObj.addQuery('filed\_name', 'operator', 'value'); * myObj.addQuery('field\_name', 'operator', 'value'); * Execute the query * myObj.query(); 1. Process returned record(s) with script logic * while(myObj.next()) {
76
Step 1: Create a GlideRecord Object for the Table of Interest * To query a table, first create an object for the table * Object is called a GlideRecord * Only parameter needed is the name of the table
var myObj = new GlideRecord('table\_name'); var myObj = new GlideRecord('change\_request');
77
What is the code for the following portion of creating a glide record Step 2: Build the Query Condition(s) * addQuery() builds a SQL select statement (not seen by the user) * Each addQuery() call adds a new "where" clause to the select statement * addQuery() calls are automatically AND'ed
var myObj = new GlideRecord('change\_request'); myObj.addQuery('category', '=', 'Hardware'); myObj.addQuery('priority', '!=', 1); select \* from change\_request where category = hardware and priorty != 1;
78
What is the code for the following: Step 3: Execute the query
myObj.query();
79
What is the code for the following: Step 4: Process returned records with script logic
next() moves to the next record in the GlideRecord object while() iterates through all returned records if() process only the first record returned hasNext() steps through returned records and determines if there are any more records
80
what does the following code do: var incGR = new GlideRecord('incident'); incGR.addQuery('problem\_id', '=',current.sys\_id); incGR.query(); while (incGR.next()) { incGR.work\_notes = "related problem " + current.number + " closed with the following close notes: \n\n" + current.close\_notes; incGR.update(); }
The update() method to save changes to the records in the GlideRecord If record does not exist, it is inserted The work\_notes fields in the returned Incident records are updated with the value currently in the related Problem's close\_notes field
81
What are the four steps in the GlideRecord creation?
1. Create a GlideRecord object for the table of interest 2. Build the query condition(s) 3. Execute the query 4. Process returned record(s) with script logic
82
what is an addOrCondition()
use the addOrCondition() method to add a new condition to a select statement using OR works with addQuery() var myObj = new GlideRecord('change\_request'); var q1 = myObj.addQuery('category', '=', 'Hardware'); q1.addOrCondition('priority', '!=', 1); select\* from change\_request where category = 'Hardware' OR priority !=1; use an object variable and addQuery() to add the first condition and addOrCondition for the second conditon
83
how does the glide record mixing ANDs and ORs work Create "groups" to represent() (A or B) and (C or D)
var myObj = new GlideRecord('incident'); var q1 = myObj.addQuery('state', ' q1.addOrCondition('state', '\>', 5); var q2 = myObj.addQuery('priority', 1); q2.addOrCondition('priority', 5); myObj.query(); select \* from incident where (state\<3 OR state\>5) AND (priority = 1 OR priority = 5);
84
How do i code a query for a single record? get(object name, Object value) used to query for a single record returns: true - if a record is found false - if a record is not found
if(!current.parent\_incident.nil()) { var myObj = new GlideRecord('incident'); myObj.get(current.parent\_incident); myObj.u\_rca = true; myObj.update(); }
85