ServiceNow Scripting Fundamentals Flashcards

1
Q

When should you script? (5)

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
- Syntax 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 color does blue represent in the Syntax Editor?

A

Reserved words

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
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
7
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
8
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
9
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
10
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
11
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
12
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
13
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
14
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
15
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
16
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
17
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
18
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
19
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
20
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
21
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
22
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
23
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
24
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
25
What type of script presents an error at the bottom of the script if you attempt to save it without resolving an error?
Server-side
26
How do you view all configuration changes made to a table?
Type the table name in the Filter Navigator and append with .config
27
What are client scripts used for? Provide 7 examples.
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
28
When is an "onLoad" client script run?
On load BEFORE control is given to the user.
29
When is the "onSubmit" client script run?
When the form is saved, submitted or updated (when a button is clicked)
30
What are "onSubmit" client scripts typically used for?
Field validation
31
What is the purpose of an "onChange" client script?
- Respond to field values of interest - Modify one field value in response to another
32
When might you use the 'isTemplate' parameter?
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.
33
In an onChange client script, what does oldValue represent and when does it change?
The date saved in the server. Old value is not changed until it is saved back to the server again.
34
What is the purpose of the GlideForm API?
- Customizing the view of forms - Managing form fields and their data
35
Which value, server or form, does g_form.getValue() retrieve?
Value selected on form
36
When g_form.getValue() is called against a string field, what is returned?
The string field as it appears on the form
37
When g_form.getValue() is called against a non-string field, what is returned?
The value as it is saved in the server, not the display/user-friendly label.
38
What functionality does the GlideUser API provide?
Methods to access information about the currently logged in user.
39
What scope does the GlideUser API belong to?
Global
40
Which debugging method is suggested for catching runtime errors?
Try/catch
41
How are views input on the client script record?
Comma separated list
42
In what order to client scripts run if they have the same value in the "order" field?
Either by created or the sys ID with the lower hexadecimal value.
43
What causes a GlideRecord query to execute the query?
gr.query();
44
How would you check if a GlideRecord query has another record?
if(myObj.hasNext()) {}
45
How do you add an OR condition to a GlideRecord query?
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');
46
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
var gr = new GlideRecord('incident'); var q1 = addQuery('state', 3); q1.addOrQuery('state', 5); var q2 = addQuery('priority', 1); q2.addOrQuery('impact', 1);
47
When counting records, what is the benefit of using getRowCount? What is the benefit of GlideAggregate?
- 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
48
How do you use getRowCount?
After .query(), assign gr.getRowCount() to a new variable.
49
How do you use GlideAggregate?
var count = new GlideAggregate('table'); count.addQuery('field', 'value'); count.addAggregate('COUNT'); count.query(); var incidentCount = 0; if (count.next()) { incidents = count.getAggregate('COUNT'); }
50
When is it recommended to use GlideAggregate?
If your table has more than 100 rows.
51
What are three benefits of GlideQuery?
- 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
52
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();
new GlideQuery('task') .where('closed_date', '<' '2016-01-01 00:00:00') .deleteMultiple(); *Note how there are no semicolons until the last statement.
53
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();
The addQuery is ignored. All task records are deleted and no error is generated.
54
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();
The NiceError shows the problem and known fields
55
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); }
new GlideQuery('task') .where('approval', 'not requested') .select('assigned_to', 'description') .forEach(doSomething);
56
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); }
The script runs, but no results are returned.
57
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);
The NiceError shows the invalid choice and allowed values.
58
The priority value used in the code below is invalid. What happens when it is executed? new GlideQuery('task') .where('priority', '<', 'v') .whereNotNull('assigned_to') .select('assigned_to.name', 'priority') .forEach(doSomething);
The NiceError shows the type error and the expected type.
59
How do you check the type of a value?
typeof(whatyourechecking)
60
Which values are falsy?
All values are truthy unless they are defined as falsy: * false * 0 * -0 * 0n * "" * null * undefined * NaN
61
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
new GlideQuery('sys_user') .insert({ user_name: 'sock.monkey', first_name: 'Sock', last_name: 'Monkey', roles: 'admin' }) .get()
62
How do you retrieve roles from a record on the sys_user table with the username of sock.monkey using GlideQuery?
var newUser = new GlideQuery('sys_user') .where('user_name', 'sock.monkey') .selectOne('roles') .get();
63
How do you update the roles of a specific user record with GlideQuery when the sys ID is known? Role to be updated is itil.
new GlideQuery('sys_user') .where('sys_id', sysID) .update({ roles: 'itil' });
64
How do you delete a record with GlideQuery?
new GlideQuery(table) .where(field, value) .deleteMultiple();
65
What class is used with GlideQuery when multiple records need to be read?
Stream
66
With which method are records returned with the Stream class when using GlideQuery()?
.select()
67
What methods can be used in combination with the Stream class and the .select() method? (5)
- map - flatMap - forEach - reduce - some/any
68
What class is used with GlideQuery to read a single record?
Optional
69
What are 5 common methods that return an object of the Optional class?
Any of these: - get - map - isEmpty - isPresent - ifPresent - orElse - selectOne - insert() - update()
70
When does the Optional class return "empty" when using GlideQuery?
If no records are returned
71
What does .select() do within GlideQuery?
Limits the fields returned by the query to the ones specified. - It is analogous to .query() within GlideRecord.
72
What does .where() do within GlideQuery?
Filters the records to be returned by the query.
73
How do you specify that a specific number of records be returned by GlideQuery?
.limit(x)
74
How do you perform a specific action on each record when running a GlideQuery?
.forEach()
75
What are 2 GlideQuery methods that allow you to return 1 record without using .limit()?
.selectOne(field, value) .get();
76
Is GlideRecord or GlideQuery faster?
GlideRecord - GlideQuery has to be translated into GlideRecord.
77
True or False: A script include can be configured so that it is callable from both server-side and client side.
False It must be set up for one or the other.
78
What are the 3 types of script includes?
- Classless script storing one function - Definition of a new class - Extension of an existing class
79
What class is extended when "Client callable" is checked on a script include?
AbstractAjaxProcessor
80
True or False: You are unable to initialize custom variables within a script include that extends another script include.
True. - It uses the initialize function of the script include you are extending.
81
What are the steps for calling a script include client-side?
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); }
82
How do you read a parameter from the client-side call within a script include?
this.getParameter('sysparm_parameter_name')
83
What does JSON stand for?
JavaScript Object Notation
84
What is a more efficient way to return data from a client-callable script include?
Using JSON - You can return a stringified object or array of objects.
85
How do you access values from the JSON object received from a client-callable script include?
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.
86
Under which application is Flow Designer found?
Process Automation
87
Where can the Flow API be used? The FlowScript API?
- 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
88
What two categories do scripts within ServiceNow fall into?
- Client-side - Server-side
89
Give 5 examples of client script uses.
Any 5 of the following - 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
90
When can client-side scripts execute?
When: - Form loaded - Form submitted - Field value changed
91
Which type of script should be used to validate field values?
onSubmit
92
When configuring a client script, what options exist within "UI Type?"
- Desktop - Mobile/Service Portal - All
93
When configuring a client script, what options exist under "Type?"
- onChange - onLoad - onSubmit - onCellEdit
94
What is enabled when "Inherited" is marked as true on a client script?
The ability of the script to be evaluated on tables extended from the table the script was configured for.
95
What is true if the "Global" checkbox is checked? If it is not checked?
- True: The script applies to all views. - False: Applies only to the views you manually specify.
96
What arguments are passed to an onLoad client script?
None.
97
What is the syntax for the onLoad script template?
function onLoad() {}
98
What arguments are passed to an onSubmit client script?
None.
99
What is the syntax for the onSubmit script template?
function onSubmit() {}
100
What parameters are passed into an onChange client script? What do they represent?
- 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.
101
What occurs when a record is selected?
- The form and form layout are rendered - Fields are populated with values from the database
102
What is the syntax for an onChange client script?
function onChange(control, oldValue, newValue, isLoading, isTemplate) { if (isLoading || newValue == '') { return; } }
103
When is the value of "oldValue" set for an onChange client script?
When the form loads.
104
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:
1. oldValue = hello, newValue = no value 2. oldValue = hello, newValue = bye 3. oldValue = hello, newValue = greetings 4. oldValue = greetings, newValue = no value
105
How do you get to client scripts within Studio?
Client Development > Client Scripts
106
What is the purpose of methods within the GlideForm API?
Managing forms and form fields
107
What are some capabilities of the GlideForm API (6)?
- 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
108
What object is used to access GlideForm methods?
g_form
109
What are 5 ways to debug Client Scripts or UI policies?
- Browser's Developer Console - Debug UI Policies module - JavaScript try/catch - JavaScript Log and jslog() - Field Watcher
110
Do UI Policies execute UI Policy scripts only when the Condition field evaluates to true? Explain your reasoning.
If the Reverse if False option is selected, UI Policies execute the "Execute if false" script when the Condition field evaluates to false.
111
Which of these classes are part of the ServiceNow client-side API? - GlideSystem - GlideUser - GlideDateTime - GlideDate - GlideForm
- GlideUser - GlideForm
112
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.
- 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
113
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.
False. A single client script can be either onLoad or onSubmit but cannot be both.
114
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.
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.
115
True or False: UI Policies require scripting to make form fields Mandatory, Visible or Read-only.
False. UI Policy actions can set field attributes without scripting.
116
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
- When a record is loaded into a form - When field values change on a form
117
Which object is used to access GlideUser methods and properties?
g_user
118
How do you check whether a user has a specific role from a client script?
g_user.hasRole()
119
How do you check whether a user has a role directly assigned, ?aka it is not inherited?
g_user.hasRoleExactly()
120
Which executes first, UI policy actions or UI policy scripts?
UI policy actions execute before UI policy scripts
121
What does red text in the syntax editor represent?
Strings
122
What does teal text represent in the syntax editor
Function/variable names
123
What does .select() do in GlideQuery?
Specifies which fields to return Returns a stream containing results of the query
124
What does .selectOne() do in GlideQuery?
Specifies which fields to return Returns an optional which may contain a single record
125
What are the parameters for the GlideQuery method .insert()?
keyvalues, [selectedFields]
126
What does the .update() method do in GlideQuery? What does it return?
Updates an existing record Returns an optional of the newly updated record
127
What are 3 qualities of the Stream class?
- Used for returning/reading multiple records - Data is returned like a JavaScript array - Lazily evaluated allowing millions of records to be queried without allocating large amounts of memory
128
What are 2 qualities of the Optional class?
- Used for reading a single record - Is considered "empty" if a record isn't returned by the query
129
What does the .forEach() GlideQuery method do?
Iterates through records returned by the query.
130
What does the .get() GlideQuery method do?
Displays a single GlideRecord query result
131
What type of script include is not client-callable even if the checkbox is marked as true?
Classless, ones in which the default template is deleted.
132
What must be true for a function that is not declared first in a classless script include to be called?
The first script must have been completed execution first.
133
How do you call a function from a classless script include?
Reference only the method name.
134
What does AJAX stand for?
Asynchronous JavaScript and XML
135
When is g_scratchpad set?
On form load
136
What is the syntax to call a script include that exists in another scope?
Prepend the script include's name with the unique scope namespace.
137
What role is given for users to develop in flow designer?
flow_designer
138
Why should granting the flow_designer role be done with caution?
It gives the user access to all tables and database operations, which is equal to the admin role.
139
What 7 links are on the Flow Designer homepage?
* Flows * Subflows * Actions * Flow Executions * Connections * Help * New
140
Define "Flow."
An automated process consisting of a trigger and sequence of actions.
141
Define "Subflow."
A sequence of reusable actions that can be started from a flow, subflow or script.
142
Define "Action" as it relates to Flow Designer.
A reusable operation that enables Process Analysts to automate new platform features without having to write code.
143
Define "Flow execution."
A list of associated execution detail pages. Each page is created when a flow runs and stores information about configuration and runtime values.
144
What is the purpose of the "Connections" link on the Flow Designer homepage?
Add, edit and view Integration Hub connections.
145
What is the purpose of the "Help" link on the Flow Designer homepage?
Contains links to documentation, videos and community discussions
146
What options are available when you click "New" in Flow Designer?
Create a new Flow, Subflow or Action
147
What are the 3 flow designer triggers?
* Record * Schedule (Date) * Application
148
What does a record-based trigger require in Flow Designer? (2)
* Table to monitor * Condition to start the flow
149
What choice do you select if you want the flow to run repeatedly in predefined intervals?
Repeat
150
Which executes first, client script or UI policy? If there is a conflict between a client script and UI policy?
- Default: Client script - In conflict: UI policy https://developer.servicenow.com/dev.do#!/learn/courses/washingtondc/app_store_learnv2_scripting_washingtondc_scripting_in_servicenow/app_store_learnv2_scripting_washingtondc_client_side_scripting/app_store_learnv2_scripting_washingtondc_client_scripts_vs_ui_policies
151
Which standards does the Javascript engine in ServiceNow support?
ECMAScript5 and ECMAScript 2021
152
Which system property enables/disables display of the context editor?
glide.ui.syntax_editor.context_menu
153
Which font style is used for tokens with a context menu?
Bold
154
Where are syntax editor macros located?
System Definition > Syntax Editor Macros
155
Which script type will save with syntax errors?
Client
156
What is an artifact?
Application files in an application.