ServiceNow Scripting Fundamentals Flashcards

1
Q

When should you script?

A
  • Add new functionality
  • Extend existing functionality
  • Guide users through messaging (alerts/notification)
  • Automate processes
  • Interact with third party applications
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which administrator develops in the global scope?

A

System Administrator

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

Which administrator develops in a certain piece (like business rules), typically within a certain application?

A

System Definition Administrator

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

What is the name of ServiceNow’s built in text editor and what are it’s features?

A

Syntax Editor:
- Automatic Javascript syntax coloring, auto-indentation, line numbers, creation of closing braces and quotes
- Context-sensitive help
- Code editing functions
- Editor macros for typing commonly used code
- Syntax error checking

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

What does purple indicate within the Syntax Editor

A

Reserved words

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

What color does blue represent in the Syntax Editor?

A

Function/variable names or Strings

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

What do Bold/Italics represent in the Syntax Editor

A

Context menu items

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

What does the color green represent in the Syntax Editor?

A

Comments

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

How does Syntax Editor help with braces and quotes?

A
  • It automatically adds the closing quote, braces or parenthesis
  • It highlights pairs of brackets/parentheses
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the benefit of using single quotes in JavaScript?

A

Values within single quotes can be compared with equals, equals equals, numeric comparisons and more.

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

What functionalities does the Context-sensitive Help provide?

A
  • Displays a list of valid elements at the cursor’s current position
  • Lists methods for a class
  • Lists expected parameters
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you display valid elements at the cursor’s current position within the Syntax Editor?

A

CTRL + Spacebar at the beginning of a line

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

How do you view a list of methods for a class within the Syntax Editor?

A

Type a period after the class name

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

How do you view a list of expected parameters for a class or method?

A

Type 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
15
Q

If you create custom objects, does the Syntax Editor provide any suggestions for variables belonging to the object?

A

Yes, if you type a period after the object, it will suggest variables belonging to the object.

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

What options are presented when you right click on bold/italicized text within the Syntax Editor?

A

The context menu:
- Show definition
- Show data
- Find references

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

How do you find a list of other places an object is used from within Syntax Editor?

A

Right click on the context menu and click ‘Find references.’

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

What is an alternative method of adding commments to manually typing forward slashes?

A
  1. Highlight applicable text
  2. Click the “Toggle Comment” button in the bar at the top of the Syntax Editor.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

True or false: “Replace all” asks for confirmation before making the replacement(s)?

A

False. It does not.

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

What contains shortcuts for commonly used code?

A

The Syntax Editor Macros

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

How do you insert a Syntax Editor macro into your code?

A

Type the macro name and press tab.

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

How do you find the full list of Syntax Editor macros within the editor?

A

Type “help” and press tab.

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

What can the Syntax Editor “Syntax Checker” find?

