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
Q

How does an onSubmit() script work

A

This runs when a form is saved, updated, or submitted and is typically used for field validation

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

What does the following code do:

function onSubmit() {

if (!myCondition) {

return false;

else {

//perform some logic here

}

}

A

This runs on form submission and will cancel the submission if “myCondition” isn’t met. Return false is what cancels the process.

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

How does an onChange() script work

A

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.

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

What are the five parameters automatically passed to an onChange client script and what do they do?

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

How does the onCellEdit() script work?

A

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.

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

what parameters are automatically passed to an onCellEdit() Client Script

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

what does the following function do:

A

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.

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

What are the three most popular client-side APIs

A

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.

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

What can you use to access GlideForm methods

A

g_form global object

for example:

g_form.setValue(‘impact’,1);

g_form.showFieldMsg(‘state’,’Change is waiting approval’,’info’);

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

What g_form methods are used to:

Draw attention to an area on the form

A

flash() - flashes a field’s label to draw attention to it

showFieldMsg() - displays a message under a form field

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

What g_form methods are used to:

Get field information

A

getValue() - retrieves a field’s value

getReference() - retrieves a reference object from the database

36
Q

What g_form methods are used to:

Change a field value

A

setValue() - sets a field’s value

clearValue() - clears a field’s value

37
Q

What g_form methods are used to:

Change a choice list

A

addOption() - adds an option to the end of a Choice list

clearOptions() - removes all options from a Choice list

38
Q

What g_form methods are used to:

get form information

A

getSections() - retuns the elements of a form’s section as an array

isNewRecord() - returns true if a record has never been saved

39
Q

What g_form methods are used to:

generate form actions

A

addInfoMessage() - displays an informational message at the top of a form

clearMessages() - removes messags previously added to the form

40
Q

What does g_form.getValue retrieve and what is something that needs to be watched when using this method

A

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
Q

what does the g_user object do?

A

This GlideUser API provides useful methods to access information about the currently logged in user

42
Q

the following are examples of what:

firstName

lastName

userID
userName

A

these are g_user properties

43
Q

what is the try/catch syntax and what does it do

A

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
Q

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);

}

A

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
Q

what debugging tools are only available to desktop

A

the JavaScript log and Field Watcher

46
Q

the g_form methods and alert arguments can be what?

A

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
Q

What occurs when a script requests a record on another table in the database

A
  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
Q

What does a callback function do in a script

A

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
Q

What is the difference between synchronous and asynchronous

A

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
Q

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);

}

A

this is an Asynchronous code that first gets the user info and then puts it into a function

51
Q

What do g_form methods do?

A

These are client scripts that are used to manage the form and form fields

52
Q

what do g_user properties and methods do

A

These are part of a client script and are used to access information about the currently logged in user

53
Q

What does a UI policy do

A

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
Q

What data can you see in a UI policy

A

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
Q

What is a business rule

A

JavaScript that runs when -

a record is:

  • displayed
  • inserted
  • updated
  • deleted

or a table is queried

56
Q

What kind of business rule would do the following:

Prevent users from one location from seeing CIs from another

A

A before business rule as this would run before the query is sent to the database

57
Q

what are the pre-defined server side global variables

A
  • 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
Q

What is dot walking

A

This is a way to allow direct access to fields for related records (reference objects) by traversing tables

..

59
Q

What is the “Script tree”

A

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
Q

Glide system logging methods sending debugging information to the system log or the top of the form. What are they?

A

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
Q

What do i do to pass data from the server side to the client side during a form load

A

Display business rules

62
Q

What do user methods do and what are some examples of them

A

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
Q

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());

}

A
  • 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
Q

What are system methods and some examples of them

A

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
Q

Date and Time methods work with date and time data. What are some examples of these methods?

A

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
Q

What does the following code do?

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);

}

}

A

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
Q

What is a display business rule?

A

rules to pass data from the server-side to the client-side during a form load

68
Q

What does the glide system API do

A

it’s a collection of methods, executes server side, accesses system-level information such as:

  • logged in user
  • system
  • date and time
69
Q

What do the following user methods do:

getUser()

getUserDisplayName()

getUserID()

getUserName()

hasRole()

hasRoleInGroup()

A

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
Q

What are system methods

A

These primarily work with form objects, tables, fields, and logging

examples:

  • getProperty(), getPreferece()
  • getDisplayColumn(), tableExists()
  • nil(), eventQueue()
  • print(), log(), logError(), getMessage()
71
Q

What do the following system methods do:

  • getProperty()
  • getPreference()
  • getDisplayColumn()
  • tableExists()
  • nil()
  • eventQueue()
  • print()
  • log()
  • logError()
  • getMessage()
A
  • 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
Q

what are date and time methods

A

work with date and time data:

examples:

  • beginningOfLastWeek()/endOfLastWeek(), beginningOfNextMonth()/endOfNextMonth()
  • dateDiff()
  • now(), nowDateTime()
  • minutesAgo(), quartersAgo(), monthsAgo(), yearsAgo()
73
Q

what is a gliderecord

A
  • 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
Q

What is the strategy for creating a new GlideRecord query

A
  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
Q

What are the four steps to using a glide record and their code

A
  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
Q

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
A

var myObj = new GlideRecord(‘table_name’);

var myObj = new GlideRecord(‘change_request’);

77
Q

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
A

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
Q

What is the code for the following:

Step 3: Execute the query

A

myObj.query();

79
Q

What is the code for the following:

Step 4: Process returned records with script logic

A

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
Q

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();

}

A

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
Q

What are the four steps in the GlideRecord creation?

A
  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
Q

what is an addOrCondition()

A

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
Q

how does the glide record mixing ANDs and ORs work

Create “groups” to represent()

(A or B) and (C or D)

A

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
Q

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

A

if(!current.parent_incident.nil()) {

var myObj = new GlideRecord(‘incident’);

myObj.get(current.parent_incident);

myObj.u_rca = true;

myObj.update();

}

85
Q
A