ServiceNow Scripting Fundamentals Flashcards
When should you script?
- Add new functionality
- Extend existing functionality
- Guide users through messaging (alerts/notification)
- Automate processes
- Interact with third party applications
Which administrator develops in the global scope?
System Administrator
Which administrator develops in a certain piece (like business rules), typically within a certain application?
System Definition Administrator
What is the name of ServiceNow’s built in text editor and what are it’s features?
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
What does purple indicate within the Syntax Editor
Reserved words
What color does blue represent in the Syntax Editor?
Function/variable names or Strings
What do Bold/Italics represent in the Syntax Editor
Context menu items
What does the color green represent in the Syntax Editor?
Comments
How does Syntax Editor help with braces and quotes?
- It automatically adds the closing quote, braces or parenthesis
- It highlights pairs of brackets/parentheses
What is the benefit of using single quotes in JavaScript?
Values within single quotes can be compared with equals, equals equals, numeric comparisons and more.
What functionalities does the Context-sensitive Help provide?
- Displays a list of valid elements at the cursor’s current position
- Lists methods for a class
- Lists expected parameters
How do you display valid elements at the cursor’s current position within the Syntax Editor?
CTRL + Spacebar at the beginning of a line
How do you view a list of methods for a class within the Syntax Editor?
Type a period after the class name
How do you view a list of expected parameters for a class or method?
Type open parenthesis after a valid class, function or method name.
If you create custom objects, does the Syntax Editor provide any suggestions for variables belonging to the object?
Yes, if you type a period after the object, it will suggest variables belonging to the object.
What options are presented when you right click on bold/italicized text within the Syntax Editor?
The context menu:
- Show definition
- Show data
- Find references
How do you find a list of other places an object is used from within Syntax Editor?
Right click on the context menu and click ‘Find references.’
What is an alternative method of adding commments to manually typing forward slashes?
- Highlight applicable text
- Click the “Toggle Comment” button in the bar at the top of the Syntax Editor.
True or false: “Replace all” asks for confirmation before making the replacement(s)?
False. It does not.
What contains shortcuts for commonly used code?
The Syntax Editor Macros
How do you insert a Syntax Editor macro into your code?
Type the macro name and press tab.
How do you find the full list of Syntax Editor macros within the editor?
Type “help” and press tab.
What can the Syntax Editor “Syntax Checker” find?
- Missing characters, such as { and [
- Missing ; at the end of statements
- Incomplete arguments in for loops
- Bad function calls
What is the Syntax Editor “Syntax Checker” not able to find?
Typos, in:
- variable names
- function calls
- method calls
What do red circles indicate in Syntax Editor? Orange?
- Red: Errors
- Orange: Warnings
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
How do you view all configuration changes made to a table?
Type the table name in the Filter Navigator and append with .config
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
What does it mean if the “Global” checkbox is checked on a client script?
The client script can be used on all views
When is an “onLoad” client script run?
On load BEFORE control is given to the user.
When is the “onSubmit” client script run?
When the form is saved, submitted or updated (when a button is clicked)
What are “onSubmit” client scripts typically used for?
Field validation
What is the purpose of an “onChange” client script?
- Respond to field values of interest
- Modify one field value in response to another
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.
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.
What is the purpose of the GlideForm API?
- Customizing forms
- Managing form fields and their data
Which value, server or form, does g_form.getValue() retrieve?
Value selected on form
When g_form.getValue() is called against a string field, what is returned?
The string field as it appears on the form
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.
What functionality does the GlideUser API provide?
Methods to access informationa bout the currently logged in user.
What scope does the GlideUser API belong to?
Global
Which debugging method is suggested for catching runtime errors?
Try/catch
How are views input on the client script record?
Comma separated list
In what order to client scripts run if they have the same value in the “order” field?
Either by created by or the sys ID with the lower hexadecimal value.
What causes a GlideRecord query to execute the query?
gr.query();
How would you check if a GlideRecord query has another record?
if(myObj.hasNext()) {}
How do you add an OR condition to a GlideRecord query?
- Create the GlideRecord object
- Create a new variable and assign your addQuery to it
- 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’);
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);
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
How do you use getRowCount?
After .query(), assign gr.getRowCount() to a new variable.