A
  • Missing characters, such as { and [
  • Missing ; at the end of statements
  • Incomplete arguments in for loops
  • Bad function calls
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is the Syntax Editor “Syntax Checker” not able to find?

A

Typos, in:
- variable names
- function calls
- method calls

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

What do red circles indicate in Syntax Editor? Orange?

A
  • Red: Errors
  • Orange: Warnings
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What type of script presents an error at the bottom of the script if you attempt to save it without resolving an error?

A

Server-side

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

How do you view all configuration changes made to a table?

A

Type the table name in the Filter Navigator and append with .config

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

What are client scripts used for?

Provide 7 examples.

A

Managing behavior of forms, fields and lists in real time
- Make fields mandatory
- Set one field in response to another
- Modify choice list options
- Hide/show form sections
- Hide fields
- Display alerts
- Manage/prohibit list editing

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

What does it mean if the “Global” checkbox is checked on a client script?

A

The client script can be used on all views

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

When is an “onLoad” client script run?

A

On load BEFORE control is given to the user.

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

When is the “onSubmit” client script run?

A

When the form is saved, submitted or updated (when a button is clicked)

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

What are “onSubmit” client scripts typically used for?

A

Field validation

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

What is the purpose of an “onChange” client script?

A
  • Respond to field values of interest
  • Modify one field value in response to another
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

When might you use the ‘isTemplate’ parameter?

A

When you want to prevent a client script from running when a template is to be applied so that values from the template aren’t overwitten.

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

In an onChange client script, what does oldValue represent and when does it change?

A

The date saved in the server.

Old value is not changed until it is saved back to the server again.

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

What is the purpose of the GlideForm API?

A
  • Customizing forms
  • Managing form fields and their data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

Which value, server or form, does g_form.getValue() retrieve?

A

Value selected on form

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

When g_form.getValue() is called against a string field, what is returned?

A

The string field as it appears on the form

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

When g_form.getValue() is called against a non-string field, what is returned?

A

The value as it is saved in the server, not the display/user-friendly label.

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

What functionality does the GlideUser API provide?

A

Methods to access informationa bout the currently logged in user.

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

What scope does the GlideUser API belong to?

A

Global

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

Which debugging method is suggested for catching runtime errors?

A

Try/catch

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

How are views input on the client script record?

A

Comma separated list

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

In what order to client scripts run if they have the same value in the “order” field?

A

Either by created by or the sys ID with the lower hexadecimal value.

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

What causes a GlideRecord query to execute the query?

A

gr.query();

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

How would you check if a GlideRecord query has another record?

A

if(myObj.hasNext()) {}

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

How do you add an OR condition to a GlideRecord query?

A
  1. Create the GlideRecord object
  2. Create a new variable and assign your addQuery to it
  3. Run .addOrQuery on the variable created in the step above

var gr = new GlideRecord(‘table’);
var q1 = gr.addQuery(‘cat’, ‘lucy’);
q1.addOrQuery(‘cat’, ‘felix’);

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

What would your query be if you wanted the following:
- State is 3 or State is 5
- AND priority is 1 or impact is 1

A

var gr = new GlideRecord(‘incident’);
var q1 = addQuery(‘state’, 3);
q1.addOrQuery(‘state’, 5);
var q2 = addQuery(‘priority’, 1);
q2.addOrQuery(‘impact’, 1);

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

When counting records, what is the benefit of using getRowCount?
What is the benefit of GlideAggregate?

A
  • getRowCount: Less code but larger performance impact. Because it’s getting all the records/their details and then counting them.
  • GlideAggregage: More code but executes quicker
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
50
Q

How do you use getRowCount?

A

After .query(), assign gr.getRowCount() to a new variable.

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

How do you use GlideAggregate?

A

var count = new GlideAggregate(‘table’);
count.addQuery(‘field’, ‘value’);
count.addAggregate(‘COUNT’);
count.query();
var incidentCount = 0;
if (count.next()) {
incidents = count.getAggregate(‘COUNT’);
}

52
Q

When is it recommended to use GlideAggregate?

A

If your table has more than 100 rows.

53
Q

What are three benefits of GlideQuery?

A
  • Presents errors as soon as possible (Fail fast)
  • Behaves like normal Javascript, instead of mixing Java and Javascript elements like GlideRecord
  • Do more with less lines of code
54
Q

How do you write the following query in GlideQuery?

var gr = new GlideRecord(‘task’);
gr.addQuery(‘closed_date’, ‘<’ ‘2016-01-01’);
gr.query();
gr.deleteMultiple();

A

new GlideQuery(‘task’)
.where(‘closed_date’, ‘<’ ‘2016-01-01 00:00:00’)
.deleteMultiple();

*Note how there are no semicolons until the last statement.

55
Q

The following query’s field is mistyped. What happens when it is executed?

var gr = new GlideRecord(‘task’);
gr.addQuery(‘closed_date’, ‘<’ ‘2016-01-01’);
gr.query();
gr.deleteMultiple();

A

The addQuery is ignored.
All task records are deleted and no error is generated.

56
Q

The following query’s field is mistyped. What happens when it is executed?

new GlideQuery(‘task’)
.where(‘closed_date’, ‘<’ ‘2016-01-01 00:00:00’)
.deleteMultiple();

A

The NiceError shows the problem and known fields

57
Q

How do you write this query in GlideQuery?

var gr = new GlideRecord(‘task’);
gr.addQuery(‘approval’, ‘not requested’);
gr.query();
while (gr.next()) {
doSomething(gr.assigned_to,gr.description);
}

A

new GlideQuery(‘task’)
.where(‘approval’, ‘not requested’)
.select(‘assigned_to’, ‘description’)
.forEach(doSomething);

58
Q

In the code below, ‘not_requested’ is not a valid choice. What happens when it is executed?

var gr = new GlideRecord(‘task’);
gr.addQuery(‘approval’, ‘not_requested’);
gr.query();
while (gr.next()) {
doSomething(gr.assigned_to,gr.description);
}

A

The script runs, but no results are returned.

59
Q

In the code below, ‘not_requested’ is not a valid choice. What happens when it is executed?

new GlideQuery(‘task’)
.where(‘approval’, ‘not_requested’)
.select(‘assigned_to’, ‘description’)
.forEach(doSomething);

A

The NiceError shows the invalid choice and allowed values.

60
Q

How do you write the following query in GlideQuery?

var gr = new GlideRecord(‘task’);
gr.addQuery(‘priority’, ‘<’, ‘1’);
gr.addQuery(‘location.country’, ‘United Kingdom’);
gr.query();
while (gr.next()) {
sendNotification(gr);
}

A

new GlideQuery(‘task’)
.where(‘priority’, ‘<’, ‘1’)
.whereNotNull(‘assigned_to’)
.select(‘assigned_to.name’, ‘priority’)
.forEach(doSomething);

61
Q

The priority value used in the code below is invalid. What happens when it is executed?

var gr = new GlideRecord(‘task’);
gr.addQuery(‘priority’, ‘<’, ‘V’);
gr.addQuery(‘location.country’, ‘United Kingdom’);
gr.query();
while (gr.next()) {
sendNotification(gr);
}

A
62
Q

The priority value used in the code below is invalid. What happens when it is executed?

new GlideQuery(‘task’)
.where(‘priority’, ‘<’, ‘1’)
.whereNotNull(‘assigned_to’)
.select(‘assigned_to.name’, ‘priority’)
.forEach(doSomething);

A

The NiceError shows the type error and the expected type.

63
Q

How do you check the type of a value?

A

typeof(whatyourechecking)

64
Q

Is the value 0 truthy or falsy?

A

Truthy

65
Q

How do you create a record with the following attributes using GlideQuery on the sys_user table?
- Username: sock.monkey
- First name: Sock
- Last name: Monkey
- Roles: admin

A

new GlideQuery(‘sys_user’)
.insert({
user_name: ‘sock.monkey’,
first_name: ‘Sock’,
last_name: ‘Monkey’,
roles: ‘admin’
})
.get()

66
Q

How do you retrieve roles from a record on the sys_user table with the username of sock.monkey using GlideQuery?

A

var newUser = new GlideQuery(‘sys_user’)
.where(‘user_name’, ‘sock.monkey’)
.selectOne(‘roles’)
.get();

67
Q

How do you update the roles of a specific user record with GlideQuery?

A

new GlideQuery(‘sys_user’)
.where(‘sys_id’, sysID)
.update({
roles: ‘itil’
});

68
Q

How do you delete a record with GlideQuery?

A

new GlideQuery(table)
.where(field, value)
.deleteMultiple();

69
Q

What class is used with GlideQuery when multiple records need to be read?

A

Stream

70
Q

How are records returned with the Stream class when using GlideQuery()?

A

.select()

71
Q

What methods can be used in combination with the Stream class/.select()

A
  • map
  • flatMap
  • forEach
  • reduce
  • some/any
72
Q

What class is used with GlideQuery to read a single record?

A

Optional

73
Q

How is a record returned with the Optional class when using GlideQuery()?

A
  • selectOne()
  • insert()
  • update()
74
Q

What methods can be used with the Optional class?

A
  • get
  • map
  • isEmpty
  • isPresent
  • ifPresent
  • orElse
75
Q

When does the Optional class return “empty” when using GlideQuery?

A

If no records are returned

76
Q

What does .select() do within GlideQuery?

A

Limits the fields returned by the query to the ones specified.
- It is analogous to .query() within GlideRecord.

77
Q

What does .where() do within GlideQuery?

A

Filters the records to be returned by the query.

78
Q

How do you specify that a specific number of records be returned by GlideQuery?

A

.limit(x)

79
Q

How do you perform a specific action on each record when running a GlideQuery?

A

.forEach()

80
Q

Using GlideQuery, how do you return 1 record without using .limit()?

A

.selectOne(field, value)
.get();

81
Q

Is GlideRecord or GlideQuery faster?

A

GlideRecord
- GlideQuery has to be translated into GlideRecord.

82
Q

True or False:
A script include can be configured so that it is callable from both server-side and client side.

A

False
It must be set up for one or the other.

83
Q

What are the 3 types of script includes?

A
  • Store One Classless Function
  • Define a New Class
  • Extend an Existing Class
84
Q

What is the syntax for declaring a new class within a script include?

A

var ClassName = Class.create();
ClassName.prototype = {
initialize: function() {
},
type: ‘ClassName’
};

85
Q

What class is extended when “Client callable” is checked on a script include?

A

AbstractAjaxProcessor

86
Q

True or False:
You are unable to initialize custom variables within a script include that extends another script include.

A

True.
- It uses the initialize function of the script include you are extending.

87
Q

What are the steps for calling a script include client-side?

A
  1. Create a new GlideAjax object for the script include of interest
    - var ga = new GlideAjax(‘HelloWorld’);
  2. Pass parameters to the script include. sysparm_name is a reserved parameter used to represent the name of the method.
    - ga.addParam(‘sysparm_name’, ‘alertGreeting’);
    - ga.addParam(‘sysparm_user_name’,’Ruth’);
  3. Make call to the server. Sends an XML containing parameters to the script include. HelloWorldParse is the name of the callback function.
    - ga.getXML(HelloWorldParse);
  4. Callback function processes returned data
    - function HelloWorldParse(response) {
    var answerFromXML = response.responseXML.documentElement.getAttribute(“answer”);
    alert(answerFromXML);
    }
88
Q

How do you read a parameter from the client-side call within a script include?

A

this.getParameter(‘sysparm_parameter_name’)

89
Q

What does JSON stand for?

A

JavaScript Object Notation

90
Q

What is a more efficient way to return data from a client-callable script include?

A

Using JSON
- You can return a stringified object or array of objects.

91
Q

How do you access values from the JSON object received from a client-callable script include?

A

Within the callback function, parse the object received.
- You can dot walk from the parsed objec to get specific values.
- You can access elements by index if an array was returned and then dot walk for their attributes.

92
Q

Under which application is Flow Designer found?

A

Process Automation

93
Q

Where can the Flow API be used?
The FlowScript API?

A
  • Flow API: Outside of Flow Designer (Scripts, Background, business Rules) and inside Flow Designer, for example to call other flows)
  • FlowScript API: Only inside FlowDesigner
94
Q

What two categories do scripts within ServiceNow fall into?

A
  • Client-side
  • Server-side
95
Q

What are client-side scripts used for within ServiceNow?

A

Managing forms and form fields:
- Place the cursor in a form field on form load
- Generate alerts, confirmations and messages
- Populate a form field in response to another field’s value
- Highlight a form field
- Validate form data
- Modify choice list options
- Hide/Show fields or sections

96
Q

When can client-side scripts execute?

A

Whne forms are:
- Loaded
- Changed
- Submitted

97
Q

Which type of script should be used to validate field values?

A

onSubmit

98
Q

When configuring a client script, what options exist within “UI Type?”

A
  • Desktop
  • Tablet
  • Mobile/Service Portal
  • All
99
Q

When configuring a client script, what options exist under “Type?”

A
  • onChange
  • onLoad
  • onSubmit
100
Q

What is enabled when “Inherited” is marked as true on a client script?

A

The ability of the script to be evaluated on tables extended from the table the script was configured for.

101
Q

What does the “Global” checkbox control with regards to client-script configuration?

A

Whether the script applies to all views.

When false, you must specify the view the script applies to.

102
Q

What arguments can be passed to an onLoad client script?

A

None. No arguments are passed to an onLoad client script.

103
Q

What is the syntax for the onLoad script template?

A

function onLoad() {}

104
Q

What arguments can be passed to an onSubmit client script?

A

None. No arguments are passed to an onSubmit client script.

105
Q

What is the syntax for the onSubmit script template?

A

function onSubmit() {}

106
Q

What parameters are passed into an onChange client script?
What do they represent?

A
  • control: field the Client Script is configured for
  • oldValue: value of the field when the form loaded. Value held in the database.
  • newValue: value of the field after the change
  • isLoading: boolean value indicating whether the change is occurring as part of a form load.
  • isTemplate: boolean value indicating whether the change occurred due to population of the field by a template.
107
Q

What occurs when a record is selected?

A
  • The form and form layout are rendered
  • Fields are populated with values from the database
108
Q

What is the syntax for an onChange client script?

A

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == ‘’) {
return;
}
}

109
Q

When is the value of “oldValue” set for an onChange client script?

A

When the form loads.

110
Q

A record has a short description field holding the value of “hello”.
What is the value of oldValue and newValue after each of the following events?
1. Form loads:
2. User changes the value in the Short description field to bye:
3. User changes the value in the Short description field to greetings:
4. User saves the form and reloads the form page:

A
  1. oldValue = hello, newValue = no value
  2. oldValue = hello, newValue = bye
  3. oldValue = hello, newValue = greetings
  4. oldValue = greetings, newValue = no value
111
Q

How do you get to client scripts within Studio?

A

Client Development > Client Scripts

112
Q

What is the purpose of methods within the GlideForm API?

A

Managing forms and form fields

113
Q

What are some capabilities of the GlideForm API (6)?

A
  • Retrieve a field value on a form
  • Hide a field
  • Make a field read-only
  • Write a message on a form or a field
  • Add fields to a choice list
  • Remove fields from a choice list
114
Q

What object is used to access GlideForm methods?

A

g_form

115
Q

Which of the following is a strategy for debugging Client Scripts or UI policies?

A
  • Browser’s Developer Console
  • Debug UI Policies module
  • JavaScript try/catch
  • JavaScript Log and jslog()
  • Field Watcher
116
Q

Do UI Policies execute UI Policy scripts only when the Condition field evaluates to true? Explain your reasoning.

A

If the Reverse if False option is selected, UI Policies execute the “Execute if false” script when the Condition field evaluates to false.

117
Q

Which of these classes are part of the ServiceNow client-side API?
- GlideSystem
- GlideUser
- GlideDateTime
- GlideDate
- GlideForm

A
  • GlideUser
  • GlideForm
118
Q

When do onSubmit client scripts execute their script logic?
1. When a user clicks the Submit button
2. When a user clicks the Delete button
3. When a user clicks the Update button
4. When a user clicks the Save menu item in the Additional Actions menu
5. When a user clicks the Lookup button on a reference field.

A
  • When a user clicks the Submit button.
  • When a user clicks the Update button
  • When a user clicks the Save menu item in the Additional Actions menu
119
Q

True or False:
A single Client Script can execute its script logic when a user loads a record into a form AND when a user saves/submits/updates a form.

A

False.

A single client script can be either onLoad or onSubmit but cannot be both.

120
Q

True or False:
A single Client Script can execute its script logic when a user loads a record into a form AND when a user changes a value in a field.

A

True.

An onChange client script could handle this behavior. When a form is loaded, field/variable values that are populated are technically changed from blank to the value held in the database.

121
Q

True or False:
UI Policies require scripting to make form fields Mandatory, Visible or Read-only.

A

False.

UI Policy actions can set field attributes without scripting.

122
Q

When can UI policies execute their logic?
- When a record is loaded into a form
- When field values change on a form
- When a form is saved, submitted or updated
- When a Client Script executes
- When a record is loaded into a list

A
  • When a record is loaded into a form
  • When field values change on a form
123
Q

What functionality does the GlideUser API provide?

A

Methods and properties for finding information about the currently logged in user and their roles.

124
Q

Which object is used to access GlideUser methods and properties?

A

g_user

125
Q

How do you check whether a user has a specific role from a client script?

A

g_user.hasRole()

126
Q

How do you check whether a user has a role directly assigned, ?aka it is not inherited?

A

g_user.hasRoleExactly()