Вы находитесь на странице: 1из 413

ServiceNOW Tutorial

01 Developer platform introduction - Module 1 - Platform basics

Introduction to an instance
Learn about the main sections of the ServiceNow UI.

The ServiceNow UI has four main sections:

Banner
Application navigator
Content
The Edge

Figure 1. ServiceNow user interface


The banner contains the logo and global navigation controls. Some controls require permission to use. For example, only system administrators can
impersonate a user.

The banner has the following components:

Global search: Search for text in all ServiceNow applications


Impersonate a user: Lets system administrators view the UI (for example, lists and forms) as the selected user. Impersonating is useful when testing
permissions or customizing the UI for a users role.
Elevated security: Lets system administrators apply the admin security role for the current session. Some features require this role.
Log out: Log out of the instance.
Gear icon: Let users define their system preferences.

The application navigator provides access to all ServiceNow modules and applications.
Figure 2. Application navigator

Users only see applications they are authorized to use. The system administrator role used to develop applications can see all applications and modules.
Selecting a module opens the page, list, or form in the content frame. You can use either the filter or mark favorites to quickly locate applications and
modules. When you use a module it is marked as a favorite. Click the star to toggle favorite status on and off. Click the star next to the filter to show all your
favorites in the navigator.

The content frame displays the page that is selected in the application navigator, for example:

Homepage widgets
Lists that display records in a table
Forms that display a single record
Service catalog of items that can be ordered
The Live Feed social application with posts and other shared content
Knowledge base articles
ServiceNow basics
Learn how to perform basic tasks in the ServiceNow application.

In a series of exercises, you will practice the following basic tasks:

Impersonating a user
Using the Edge
Navigating
Configuring and personalizing
Searching

To perform these exercises, log in to the developer site and access your developer instance, or log in to another instance where you have admin access.

Exercise 1: Impersonate a user


In this exercise you will impersonate a user. Impersonating a user is useful to test changes to a users role.

Ensure that you are logged in as the system administrator. You do not need the users password to impersonate.

In this exercise, you will impersonate a user named Abel Tuter.

1. Click the Impersonate User icon in the banner.


2. Enter Abel in the search field and press Enter.
Abel Tuter appears in the search box.
3. Click OK.
The application navigator displays the modules and applications to which Abels role has access.
4. Return to the administrator role by impersonating the System Administrator.
Use the Edge
The Edge contains a number of functions.

Toggle Navigator: shows or hides the application navigator


List and Form View: splits the content frame into two panes (the list pane on the left and the form pane on the right)
Tagged documents: displays the Tagged Documents page
All bookmarks: displays a list of all bookmarks in the Edge
Home displays the users home page, which varies depending on role

Adding and removing bookmarks


Adding elements that you work with frequently improves your eciency in ServiceNow. To add bookmarks, drag applications, modules, filters, lists, forms and
pages to the Edge. The exact form, list, or record that you dragged to the Edge is opened when you click the bookmark.

To remove a bookmark, hover over the bookmark and click Edit Bookmark, then click Delete.

Using flyouts
Flyouts open forms, lists, and other pages in a pop-up window without closing the pane in which you are currently working. Flyouts are useful for testing
changes when you are developing an application. Click away from the flyout window in an active pane to close the flyout.

Figure 1. Flyout window


You can configure a flyout by hovering over the bookmark and clicking Edit Bookmark, and then selecting the Flyout check box. To open a bookmark in a
flyout when it is not configured to be a flyout, use Cmd+click (Mac) or Ctrl+click (Windows).

Exercise 2: Use favorites and bookmarks


In this exercise you will use favorites and bookmarks to quickly return to places that you frequently access.

Favorites are marked in the application navigator with a blue star . In this exercise, you will create and access a favorite page and learn how to use
the Edge to set bookmarks.

1. Navigate to Incident > Create New and click the blue star.
Create New is marked as a favorite.
2. Clear the application navigator filter text box.
3. Click the blue star to the left of the filter text box.

The list refreshes with the modules and associated applications that are marked as a favorite.
4. Drag Create New to the Edge and drop it.
Incident > Create New is added to the Edge as a bookmark.
5. Configure the Create New bookmark on the Edge.
1. Hover over the bookmark until the Edit Bookmark pop-up appears.
2. Click Edit Bookmark.
3. Change the title to Create New.
4. Click Image, select a new image, and click Update.
5. Click Update.
6. Add Incident > Open to the Edge.
7. Click Toggle Navigator at the top of the Edge to hide the application navigator.

8. Edit the Incidents > Open bookmark to make it a flyout and add the word Flyout to the title.
When you click a flyout bookmark the list or form opens in a pop-up.
9. Use the bookmarks you created on the Edge to switch between the Create New Incident form and the Open Incident list.

Work with lists


Lists display information from a data table. Users can search, sort, filter, and edit data in lists. Lists also may be embedded in forms and may be hierarchical
(have sublists).

Editing table fields directly inline

In most tables, you can double-click a field to edit its value directly without having to navigate to a form. Administrators can define which tables and columns are
editable in the list editor. Some field types are never editable inline. For more information, see Administering the List Editor.

Figure 1. Editing a field value


Opening and editing records

Click the underlined value in the first column or the info icon to open a record.

Note: Other underlined fields are references to other tables. Click those values to open the associated record. For example, click the name listed in
the Callercolumn to open the user record.

You can also select multiple records and edit them to, for example, change several resolved issues to closed status.

Sorting records
Click a column label to sort the records in descending order. Click the label again to sort in ascending order. The blue up or down arrow indicates the current
sort field and order.

Configuring and personalizing lists

Lists can be configured for all users or personalized by the current user.

To configure, right-click in the column header and select Configure > List Layout.
To personalize, click the gear icon in the top left.

Searching lists

The Go to search above the list lets you select a field and a string to search for. Wild cards include:

Contains: *mySearchString
Starts with: mySearchString
Ends with: %mySearchString
Does not contain: !*mySearchString
Equals: =mySearchString
Does not equal: !=mySearchString

Figure 2. Search with wild card

Using filters and breadcrumbs


Click the Show/hide filter icon above the column labels to open the condition builder. You can modify the existing conditions or add conditions using
the ANDand OR buttons. AND means all conditions must be met for a record to be returned. OR means either condition may be met for a record to be returned.

When you run the filter, the condition builder collapses automatically. To keep it open, click the pushpin button before you click Run.

Figure 3. Pushpin button

The breadcrumb is updated to show the conditions, and the list refreshes with matching records. Remove a condition by clicking > next to the condition .

Searching by column

Right-click in any cell to show matching values or to filter out the value. Date fields also let youShow Before and Show After. Alternatively, you can click the
looking glass icon to open the column search fields.

Figure 4. Search by columns and right-click menu


Exercise 3: Search and filter
In this exercise you will search for records and add conditions to filter the results.

1. Navigate to Incident > Open.


2. Search for open incidents containing the string *down.
Note: An asterisk (*) in front of the string employs the contains wild card. Typing downwithout an asterisk returns results that are >=down.
1. From the Go to choice list, select Short description.
2. Enter *down in the text box.
Note: The search is not case-sensitive.
3. Press Enter.
3. Click the Show/hide filter icon to the left of the breadcrumb.
The condition builder opens.
4. Add a condition.
1. Click AND in the [Short description] condition.
2. Configure the new condition as follows: [State] [is not] [New].
3. Click Run.
5. The list refreshes with the matching incidents. The breadcrumb shows all conditions that are in the filter.
6. Click > to the left of the [Short description] condition in the breadcrumb to remove it.

The list refreshes with incidents that match the updated filter.

Exercise 4: Personalize a list for the current user


In this exercise you will configure the columns that display for you in a list.

You are personalizing the Incident > Open list, the same list as in the previous exercise.

1. If not already viewing the Incident > Open list, navigate to it.
2. Click the gear icon above the list on the left.
Figure 1. Gear icon location
3. Select Updated from the Available list and click Add .
Updated appears in the Selected list.

4. Re-order columns by selecting a column in the Selected list and clicking Move up orMove down .
5. Click OK.
The gear icon changes slightly to indicate that the list is personalized.

Exercise 5: Sort a list


In this exercise you will sort a list by column.

Continue to use the Incident > Open list for this exercise.

1. If not already viewing the Incident > Open list, navigate to it.
2. Click the Updated column header to sort the list by date of the last update.
The column name changes to blue and the list refreshes with the most recently updated incidents at the top.
3. Click the Updated column again.
The list refreshes with oldest updated incidents at the top.
Forms
A form displays information from one record in a data table. The specific information depends on the type of record displayed. Users can view and edit records
in forms. Administrators can customize forms.

Required fields are marked red with an asterisk (*). Users with permission can edit fields.

Figure 1. ServiceNow problem form


When you create or modify data in a form, your options for updating the database include:
Submit: Create a record and return to the previous page
Figure 2. Submit the form

Update: Update the record and return to the previous page


Figure 3. Update the form

Save: Update the record and stay on the current page. Click Save in the header or right-click in the header and click Save.
Figure 4. Save the form

Configuring forms

Forms cannot be personalized by an individual user. However, you can give different functions to different groups who use the same form. For example, end
users report issues in the incident form and IT team members work on the issues. The incident form is different for each group.

Configuring forms will be covered in more depth in Module 4: Customizing the user interface.
01 Developer platform introduction - Module 2 - Creating applications

Application creator
Use the application creator to start building your application.

The application creator creates the project space that tracks and contains all of your application artifacts, from table definitions and scripts to UI layouts and
reference data. Unlike traditional development environments such as Eclipse, ServiceNow does not store artifacts in files on disk. Instead, everything (even a
binary graphic) is stored as rows in tables. While you are developing an application, you will be adding new tables and modifying or extending existing tables in
many places throughout the platform. It is the application creators job to keep track of all these changes for you, and bundle them all up into a single zip file
when you are ready to publish your application.

The application creator has changed significantly in the Fuji release. It provides the ability to build applications from scratch, from a basic template, or from a
predefined template. It is recommended that you use the application creator to build applications.

This overview describes what the application creator does. Later in this course you will use the application creator to build an application in your own instance.

Figure 1. Application creator menu


The application creator has these options:

Start from Scratch: Nothing is predefined. You must define the application tables, menu, and access controls.
Create custom application: A table, menu, and access controls are provided as a place to start building the application.
Start from a template: Choose from a set of predefined templates for common enterprise applications. Many underlying ITIL business processes are
prebuilt in these templates; you can customize them as needed.

Note: To start from a template, you must activate a plugin. Click the Requires plugin activationbutton and follow the instructions in the linked help topic.

The Create custom application option is used for the examples below.

Figure 2. Create Application form


You are only required to name your application. A value is automatically provided for the Scopefield. The application name establishes the defaults for the rest
of the form.

Note: When Create Table is enabled, the platform automatically generates a basic table and enters a name that is derived from your application name.

After the application finishes building, you see the following screen:

Figure 3. Successful application creation


To return to your application later, navigate to System Applications > Applications, locate the previously created application, and click Edit.

Figure 4. Returning to your application

You can also access an application by clicking the gear icon in the upper right corner, selecting the application, and clicking the Show Selected
Applicationicon next to the application name.

The Custom Application detail page contains several important fields:

Scope: The namespace for the application that lets the system avoid conflicts with other applications and allows for public and private elements of the
application. This is automatically provided and should not be changed.
Menu: The header that shows in the application navigator on the left.
User role: Establishes a default user role for the application. Only logged-in users with the specified role may access the application.

Note: While it is possible to build an application in the global scope, it is highly discouraged for the following reasons:

You lose the ability to define public and private elements


Deployments to other instances become more complicated
You cannot list your application in the ServiceNow Store.

Always use application scoping unless you have a use-case that explicitly precludes using it.

The Custom Application form is your projects workspace that contains all associated artifacts. From here you can add tables, additional roles, application menu
items, application files, and dependencies.

Figure 5. Custom application details


Publish to Update Set is an important action that lets you save your work locally and optionally import it into another instance. Selecting this action creates an
update set that can be exported to XML and then imported into another ServiceNow instance.

Figure 6. Create update set


For more information about creating applications, see Applications on the ServiceNow Wiki.
Exercise 6: Create an application
In this exercise you will create a new application.

Log in to the developer site and access your developer instance or another instance where you have administrator access.

1. Navigate to System Applications > Applications.


2. Click New.
The Getting started building applications home appears.
3. Next to Start from scratch, click Create.
The Create Application from Scratch form opens.
4. Enter the name Marketing Events Application.
The Scope field is populated automatically.
5. Click Create and click OK to confirm that you want to create the application.
Figure 1. Confirm application
The Marketing Events Application is created and the Application Creation: Successwindow appears.

Note: When you create an application, the Application Creator creates a new role (called u_marketing_events_application_user) that you can assign to
users who need access to this application.
6. Click View app record.
The Marketing Events Application opens.
Figure 2. Marketing Events Application
You now have the foundation of the application that you will build out during the rest of the course.

Exercise 7: Publish custom applications


In this exercise you publish your custom application to an XML file, which packages all the artifacts related to the application and allows you to move it
betweenServiceNow instances. You then add your application to a separate instance.

When creating a custom application, ServiceNow stores all application artifacts in a specially-formatted XML document that can be imported into
another ServiceNowinstance. When you want to move applications from one ServiceNow instance to another, you need to publish the application.
Publishing the application packages all artifacts related to the application into an update set. An update set is an XML file that can be imported into the
otherServiceNow instance. That process is called applying the update set.

Publishing the application to an update set

1. Navigate to System Applications > Applications.


2. Select your custom application.
3. Under Related Links, click Publish to Update Set.
4. Enter the application name, version, and description.
5. Click Publish.
6. When a success message appears in the Progress window, click Done.
Now that you have a published application, you can export its update set and move it to another ServiceNow instance.
7. Under Related Links, click Export to XML and save the file to your computer.

Provide your custom application to another instance by applying the update set to it

8. Log into another instance.


9. Navigate to System Update Sets > Retrieved Update Sets.
10. Under Related Links, click Import Update Set from XML.
11. Browse for the update set that contains your application and click Upload.
ServiceNow processes the update set.
12. Click Preview Update Set.
Preview allows you to validate the contents of the update set in the new instance. If there are conflicts that cause errors, you must decide how to handle
them.
13. Do one of the following actions.

Option Description

If there are errors Examine each error in the Update Set Preview Problems list, and accept or skip the update responsible for it.

If there are no errors Click Commit Update Set.

Note: You can resolve conflicts row by row, using the Available Actions field, or you can select multiple rows and make a group decision via the Actions on
selected rows choice list. After resolving all errors, click Commit Update Set.
14. From the application navigator, select Refresh.
15. Navigate to the Marketing Events Application and check the application.

Note: If you are familiar with older versions of ServiceNow, you may want to use traditional update sets (customizations made outside the context of a custom
application) to publish applications. However, this is not possible, because custom application update sets bundle artifacts differently. Always use the technique
from this exercise to create custom application update sets.

Exercise 8: Back out an update set


In this exercise you will back out an update set to to reverse both record-level updates and changes to the dictionary.

When you delete an update record, only the record of the update is deleted. The update is not backed out of the environment. If you have committed an update
set that you do not want to keep in your environment, you have to back out the update set. Backing out either reverts to the previous settings or drops new
fields and tables from the database and deletes new scripts.

Note: Only update sets with state = Complete can be backed out.

1. Navigate to System Update Sets > Local Update Sets.


2. Open the name of the update set record to back out.
3. Click Back Out.
Note:

You may need to scroll up to see the Back Out button. It is above Related Links.
If a warning message indicates the update set does not belong to the current application specified in your Application Picker, switch to the correct
application from the link in the warning message.
After an update set is backed out, it is safe to delete it.
01 Developer platform introduction - Module 3 - Tables, references, and
inheritance

Exercise 9: Create a table


In this exercise you will create a new table, the Marketing Event table, for the Marketing Events Application.

1. From the Marketing Events Application, scroll to the Tables section and click New.
2. Enter Marketing Event in the Label field.
The Name field populates automatically, based on the label and application name.
3. Create the columns for the table, using the following information.

Column label Type Display

Name String true

City Choice false

Start Date Date false

End Date Date false


Budget Currency false

Sponsor String false

1. Double-click Insert a new row.

2. Enter a column label and click the checkmark.


3. Double-click the space under Type, enter a type, and click the checkmark.
4. Double-click the space under Display, set to either true or false, and click the checkmark.
Note: When you set Display to true for Name, the user-friendly value for the event name displays, rather than the unique system-generated ID number.
The generated ID is used by the system when a record references a marketing event.
4. Click Submit.

You can navigate to your new table by performing any of the following options.

Enter the URL in a browser: https://<yourinstancename&gt;.service-now.com/<u_tablename>_list.do


Search in the application navigator by typing <table name>.list.
If you created a module for the table, find the module in the application navigator and click the table name.
Extending tables
Decide whether to extend an existing table or create a new table.
Figure 1. Extending tables

Deciding whether or not to base your application on an existing ServiceNow table is an important decision. If you extend an existing table, you inherit the built-in
functionality of the base table. If you create a new table, you can script and configure all of the application behaviors.

You can extend any extensible table in the base system. Many custom IT applications extend the task table because it has many task-related fields, such
as Additional Comments, Approval History, Escalation, Priority, Watch List, and so on. The Task table also uses common business processes such as
approvals, journaling, assignment, inactivity monitors, and service level agreements. If your custom application needs these features, extend the Task table and
add custom fields to it.

Note: Do not change the base system Task table. Extend it by creating a new table that extends from the Task table.

Create a new table if your application is not related to tasks. New tables are created with a default set of required fields and have no pre-defined business rules,
access control lists (ACLs), or workflow logic. After creating a custom table, you can add new columns, business rules, and ACLs at any time.

Note: If your application needs to extend your custom table, check the Extensible check box when you create it. If you dont check it when you create it, you can
make it extensible later.
An application can use multiple tables, including:
Base table that contains the primary application records
Reference or lookup tables

Use the following to help you decide whether you need to extend an existing table.

Table 1. Extend an existing table?

Scenario Extend Create new

A table exists with fields similar to what is needed X -

No similar table exists - X

Table will contain sample or seeded data that is used only for reference by the application - X

The scripts and workflow for an existing table are useful X -

You prefer to script the application behaviors - X

You want to use the approval workflow activities X -

Note: The user approval workflow activity works with all tables. All other approval activities work only with tables that are extended from Task.

Exercise 10: Extend a table


In this exercise you will create a new table, the Equipment Request table, by extending the Task table. Extending a table allows you to take advantage of the
built-in columns and processes of theServiceNow base system.

1. From the Marketing Event Application, scroll to the Tables section and click New.
2. Enter Equipment Request in the Label field.
The Name field is filled in automatically, based on the label and application name.

3. In the Extends table field, select Task.


4. In the Add module to menu field, select Marketing Event.
5. Create the table rows, using the following information.

Column lab Type Reference Display

Type String true

Cost Currency false


Needed From Date false

Needed Until Date false

Marketing Event Reference Marketing Event false

Note: The Marketing Event field is a reference to the Marketing Event table. A reference field creates a relationship between two tables and allows you to
display information from another table. It is similar to the primary and foreign keys in a relational database. In this case, a particular piece of equipment is
related to a particular marketing event.
6. Click Submit.

Reference fields
Reference fields store a reference to a specific row in another table, similar to foreign keys in SQL.

An example of a reference field is the Caller field on the Incident table, which is a reference to a specific user in the [sys_user] table.

Users dont need to understand foreign keys or SQL joins to query reference fields. If a table contains a reference to another table, any field on the referenced
table can be accessed using dot-walking. For example, incident.caller references the name of the user who opened the incident. Dot-walking can be chained
several levels deep, for example, incident.caller.company references the company name of the caller who opened the incident.

Administrators can create new reference fields and configure several options for reference fields, including:

The display value


Auto-complete behavior
Reference qualifiers
Cascade delete rules
For more information, from the ServiceNow wiki:
Reference fields
Dot-walking

Exercise 11: Query reference field by dot-walking from UI


In this exercise you will query a reference field by dot-walking from the UI. Dot-walking is an object-oriented approach to data access that you can use with any
table search.

As a developer, you are already familiar with foreign keys and SQL joins used to reference rows in a related table. ServiceNow makes it easy for end-users to
query related tables without needing to know SQL syntax.

Incident table rows contain a field named Caller, which is a reference to the user [sys_user] table. You can search the incident table for all incidents created by
callers who work in the sales department:

1. Navigate to Incident > All.


A list of incidents appears.
2. Click the Show/hide filter icon .
The condition builder opens.
3. Build the condition [Caller.Department] [is] [Sales].
1. Click the choose field list, scroll to the bottom, and select Show Related Fields.
The choose field list changes to Keywords.
2. Click the Keywords list and select Caller > User fields.
The Keywords list changes to Caller >> User fields
3. Click the Caller >> User fields list and select Department.
4. Type Sales in the textbox.
As you type in the textbox, choices of department names appear.
4. Click Run.
The table refreshes to show only incidents whose caller is in the sales department.
Differentiating between reference fields and choice lists
Knowing the difference between reference fields and choice lists is important when developing forServiceNow. Both types of field can look very similar, and
optionally appear as popup menus in the user interface, so end users may not immediately know the difference.

The following table highlights differences between reference fields and choice lists:

Reference field Choice list

Reference fields store a reference to a row on another table. For Choice lists present the user with a list of pre-defined choices. Administrators
example, the Caller field on the Incident table is a reference to the User can define the available choices and customize the behavior and appearance of
[sys_user] table. choice lists.

Referenced tables often have many rows Choice lists have a small number of items

Referenced objects can contain a lot of other fields to store information Choice list items contain a friendly name and a value used for scripting

Referenced tables are often updated Choice lists are rarely updated

End users can add rows to referenced tables Only administrators can change choice lists

Choices contain both a friendly label, such as Top Priority, and a value, such as P1, that is used for scripting. This makes it possible to change labels without
having to modify your script code that references the choice field.

Because ServiceNow stores all choice lists in the [sys_choice] table, you can write script code to modify choice lists or import new choices from external data
sources. For a complete reference on managing lists, see Customizing Choice Lists on the ServiceNow Wiki.

For a tutorial on choice list best practices, including an example of re-using a single choice list in multiple places, see https://www.youtube.com/watch?v=I-m-
egREJ5M
Exercise 12: Modify inherited choice list
In this exercise you will build on the Marketing Events application and customize the Choice list that was inherited from the Task table to add a new choice and
remove unneeded choices.

1. Navigate to Marketing Events Application > Equipment Requests.


A list of equipment request records appears, if there are any in the table.
2. Click New.
An Equipment Request form appears.

Note: The choices found in the State list are inherited from Task. When rendering the list, the platform uses rows from Choice[sys_choice] that are
associated with Task and are global to all other tables that extend from Task. In the next steps, you will create a new custom set of choices.
3. Right-click State and select Configure Choices.
A choice list editor appears.
4. Enter the following information and click Add.

Field Value

New item On Loan


text

Numeric 10
Value
Note: A value of 10 is important because that value is not already used by the platform and will not interfere with business rules in the
base system.

On Loan appears in the Selected list.


5. Click Closed Skipped and click Remove.
Closed Skipped moves to the Available list and does not show in the Choice list.
6. Click Closed Incomplete and click Remove.
Closed Incomplete is moved to the Available list and does not show in the Choice list.
7. Click Save.
The State list now contains a new choice that is not inherited from the parent task table and omits two choices that were. When you configure a choice list,
the platform makes a copy of all the choices [sys_choice] rows from the parent tables choice list. The duplicated rows in the sys_choice table are now
unique to your extended table, and any changes you make only affect your extended table, not the parent task table.

01 Developer platform introduction - Module 4 - Customizing the user


interface

Exercise 13: Configure list layout


In this exercise you will configure the columns that appear for all users of the Marketing Events list.

1. Navigate to Marketing Event > Marketing Events.


2. Right-click the column heading and select Configure > List Layout.
3. Use the Move up and Move down arrows to arrange the column headers in the Selected list in the following order: Name, City, Budget, Sponsor, Start Date,
and End Date.
4. Click Save.
5. Click New.
A form appears. You will configure the form in the next exercise.

Forms designer
The ServiceNow graphical forms designer allows you to design and lay out interactive table editor forms with fields from a master table row and lists from
related tables.

Figure 1. Forms designer


The ServiceNow system handles the details of browser support, mobile support, and CSS and table layouts, so you dont have to write HTML code. The form
designer lets you add, modify, create, or delete fields, views, and tabbed sections by dragging and dropping.

You create logic with UI policies to dynamically show and hide fields in forms. It is also easy to add related list tables to a form, so that users can review and edit
one-to-many relationships to the main table row they are editing in the form. You will learn about these features later in this module.

See the product documentation on Form Design for more information.

Note: The form design feature is available by default for new ServiceNow instances. For upgraded ServiceNow instances, ask a system administrator to
activate the NG form designer plugin (com.glide.ui.ng.fd) to access the feature.

Exercise 14: Configure form layout


In this exercise you will configure the Marketing Events form.

1. Right-click the title bar of the Marketing Events form and select Configure > Form Design.
2. Drag and drop the items in the order you want them to appear.
3. Add city values.
1. Hover over the City field and click the gear icon.
2. In the Properties dialog box, click Create choices.
3. For Choice 1, 2, and 3, enter Dallas, Kansas City, and London.
4. Click in the empty row and create new entries for San Jose, Portland, andSydney.
5. Close the Properties dialog box.
4. Make the Name field mandatory.
1. Hover over the Name field and click the gear icon.
2. Select the Mandatory check box.
3. Close the Properties dialog box.
5. Click Save.
6. On the Marketing Event form, right-click the title bar, and select Reload form.

Exercise 15: Configure a related list


In this exercise you will add a related list so that you can see events and equipment requests on the same page.

A form can display records from other tables that are related to the main record.

1. Navigate to Marketing Events Application > Marketing Events.


2. Click New.
3. Right-click the header of the event and select Configure > Related Lists.
4. From the Available list, double-click the Equipment Request > Marketing Event list.
You can also add the Attachments related list. This is a built-in functionality that allows you to add a file, document, or image to a record.
5. Click Save.
The related Equipments Requests now appear at the bottom of the form.
Exercise 16: Configure list control
In this exercise you will configure list control to hide the New button (which prevents users of the Marketing Events Application from creating new records) and
allow users to double-click a related list to add an entry.

Many of the behaviors of related lists are configurable. The following list describes some configurations, but there are many more.

Remove the New button to prevent users from creating new rows in the related table
Hide empty columns
Hide the entire list if its empty
Enable grid editing, so that new rows can be created with a double-click

1. Navigate to Marketing Events Application > Marketing Events.


2. Click New.
The Marketing Events form opens.
3. Enter a name for the new event in the Name field.
4. Right-click the header and click Save.
Note: This step is very important; if you dont save the record, the related list does not appear in later steps.
5. Right-click any column heading and select Configure > List Control.
The list control form appears.
6. Select the Omit new button and List edit insert row check boxes.
7. Click Submit.
The Marketing Events form reopens. The New button no longer displays in the header and the related list displays Insert a new row, which allows users to
double-click the row to add an entry.

Exercise 17: Work with modules


Modules are convenient links under your application menu. They can link to different kinds of features, such as filtered lists, record-creation forms, reports,
surveys, and much more. In this exercise you will create modules for the Marketing Events application from the previous exercise.

1. In the application navigator, right-click the Marketing Events Application and select Edit Application Menu.
2. Scroll to the Modules section and click the Equipment Requests module.
1. Change the Title to All Equipment Requests.
2. In Hint, enter List of all Equipment Request records in the database.
3. Click Update.
The module name changes under Marketing Events in the application navigator.
4. To add a module, scroll to the Modules related list and click New.
5. Configure the new module as follows:

Option Description

Title Enter New Equipment Requests

Application menu Defaults to Marketing Events; leave as is

Hint Enter a hint of your choice

Roles Click the icon and select x_<your scope>_marketing_events_user

Link type Select New Record

Table Select Equipment Request [x_<your scope>_equipment_request]

6. Click Submit.
7. Add another module to display only open Equipment Request records.
Be sure to enter a descriptive hint and set the filter appropriately so that only rows whose [State] [is not] [Closed Complete] are shown.
8. Use the Order field in the Modules related list to display the modules in this order: Marketing Events, New Equipment Request, All Equipment Requests,
and Open Equipment Requests.
Number the modules 100, 200, 300, and 400.
UI policies
UI policies are client-side logic that governs field behavior and visibility on forms.

ServiceNow automatically generates client-side Javascript that the browser executes to enforce policies on the form being displayed. Each policy has a
condition that must resolve as true to be executed. Policies determine the following field attributes and behaviors:

Make the field mandatory


Show or hide the field
Make the field read-only

Most basic UI policies are declarative and do not require scripting. You may also write your own scripts to handle more complex scenarios.

In the example below, no scripting was required to:

Make the Number field read-only


Make the Configuration item field mandatory
Hide the Priority field

Figure 1. Before and after UI policy applied


Note: Another client-side script within ServiceNow, called a client script, can also be used to hide/show fields and make fields mandatory. For faster load times,
use a UI policy instead of a client script when the only purpose of the script is to set a field to show/hide, read/write, or mandatory/optional.

Exercise 18: Create a UI policy


In this exercise you will create a UI policy on the Incident form.

The UI policy you create for the Incident form does the following when the incident state changes to Resolved.

Make the Location field mandatory.


Hide the Assigned to field.
Make the Category field read-only.
Run a client script that displays an alert message.
1. Navigate to System UI > UI Policies.
2. Click New.
3. Configure the UI poicy as follows:

Option Description

Table Select Incident

Short description Enter Hide "Assigned to" when resolved

Conditions Select [State] [is] [Resolved]

Reverse if false Select this check box. The UI policy is reversed if the incident state is not Resolved.

On load Select this check box to perform the actions when the form is loaded or when the condition changes.

4. Right-click in the header bar and click Save from the context menu.
The UI Policy Hide Assigned to when resolved list appears.
5. Scroll to the UI Policy Actions section and click New.
6. Make the following selections.

Option Description

Field name Select Assigned to

Mandatory Select Leave alone

Visible Select False


Read only Select Leave alone

7. Click Submit.
A new row appears in the related list.
8. Repeat steps 5 to 7 twice to configure each of the following UI policy actions.

Option Description

Location Select Mandatory

Category Select Read only

9. Click the Script tab.


10. In the Run scripts check box that appears, check the box.
Two script editors appear.
11. In the Execute if true script, enter the following.

function onCondition() {
alert('You changed the "Incident state" to
Resolved. Note that location is now mandatory');
}

12. Click Update.


13. Try out the new policy.
1. Navigate to Incident > Open.
2. Open any active incident and change the state to Resolved.
3. Dismiss the alert box.
14. The Location field is marked as mandatory, the Category field is read-only, and theAssigned to field disappears.
02 Integrating with ServiceNow - Module 1 - Importing legacy data

Supported import formats


You can import data from a file or remote location if it is one of five formats.

Table 1. Supported input formats

Import format Description

CSV Imports data from a character-separated values file, such as a comma-separated or tab-separated file.

XLS Imports data from Microsoft Excel spreadsheets at versions 2003 and older.

Note: The import process does not support the XLSX file format for Excel versions 2007 and newer.

XML Imports data from an extensible markup language file, such as records exported from another instance.

JDBC Imports data from a compatible database using a JDBC connector.

LDAP Imports data from a directory service, such as Active Directory.


Import vs. integrate
Developers use these guidelines to determine when to import and when integrate.

Table 1. Importing vs. integrating

Use case Recommendation

Migrate legacy data to an instance when that data is available in a supported Import the legacy data through import sets.
import format. Manage future updates fromServiceNow.

Synchronize data with an external application. Integrate with the external application.
Determine if the integration needs both inbound and outbound
communications.

Perform bulk updates containing many records. Import data to an import set.
Schedule transformation to reduce the performance impact.

Send externally generated records to an instance as the records are created Integrate with a synchronous web service.
or updated. Consider using the REST API if supported by the external
application.
Business requirements
Before you created the Marketing Event application, users tracked events and attendees with spreadsheets. Marketing event coordinators want to migrate this
legacy data to the Marketing Event application.

The event coordinators goals are to:

Replace legacy marketing event spreadsheets with application records


Replace legacy attendee spreadsheets with application records
Ensure there are no duplicate marketing events or attendees records

You can meet these goals by using import sets for the bulk import of legacy data and a transform map to coalesce legacy and existing data.

Exercise 1: Create legacy data


Create a spreadsheet to simulate legacy data. The exercise illustrates both support for different file formats and the need to transform data before importing it.

1. Use a text editor to create a comma-separated values (CSV) file using this data.

Name,Location,Sponsor,Budget,Start Date,End Date


San Jose LUG,San Jose,SJC Partners,"$3,000",9-1-2014,9-8-2014
Portland LUG,Portland,OR Partners,"$1,000",4-1-2014,4-4-2014

2. Create an Excel (XLS) file using this data.


Name Company Email Event

Samuel Clemens SF Chronicle mark.twain@sfc.com San Jose LUG

Amanda Reed Reed College amanda.reed@reed.edu Portland LUG

Note: XLS is the Excel 97-2004 Workbook format. Do not use XLSX or Excel file format options.

Exercise 2: Import legacy marketing events


Import the legacy marketing events from the CSV file that you created in Exercise 1.

In this first section, you create a source table for the data in the CSV file and a transform map that specifies an existing target table.

1. Navigate to System Import Sets > Load Data.


2. Select Create table.
3. Enter these values.

Field Value

Label Legacy Marketing Events

Table name Populates automatically

Source of import File


File Choose file and select path to your CSV file

Sheet number 1

Header row 1

4. Click Submit.
The system displays a success message after importing the file.
5. Click Create transform map.
6. Enter these values.

Field Value

Name Legacy Marketing Events

Source table Legacy Marketing Events [x_snc_marketing_ev_legacy_marketing_event]

Target table Marketing Event [x_snc_marketing_ev_marketing_event]

In this section, you map legacy data field labels from the source table to existing field labels in the target table.

7. In Related Links, click Auto Map Matching Fields.


The instance adds the Field Maps related list.
8. In Related Links, click Mapping Assist.
Figure 1. Field mapping between two tables
9. From the Source: Legacy Marketing Events field list, drag and drop the Location field to the Field Map.
10. From the Target: Marketing Event field list, drag and drop the City field to the Field Mapso that it corresponds to the Location field.
11. Click Save.

In this next section, you specify the name of the marketing event as the unique key during the import. If a match is found, the existing record is updated. If not,
a new record is inserted.

12. From the Field Maps related list, double-click the Coalesce cell for the u_name source field.
13. Set the Coalesce value to true.
The system may display a message about indexing fields.
14. If there is an indexing message, select the options to index the table without notification.
In this last section, you specify the date format of the start and end dates, and then run the transformation to complete the import.

15. From the Field Maps related list, click u_end_date.


16. In Date format, click the Suggestion icon.
17. Click MM-dd-yyyy.
18. Click Update.
19. From the Field Maps related list, click u_start_date.
20. In Date format, click the Suggestion icon.
21. Click MM-dd-yyyy.
22. Click Update.
23. In the Related Links list, click Transform.
The system displays the import set and transform map to be used in the transform.
24. Click Transform.
The system imports the data into the Marketing Event table.

Exercise 3: Test legacy marketing events import


Verify that the legacy marketing event data was imported correctly.

Navigate to Marketing Event > Marketing Events.

Figure 1. Marketing events table with imported events


Note that there are legacy records for the Portland LUG and San Jose LUG with start and end dates from a previous year.

Exercise 4: Import legacy attendees


Import the legacy attendees from the Excel spreadsheet you created earlier in the module.
In this first section, you create a source table for the data in the XLS file and a transform map that specifies an existing target table.

Note: Source tables cannot be created from other Excel file formats, such as XLSX.

1. Navigate to System Import Sets > Load Data.


2. Select Create table.
3. Enter these values.

Field Value

Label Legacy Attendees

Table name Populates automatically

Source of import File

File Path to your XLS file

Sheet number 1

Header row 1

4. Click Submit.
The system displays a success message after importing the file.
5. Click Create transform map.
6. Enter these values.

Field Value

Name Legacy Attendees


Source table Legacy Attendees [x_snc_marketing_ev_legacy_attendees]

Target table Attendee [x_snc_marketing_ev_attendees]

In this middle section, you map legacy data field labels from the source table to existing field labels in the target table.

7. In Related Links, click Auto Map Matching Fields.


ServiceNow adds the Field Maps related list.
8. In Related Links, click Mapping Assist.
Figure 1. Field mapping between tables
9. From the Source: Legacy Attendees field list, drag and drop the Event field to the Field Map.
10. From the Target: Attendee field list, drag and drop the Marketing Event field to the Field Map so that it corresponds to the Event field.
11. Click Save.

In this section, you specify email address as the unique key during the import. If a match is found, the existing record is updated. If not, a new record is inserted.

12. From the Field Maps related list, double-click the Coalesce cell for the u_email source field.
13. Set the Coalesce value to true.
14. From the Field maps related list, click u_event.
15. For Referenced value field name, enter name.
16. Click Update.

In this last section, you create a transform script using a supplied codeblock and run the script to complete the import.
17. From the Transform Scripts related list, click New.
18. Enter these values.

Field Value

When onBefore

Script
//Convert source field to string
var name = source.u_name.toString();
//Split names anywhere there is a space
var split_names = name.split (" ");
//Find the number of names
var num_names = split_names.length;
//If there is only one name map it to the last name
if (num_names == 1) {
target.last_name = split_names[0];
}
//if there are two names map to first and last name
if (num_names == 2) {
target.first_name = split_names[0];
target.last_name = split_names[1];
}
//if there are more than 3 names combine into one middle name
if (num_names >= 3) {
target.first_name = split_names.shift();
target.last_name = split_names.pop();
var middle_name = split_names.join(" ");
}
19. Click Submit.
20. In the Related Links list, click Transform.
The system displays the import set and transform map to be used in the transform.
21. Click Transform.
The system imports the data from the Excel spreadsheet into the Attendees table.

Exercise 5: Test legacy attendees import


Verify that the legacy attendee data was imported correctly.

Navigate to Marketing Event > Attendees.

Figure 1. Attendees table with imported individuals


The records for Amanda Reed and Samuel Clemens imported correctly. Also, the Marketing Event column links to the legacy marketing events imported earlier.

Evaluation of the legacy data imports


Why the import sets and transform maps meet the business requirements of the Marketing Event users.

Table 1. Business requirement review


Requirement Met? Evaluation

Replace legacy marketing event spreadsheets Yes The import set table contains a copy of the
with application records original data.
Transform rules allow you to fix the data
format and input errors.

Replace legacy attendee spreadsheets with Yes The import set table contains a copy of the
application records original data.
Transform rules allow you to fix the data
format and input errors.

Ensure there are no duplicate marketing events Yes Coalescing on the email field and the name
or attendees field ensures there are no duplicate records.
Consider also coalescing on the marketing
event field when you transform the legacy
attendee data to allow the same person to
attend different events.

02 Integrating with ServiceNow - Module 2 - Inbound web services


Additional business requirements
The Marketing Event application is so successful that users from the sales department want to identify sales prospects with it.

Specifically, the sales department wants to:

Automatically create an attendee record from a sales prospect


Automatically update attendee details when a sales prospect changes
Automatically update attendee details when there is an existing attendee record

The sales department uses an external application to track sales prospects. This external application supports REST web services as well as exporting to CSV
text files.

Inbound web service options


Developers have four options for creating inbound web services.

Table 1. Supported inbound web services

Option Endpoint Features

Web services import sets Import set table, such as User[imp_user] Control when data imports into a target table by checking for conditions.
Control how data imports into a target table by applying field mappings.
Transform data by using a set of rules.
Keep a record of data imports for auditing.
Support REST and SOAP web services.
Support JSON, CSV, Excel, and XML as input formats.

Direct web services Production table, such as User [sys_user] Access any table without having to configure an endpoint.
Perform database operations directly on tables.
Support REST and SOAP web services.
Support JSONv2, CSV, Excel, XML, PDF, and RSS as output formats.

Scripted web services Production table, such as User [sys_user] Use JavaScript to define input and output parameters.
Specify an arbitrary endpoint URL.
Support XML output only.

ODBC Driver Production table, such as User [sys_user] Allows connections from an ODBC client.
Uses a query-only web services interface.

Exercise 6: Create an inbound web service


Create an inbound web service that accepts incoming REST messages and stores them in an import-staging table. Then create a transform map to convert
sales prospect records into attendee records.

In this section, you create the inbound web service and the import set table.

1. Navigate to System Web Services > Inbound > Create New.


2. Enter these field values.
Field Value

Label Add Attendees

Name x_snc_marketing_ev_add_attendees

Create transform map Selected

Target table Attendee [x_snc_marketing_ev_attendee]

3. From the Web Service Fields embedded list, double-click Insert a new row to enter these field values.

Label Name Length

Name u_name Default (40)

First name u_first_name Default (40)

Last name u_last_name Default (40)

Company u_company Default (40)

Email u_email Default (40)

Phone u_phone Default (40)

Marketing event u_marketing_event Default (40)


The Create Web Service form displays a row for each web service field you added.
Figure 1. Web service fields
4. Click Create.
The system creates the import set table Add Attendees [x_snc_marketing_ev_add_attendees] and then displays the Table Transform Map form.

In this section, you create a transform script from a supplied codeblock to import data from a source field that has no match in the field maps.

5. From Related Links, click Auto Map Matching Fields.


The system displays the Field Maps related list with a list of matching fields. Notice there is no field map for the u_name field.
Figure 2. Field Maps related list
6. From the Transform Scripts related list, click New.
7. Enter these fields values.
Field Value

When onBefore

Script
//Convert source field to string
var name = source.u_name.toString();

//Split names anywhere there is a space


var split_names = name.split (" ");

//Find the number of names


var num_names = split_names.length;

//If there is only one name map it to the last name


if (num_names == 1) {
target.last_name = split_names[0];
}

//if there are two names map to first and last name
if (num_names == 2) {
target.first_name = split_names[0];
target.last_name = split_names[1];
}

//if there are more than 3 names combine into one middle name
if (num_names >= 3) {
target.first_name = split_names.shift();
target.last_name = split_names.pop();
var middle_name = split_names.join(" ");
}
8. Click Submit.

REST API Explorer


The REST API Explorer uses information from your instance to provide you with a list of endpoints, methods, and variables that you can use to build and test
REST requests.

From the REST API Explorer, you can select and test the following REST APIs.

Table API
Retrieve records from a table (GET)
Create a record (POST)
Retrieve a record (GET)
Modify a record (PUT)
Delete a record (DELETE)
Update a record (PATCH)
Aggregate API
Retrieve statistical calculations for a table (GET)
Import Set API
Create a record in an Import Set staging table (POST)
Retrieve an Import Set record (GET)

All REST APIs give you the option to use the current users credentials or provide another users credentials. The REST API requires the following user roles.

rest_service
Table API
Aggregate API
import_admin
Import Set API
The REST API Explorer provides sample code to execute requests from external applications. It supports these code languages.

ServiceNow Script
cURL
Python
Ruby
JavaScript
Perl

For more information, see REST API Explorer.

Exercise 7: Insert attendee


Use the REST API Explorer to simulate sending a sales prospect record from an external application to your instance through a REST web service message.
This message inserts a new Attendee record.

1. Navigate to System Web Services > REST > REST API Explorer.
The system displays the REST API Explorer form and the Table API.

Note: If you receive a one-time message describing the REST API Explorer, click Explore.
Figure 1. REST API Explorer
2. From the API list in the left panel, select Import Set API.
The system displays information for Create a record in an Import Set staging table (POST).
3. In the Prepare request section, confirm these default values.
Field Value

Request Format JSON

Response Format JSON

Authorization Send as me

Note: As an admin user, you automatically have the user roles necessary to use REST services. If you want to use another users credentials, verify the
user has the rest_service and import_admin user roles. See Creating Users and Associating to a Group.
4. In the Path Parameters section, for stagingTableName, selectx_snc_marketing_ev_add_attendees.
5. In the Request Body section, enter these values.

Field Value

u_name John Ross Ewing

u_company Ewing Oil

u_email jr.ewing@ewingoil.com

u_marketing_event Dallas LUG

The fields and values you entered begin to build the request script dynamically.
6. At the bottom of the Request Body section, click [cURL].
The system displays a sample cURL command based on your entries so far.
Note: You can copy this code and modify it to call your instance with your user credentials.
Figure 2. Sample cURL command

7. Close the Code Sample.


8. Click Send.
9. In the confirmation dialog, click OK to modify data.

The system displays Request and Response sections. The Response section displays the Status Code201 Created.

Exercise 8: Verify attendee creation


Confirm that the REST web service message successfully created an Attendee record.
Navigate to Marketing Event > Attendees.

Figure 1. Attendees table with new record

There is a record for jr.ewing@ewingoil.com. The record extracted the First name and Last namefields from the full name provided in the REST request. Also,
theMarketing Event field for that record now references the Dallas LUG.
Exercise 9: Update attendee
Simulate sending a REST message because of a record change on an external application. The message changes the existing attendee record.

1. Navigate to System Web Services > REST > REST API Explorer.
The system displays the REST API Explorer form and the Table API.
2. From the API list in the left panel, select Import Set API.
The system displays information for Create a record in an Import Set staging table (POST).
3. In the Prepare request section, enter these values.

Field Value

Request Format JSON

Response Format JSON

Authorization Send as me

Note: As an admin user, you automatically have the user roles necessary to use REST services. If you want to use another users credentials, verify the
user has the rest_service and import_admin user roles. See Creating Users and Associating to a Group.
4. In the Path Parameters section, for stagingTableName, selectx_snc_marketing_ev_add_attendees.
5. In the Request Body section, enter these values.

Field Value

u_name J.R. Ewing

u_company Ewing Oil


u_email jr.ewing@ewingoil.com

u_marketing_event Dallas LUG

Note: Changing the value of the u_name field simulates the update to that record from the external system.
6. At the bottom of the Request Body section, click Send.
7. In the confirmation dialog, click OK to modify data.
8. The system displays Request and Response sections.

In the Response section, the Status Code reads 201 Created.

Exercise 10: Test the attendee update


Find out if the REST web service message successfully updated the existing attendee record.

1. Navigate to Marketing Event > Attendees.


There are two records with the email jr.ewing@ewingoil.com instead of one, and the first name of the new record is J.
Figure 1. Attendees table with update
2. Select the check box next to that new record.
3. From Actions on selected rows, select Delete.
4. In the confirmation dialog, click Delete.
Evaluation of the inbound web service
Currently, the Add Attendees inbound web service meets some, but not all, business requirements.

Table 1. Business requirement review

Requirement Met? Evaluation

Automatically create an attendee record from a sales Yes The inbound web service automatically runs the transform map to insert records.
prospect. The external application needs to know the endpoint URL and message format.

Automatically update attendee details when a sales Yes We could use the sample code provided by the REST API Explorer to create valid
prospect changes. REST messages from an external application.
The REST API Explorer also provides the proper format for inbound REST
messages.

Automatically update attendee details when there is No The transform map treats all valid REST message requests as inserts.
an existing attendee record. Need a mechanism to identify when a REST message updates an existing record.

Coalescing records
In the context of transform maps and import sets, to coalesce means to use one or more unique keys to determine if there is a matching record in a target
table.

If an import set record coalesces to an existing record, the system updates the matching record in the target table. If an import set record does not coalesce,
the system creates a new record in the target table.

Each transform map contains a Field Maps related list, and each field map contains a Coalescefield. Setting the Coalesce field to true indicates that this field
contains uniquely identifying information for the target record.

For example, in the baseline system there is a transform map for the User [sys_user] table that coalesces on the email field.

Figure 1. User table transform map


Whenever the system imports user records, it can check the email field for a matching value. If an incoming email address matches the email address of an
existing user record, the system updates the matching user record. If an incoming email address does not match any existing users email address, the
system creates a new user record with this email address.

For example, in the baseline system there is a user record for Abel Tuter with the email address abel.tuter@example.com.

Figure 2. Sample user record

Whenever a user import set record contains this email address, the system updates Abel Tuters user record with the other field values from the import set
record.

Some transform maps use multiple coalesce fields to indicate that unique information is spread across multiple fields. For example, what makes a marketing
event unique is the name and date of the event. So the Dallas LUG on May 15, 2015 is distinct from the same event on October 5, 2015, but is also distinct
from a New York LUG also on May 15, 2015. The combination of the name and date however, uniquely identifies the record.

Exercise 11: Update the add attendees transform map


Update the existing transform map to add a coalesce field.
1. Navigate to System Import Sets > Administration > Transform Maps.
2. Click Add Attendees.
3. From the Field Maps related list, double-click the Coalesce cell for the u_email field.
4. Change the value from false to true.
Figure 1. Changing a coalesce value on a field map

5. Click the green checkmark to save your change.


Exercise 12: Test the updated transform map
Find out whether coalescing on the email field allows the transform map to update an existing attendee record instead of creating a new one.

1. Navigate to System Web Services > REST > REST API Explorer.
The system displays the REST API Explorer form and the Table API.
2. From the API list in the left panel, select Import Set API.
The system displays information for Create a record in an Import Set staging table (POST).
3. In the Prepare request section, enter these values.

Field Value

Request Format JSON

Response Format JSON

Authorization Send as me

Note: As an admin user, you automatically have the user roles necessary to use REST services. If you want to use another users credentials, verify the
user has the rest_service and import_admin user roles.See Creating Users and Associating to a Group.
4. In the Path Parameters section, for stagingTableName, selectx_snc_marketing_ev_add_attendees.
5. In the Request Body section, enter these values.

Field Value

u_name J.R. Ewing

u_company Ewing Oil


u_email jr.ewing@ewingoil.com

u_marketing_event Dallas LUG

Note: Changing the value of the u_name field simulates the update to that record from the external system.
6. At the bottom of the Request Body section, click Send.
7. In the confirmation dialog, click OK to modify data.
The system displays Request and Response sections. In the Response, notice that theStatus Code reads 201 Created.
8. Navigate to Marketing Event > Attendees.
Figure 1. Updated attendees table
There is only one Attendee record for jr.ewing@ewingoil.com and the First name is now J.

Evaluation of the updated inbound web service


The Add Attendees inbound web service now meets all business requirements.

Table 1. Updated business requirements review

Requirement Met? Evaluation

Automatically create an attendee record from a Yes The inbound web service automatically runs
sales prospect. the transform map to insert records.
The external application needs to know the
endpoint URL and message format.

Automatically update attendee details when a Yes We could use the sample code provided by
sales prospect changes. the REST API Explorer to create valid REST
messages from an external application.
The REST API Explorer also provides the
proper format for inbound REST messages.

Automatically update attendee details when there Yes The transform map can identify import set
is an existing attendee record. records that match an existing attendee.
The transform map updates other field
values such as the name.
02 Integrating with ServiceNow - Module 3 - Outbound web services

New business requirements


The Marketing Event application is so successful that users from the sales department want to identify sales prospects with it.

Marketing events are a good place to find new sales prospects. The sales team would like to:

Identify marketing event attendees who are not already sales prospects.
Send attendee details to the external application whenever an attendee is added or changed.
Indicate an attendee record has been sent to the external application.

To accomplish these goals you will:

Add a sales prospect field to the Attendee [x_snc_marketing_ev_attendee] table.


Create a Sales Prospect table to simulate an external application.
Create a Synch Sales Prospects inbound web service to simulate the endpoint URL of an external application.
Create an outbound REST message to send sales prospect details to the external application.
Create an asynchronous business rule to create an outbound REST message whenever an attendee record is inserted or updated.

Exercise 13: Update the attendee table


Add a new sales prospect field to the Attendee table.

1. Navigate to Marketing Event > Attendees.


2. Open any record, such as fr.ewing@ewingoil.com.
3. Right-click the form header and select Configure > Form Design.
The system opens Form Design in a new tab.
4. Click the Field Types tab.
5. Drag a True/False field directly below the Marketing Event field.
Figure 1. Adding a new field to the attendees table

6. Click the new field and rename it Sales Prospect.


7. Click the gear icon next to the field name.
The system displays the Properties pop-up window for the new field.
Figure 2. Properties window for Sales Prospect field
8. Enter these values.

Field Value

Name sales_prospect

Default Cleared

Read Only Selected

9. Close the Properties pop-up window.


10. Click Save.
The system adds the new field to the Attendee table and form.
11. Close the Form Design tab.
12. From the Attendee record, click the Additional Actions menu and select Reload form.
The system reloads the form and displays the new field.
Figure 3. Updated attendee form
Exercise 14: Update the add attendees inbound web service
Automatically set the value of the sales prospect field when an external record is created or modified by updating the Add Attendee inbound web service.

1. Navigate to System Web Services > Inbound > Add Attendees.


2. From the Web Service Transform Maps related list, click Add Attendees.
3. From the Transform Scripts related list, click New.
4. Enter these values.
Field Value

When onBefore

Order 200

Script
//Set sales_prospect to true
target.sales_prospect = true;

Figure 1. Completed transform script


5. Click Submit.
Exercise 15: Create a sales prospect table
Simulate the end point of an external application by creating a sales prospect table. Then use the table to trigger an outbound REST message.

1. Navigate to System Applications > Applications.


2. Click Marketing Events Application.
3. From the Tables related list, click New.
4. Enter these field values.

Field Value

Label Sales Prospect

Name x_snc_marketing_ev_sales_prospect

Add module to menu Marketing Event

Note: The Name field automatically populates the value x_snc_marketing_ev_sales_prospect.


5. From the Columns embedded list, double-click Insert a new row to enter these column values.

Column label Type

Name string

Company string
Email string

Phone string

Region string

Figure 1. Newly created table columns


6. Click Submit.
The system creates the table and adds a module to the Marketing Event menu.
Figure 2. Marketing Event menu in the application navigator
Exercise 16: Create a sales prospect inbound web service
Simulate the endpoint URL of the sales prospect external application by creating an inbound web service. Then perform database operations on the Sales
Prospect table by sending outbound REST messages.

1. Navigate to System Web Services > Inbound > Create New.


2. Enter these field values.

Field Value

Label Add Sales Prospect

Name x_snc_marketing_ev_add_sales_prospect

Create transform map Selected

Target table Sales Prospect [x_snc_marketing_ev_sales_prospect]


3. From the Web Service Fields embedded list, double-click Insert a new row to enter these field values.

Label Name Length

Name u_name Default (40)

Company u_company Default (40)

Email u_email Default (40)

Phone u_phone Default (40)

Region u_region Default (40)

The Create Web Service form displays a row for each web service field you added.
Figure 1. Added web service fields
4. Click Create.
The system creates the import set table Add Sales Prospect [x_snc_marketing_ev_add_sales_prospect] and the endpoint
URLhttps://<instancename&gt;.service-now.com/x_snc_marketing_ev_add_sales_prospect.do?WSDL, and then displays the Table Transform Map form.
Figure 2. Table Transform Map for new inbound web service
5. Under Related Links, click Auto Map Matching Fields.
The system displays the Field Maps related list with a list of matching fields.
6. Double-click the Coalesce cell for the u_email row, and set the value to true.
7. Click the green checkmark to save the transform map.
8. From Related Links, click Index Coalesce Fields.
The system displays a Create a New Index confirmation pop-up window.
9. Select Do not notify me.
10. Click OK.
The system schedules the creation of an index.
11. Click OK.

Exercise 17: Create an outbound web service


Create an outbound REST web service containing attendees who are not sales prospects. The REST message uses an HTTP method to change records on the
external application.

Since we do not actually have an external application to receive the outbound message, we will use the Import Set API as our target endpoint.

1. Navigate to System Web Services > Outbound > REST Message.


2. Click New.
3. Enter these field values.

Field Value

Name Synch Sales Prospects

Endpoint https://<instancename&gt;.service-now.com/api/now/import/ x_snc_marketing_ev_add_sales_prospect

Note: Click the lock icon to access the field.


Use basic authentication Selected

Basic authentication user ID admin

Basic authentication user password enter the admin password

4. From the HTTP Headers embedded list, double-click Insert a new row to enter these headers.

Name Value

Content-Type application/json

Accept application/json

5. Right-click the form header, and click Save.


The system displays the HTTP Methods related list.
Figure 1. Available HTTP Methods for the Synch Sales Prospects REST message
6. From the HTTP Methods related list, click post.
7. Enter these field values.

Field Value
Content
{
"u_name":"${u_name}",
"u_company":"${u_company}",
"u_email":"${u_email}",
"u_phone":"${u_phone}",
"u_region":"${u_region}"
}

8. Click update.
9. From the Variable Substitutions related list, click New.
10. Enter these values.
Note: You must click New for each substitution.

Name Escape type Test value

u_name No escaping League of Extraordinary Gentlemen

u_company No escaping allan.quatermain@loeg.com.uk

u_email No escaping Allan Quatermain

u_phone No escaping (+44) (0)20 7930 4832

u_region No escaping EMEA

Figure 2. Completed variable substitutions list


Exercise 18: Test the outbound web service
Verify the outbound web service that you created in the previous exercise can change a record in an external application.
1. Navigate to System Web Services > Outbound > REST Message.
2. Click Sync Sales Prospects.
The available HTTP methods appear.
Figure 1. HTTP methods for the REST message
3. Under HTTP Methods, click post.
4. From the HTTP Method post forms Related Links, click Test.
The system displays a Test Runs record. The HTTP status should be 201.
Figure 2. Test Runs record
5. Click Update to return to the HTTP Method post form.
6. From Related Links, click Preview Script Usage.
The system displays sample JavaScript to call the outbound REST Message.
Figure 3. Sample JavaScript
Note: This script uses hard-coded values. You will use this script as a business rule template in a later exercise.
7. Navigate to Marketing Event > Sales Prospects.
The system displays the record you inserted from a REST message.
Figure 4. Sales Prospects table with new record
Exercise 19: Create an asynchronous business rule
Automatically call an outbound REST message by creating an asynchronous business rule for the Attendee table.

The purpose of this business rule is to send an outbound REST message whenever an attendee is created or updated.

1. Navigate to System Definition > Business Rules.


2. Click New.
3. Enter these field values.

Field Value
Name Add Sales Prospects

Table Attendee [x_snc_marketing_ev_attendee]

Advanced Selected

When Async

Insert Selected

Updated Selected

Condition current.sales_prospect == false;

Script
function onAsync(current) {
//This function will be automatically called when this rule is processed.
try {
//Combine first and last names
var fullname = current.first_name + ' ' + current.last_name;
var r = new sn_ws.RESTMessageV2('x_snc_marketing_ev.Synch Sales Prospects',
'post');
r.setStringParameter('u_email', current.email);
r.setStringParameter('u_name', fullname);
r.setStringParameter('u_phone', current.phone);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
current.sales_prospect = true;
current.update();
}
catch(ex) {
var message = ex.getMessage();
}
}

4. Click Submit.

Exercise 20: Test the asynchronous business rule


Verify that the asynchronous business rule creates valid outbound REST messages when attendee records are inserted and updated.

1. Navigate to Marketing Event > Attendee.


2. Click New.
3. Enter these field values.

Field Value

First name Guy

Last name Fawkes

Email guy.fawkes@anonymous.org

Marketing Event London LUG


4. Click Submit.
The system adds the new record and displays the Attendees list.
5. From the Attendees list, click jr.ewing@ewingoil.com.
6. In the First name field, enter JR.
7. Click Update.
8. From the Attendees list, click jr.ewing@ewingoil.com again.
The attendee record appears with the Sales Prospect field is selected.
Figure 1. Attendee record for JR Ewing

9. Click Update.
The system displays the Attendees list.
10. From the Attendees list, click guy.fawkes@anonymous.org.
The attendee record appears, with the Sales Prospect field selected.
Figure 2. Attendee record for Guy Fawkes
11. Navigate to Marketing Event > Sales Prospects.
The system displays the current list of Sales Prospects.
Figure 3. Sales Prospects table
Two of the sales prospects match the Attendee records you inserted and updated.

Evaluation of the outbound web service


The outbound REST web service meets the new business requirements.

Table 1. Review of new business requirements

Requirement Met? Evaluation


Identify marketing event attendees who are not Yes Success also depends on the external
already sales prospects. applications ability to coalesce records sent
to it.
Making the field read-only prevents users
from changing the value.
Could use the Sales Prospect field to
generate a report.

Send attendee details to the external application Yes The asynchronous business rule creates an
whenever an attendee is added or changed. outbound REST message for each attendee
addition or change.
The Attendee table could have additional
fields to match sales prospect details such
as company and region.

Indicate an attendee record has been sent to the Yes The asynchronous business rule
external application automatically sets the Sales Prospect field
after sending a REST message.

02 Integrating with ServiceNow - Module 4 - Processors


Additional external application business requirements
Marketing event users have requested changes to support integration with external applications.

Specifically, they want to be able to:

Calculate a marketing events attendance from a URL query.


Display calculation results in the client.

You can meet these requirements by:

Creating a custom processor to act as the endpoint of the URL query. The system parses the URL query to identify the following components.
Table name on which the processor acts
Input parameter name
Input parameter value
Using the scoped API to calculate how many attendee records there are for a specified marketing event.

Processors
ServiceNow processors are analogous to Java servlets. Processors provide a customizable URL endpoint that can execute arbitrary server-side JavaScript
code and produce output such as TEXT, JSON, or HTML.

Typically, you create custom processors when you want a URL query to:

Produce data in non-standard formats.


Perform non-standard record operations.
Act on multiple tables.

There are two types of processors.


Single-purpose: processors that have a single purpose and single endpoint.
Multi-table: processors that apply to all tables on the instance.

By default, processors are public and can execute without requiring authorization. This means that any logged-in user can execute the processor without
needing a particular role. To prevent leakage of secure data, protect your processors with ACLs (Access Control Lists) that restrict their use to users with an
authorized role.

When to create processors


Use this table to determine whether you should use existing functionality or create a custom processor.

Table 1. Processor creation guidelines

Requirement Recommendation

Perform basic operations such as create, read, update, or Use an existing web service, such as the REST API, or use an existing processor, such
delete records. as Export to PDF.

Export data to a standard format such as JSON, CSV, PDF,


Excel, or XML.

Operate on or export data from a single table.

Perform non-standard operations such as compute Create a custom processor.


aggregation values.

Export data in a non-standard format such as SQL.

Operate on or export data from multiple tables.


Operate on or export data from multiple tables.

Exercise 21: Create a custom processor


Count the number of attendees at a given marketing event by creating a custom processor.

1. Navigate to System Definition > Processors.


2. Click New.
3. Enter these field values.

Field Value

Name getAttendance

Type Script

Description Calculate the attendance of a marketing event

Parameters mrkevent

Parameters Endpoint x_snc_marketing_ev_mrkevent

Path getAttendance

Path Endpoint x_snc_marketing_ev_getAttendance

Script
g_response.setContentType('text/html;charset=UTF-
8');

//Get Sys ID from URL parameter


var sid =
g_request.getParameter('x_snc_marketing_ev_mrkevent
');

//Look up marketing event name from Sys ID


var gr = new
GlideRecord('x_snc_marketing_ev_marketing_event');
gr.get(sid);
var name = gr.name;

//Check ACLs before querying


if(gr.canRead()) {

var numOfAttendees = 0;
var attendees = new
GlideAggregate('x_snc_marketing_ev_attendee');
attendees.addQuery('marketing_event', sid);
attendees.addAggregate('COUNT');
attendees.query();
if(attendees.next())
numOfAttendees =
attendees.getAggregate('COUNT');

g_processor.writeOutput('Marketing event '


+ name + ' has ' + numOfAttendees + ' attendees');
} else {
g_processor.writeOutput('Access denied');
}
4. Click Submit.

API components of the getAttendance processor


The getAttendance processor uses these eight new API classes, objects, and methods.

Table 1. API components of the getAttendance processor

Class, object, or method Description

g_response An object of type HttpServletResponse. See Interface HttpServletResponse.

setContentType(text/html;charset=UTF-8) A HttpServletResponse method to set the content type of the response being sent to the client.
SeeInterface HttpServletResponse.

g_request An object of type HttpServletRequest. SeeInterface HttpServletRequest.

getParameter(x_snc_marketing_ev_mrkevent) A glide method to get the value of a URL parameter.

canRead() A GlideRecord method to determine if the user can read data from a table. SeeScoped GlideRecord API
Reference.

g_processor A simplified servlet for processors.

writeOutput(Access Denied) A processor method to display information on the client.


g_target An object containing the target table name of a processor URL. For example, a processor containing the
URIincident.do applies to the Incident table.

Exercise 22: Test custom processor


Find out if the getAttendance custom processor returns a list of attendees for a particular marketing event.

1. Navigate to Marketing Event > Marketing Events.


2. Click Dallas LUG.
3. Right-click the form header and select Copy sys_id.
The system displays a pop-up window containing the Sys ID of the Dallas LUG.
Figure 1. Sys ID for copying

4. Copy the Sys ID from the pop-up window.


5. Click OK to close the pop-up window.
6. Create the URL for your custom processor by combining these values.

Base URL Processor URI

https://<instance_name>.service-now.com /<Path endpoint>.do?<Parameter endpoint>=<Sys ID of Dallas


LUG>

For example:

https://dev20118.service-now.com/x_snc_marketing_ev_getAttendance.do?x_snc_marketing_ev_mrkevent=2721380c0f3631004f2009bce1050eab

7. In a new browser window or tab, navigate to your custom processor.


The system displays the number of attendees for the Dallas LUG marketing event.
Figure 2. Number of attendees for the Dallas LUG

Evaluation of the custom processor


While the getAttendance custom processor meets our business requirements, it has some limitations.

Table 1. Additional external application business requirements review

Requirement Met? Evaluation

Calculate a marketing events attendance from a Yes Could rewrite the processor to use a
URL query. marketing event name rather than a Sys ID.
There are script actions that already
calculate this information based on events.
Could use a web service instead of a
processor to query the Attendee table.

Display calculation results in the client. Yes This information might be better displayed in
a field.
Could display result as a numeric value for
use by an external application or process.

02 Integrating with ServiceNow - Module 5 - ODBC driver

New connectivity business requirements


Marketing events users have requested improvements to support reporting from an external business intelligence application.

Support ODBC queries of marketing event data.


Support a read-only connection to the instance.

You will meet these requirements by:

Installing the ODBC driver on a supported Windows system.


Configuring the ODBC driver to communicate with your instance.
Exercise 23: Install the ODBC driver
Install the ODBC driver on a supported Windows system.

1. Navigate to User Administration > Users.


2. Click New.
3. Enter these field values.

Field Value

Name odbc

Password enter a password

4. Right-click the form header, and click Save.


5. From the Roles related list, click Edit.
6. Add these roles.

Role

itil

soap

x_snc_marketing_ev_attendee_user
x_snc_marketing_ev_equipment_request_user

x_snc_marketing_ev_marketing_event_user

7. Click Save.
8. Log in to a supported Windows system or virtual machine.
9. Navigate to KB0540707 on HI.
The browser displays the ODBC Driver Installer knowledge article.
10. From Available versions, click Download next to the ODBC driver version you want to use.
Figure 1. ODBC drivers

11. Open the ODBC Driver installer on the Windows machine and follow the on-screen instructions.
12. Navigate to Start > Programs > ServiceNow ODBC > Management Console.
13. From the left pane, navigate to Console Root > OpenAccess SDK 6.0 Manager >[installation location] > Services > ServiceNow_ODBC > Data Source
Settings>ServiceNow > IP Parameters.
14. Double-click the DataSourceIPProperties attribute.
The Properties dialog box opens.
15. In Value, enter the URL of your instance.
16. Click OK.

Exercise 24: Test the ODBC connection


Verify that the ODBC driver can communicate with your instance.

1. In Windows, navigate to Start > Programs > ServiceNow ODBC > ODBC Administrator.
2. Click the System DSN tab.
3. Select the ServiceNow data source.
4. Click Configure.
Windows displays an ODBC Driver Setup dialog box.
5. Click Test Connection.
6. Enter the ODBC user credentials you created.
Note: The password field is limited to 18 characters.
7. Click OK.
Windows displays a success message.

Exercise 25: Attempt to run an ODBC query


Issue a query to your instance using Interactive SQL.

1. In Windows, navigate to Start > Programs > ServiceNow ODBC > Interactive SQL (ODBC).
2. Enter the following command to connect to the ServiceNow instance.
connect odbcuser*password@ServiceNow
Note: Replace odbcuser and password with the ODBC user account name and password created earlier.
3. Enter the following command.
select marketing_event from x_snc_marketing_ev_attendee;
4. Press Enter.
The ODBC Driver returns an error message about not finding column information.
Figure 1. ODBC driver error message

Exercise 26: Update table application access settings


Allow web service access to the Attendee table by updating its application access settings.

1. Navigate to System Definition > Tables.


2. Click the Updated column to sort by the most recently updated table.
3. Click Attendee.
4. From Application Access, enter these values.

Field Value

Accessible from All application scopes

Can read Selected


Allow access to this table via web services Selected

5. Click Update.

Exercise 27: Rerun the ODBC query


Reissue queries to your instance with Interactive SQL.

1. In Windows, navigate to Start > Programs > ServiceNow ODBC > Interactive SQL (ODBC).
2. Enter the following command to connect to the ServiceNow instance.

connect odbcuser*password@ServiceNow

Note: Replace odbcuser and password with the ODBC user account name and password created earlier.
3. Enter the following command.
select marketing_event from x_snc_marketing_ev_attendee;
4. Press Enter.
The ODBC Driver returns results. Notice that the query returns raw database values instead of display values. In this case, the query returns the 32-
character sys ID of the marketing event.
Figure 1. ODBC query results
5. Enter the following SQL command to alter the Attendee table.
alter x_snc_marketing_ev_attendee drop column email;
The ODBC Driver displays a syntax error message.
Figure 2. ODBC driver syntax error message

6. Enter the following SQL command to create a new table.


create table test;
The ODBC Driver displays a syntax error message.
Figure 3. Second ODBC driver syntax error message
Evaluation of the ODBC driver
While the ODBC driver meets our business requirements, it has limitations.

Table 1. Connectivity business requirements review

Requirement Met? Evaluation

Support ODBC queries of marketing event data. Yes Queries return only database values not display values.
Reference and choice fields are not good candidates for ODBC queries.
Queries require knowing column and table names rather than labels.

Support a read-only connection to the instance. Yes Cannot run ALTER commands.
Cannot run DROP commands.
Cannot run CREATE commands.
02 Integrating with ServiceNow - Module 6 - Considerations and
conclusions

Evaluation of the integration methods


This table summarizes the integration methods you worked with in this learning path.

Table 1. Summary of integration methods

Integration Good for Future considerations


method

Import sets Importing bulk data from external Web service import sets allow you to restrict direct web service access to an application
files table.
Application-specific web services Web service import sets automatically apply transform maps.

Transform Data transformation and clean up Identify the fields that make a record unique and use them to coalesce.
maps Identification of and updates to There are several existing transform maps you can use as templates.
existing records
REST API Proper formatting of REST requests Can eliminate the need for web service client tools.
Explorer Testing inbound REST requests Use to reduce the complexity of scripting REST calls.
Generating sample code Calls bypass application access settings.

REST Communicating with external Use Preview Script Usage to see how to code a REST message.
messages applications REST messages require asynchronous business rules.
Automatically including record values
by using variables

Processors Running arbitrary code from a URL Creating processors requires using the application scopes namespace identifier in the
Applying an operation to multiple URL.
tables Consider whether web services can accomplish the same goal.
There are many existing processors to use.

ODBC Running reports on a separate Queries require knowing column and table names rather than labels.
Driver system Since ODBC queries return database values rather than display values, reports on
Integrating with existing reporting reference or choice fields will not be as useable.
tools Consider generating reports from theReporting engine or Performance Analyticsinstead.

Further challenges
Improve your skills by attempting these tasks on your own.

Create a mobile UI or app that sends and receives REST messages.


Create a processor that applies to any table. For example, see this Community post about computing the size of any table.

03 Coding on ServiceNow - Module 1 - Coding basics

Introduction to the ServiceNow API


The ServiceNow API allows developers to create business logic at every level of the coding stack.

As a developer, you can use the API to perform the following actions.

Query the system for information


Query the database for records
Validate that record inserts and updates meet a data policy
Change the values of fields
Create list and form controls
Change the behavior of controls based on user actions

To support the API, the ServiceNow platform provides these coding tools.

Template blocks and code snippets


Editors that offer:
Automatic formatting
Color coding
Syntax validation
Debugging tools

Where scripts run


Scripts can run on the server or the client.

Server-side scripts have access to:

The database
The current record
The previous record
The full system API

Client-side scripts have access to:

The UI elements in the browser


The current form
The current value of fields

Common coding components


You can add code to components of the server or the client.
The following records are the most common parts of the platform that accept code input.

Table 1. Platform components that accept code

Component Runs Description Often used to


on

Business Server Perform operations on table data when it is displayed, inserted, updated, deleted, Validate data and trigger events.
rules or queried. They are similar to RDBMS triggers but with a full server-side API to
support them.

Script Server Store JavaScript functions and classes for use by server-side script objects. Each Enable different components to reuse
includes script include defines either a function or an implementation of a ServiceNow server code and to make server code
class. Script includes only run when called by a server script. available to client-side calls.

Events Server Run when specific conditions occur on the system to trigger script actions. Identify and log when certain conditions
are met, such as when an incident is
opened or closed.

Script Server Run when a specific event is triggered to determine how the system handles it. Automate a response when a specific
actions event occurs, such as send an email
notification when an incident is opened.

UI actions Server Add buttons, links, and context menu items on forms and lists to allow users to Enable users to perform a specific action,
or perform application-specific operations. such as resolve an incident.
client

Client Client Run JavaScript on the browser to perform operations on form and list data. Enforce data policies during data entry,
scripts such as validate that an end date is after
a start date.

UI policies Client Perform operations on form data or fields, such as making fields mandatory, Enforce data policies from the UI, such as
visible, or read-only. make a field required on first entry and
then read-only afterwards.

03 Coding on ServiceNow - Module 2 - UI actions

Business requirements: budget


After using the Marketing Events application, users requested the following improvements.

Tell users when a marketing event exceeds its budget.


Display the total equipment cost of a marketing event.
Display the remaining budget available for a marketing event.

Exercise 1: Create a UI action


In this exercise you create a UI action to calculate the total cost of a marketing event and display an error message if the cost exceeds the budget.

1. Navigate to System UI > UI Actions.


2. Click New.
3. Enter the following values.
Field Value

Name Show event cost

Table Marketing Event [x_snc_marketing_ev_marketing_event]

Action name Show event cost

Form button Selected

Form context menu Selected

Hint Calculate an events total equipment cost

Script
var cost = 0;
var budget = current.budget;
var mrkevent = current.sys_id;
var evtname = current.name;
//Get the total cost of all equipment for this event
var equipment = new GlideRecord('x_snc_marketing_ev_equipment_request');
equipment.addQuery('marketing_event', mrkevent);
equipment.query();
while(equipment.next()){
cost = cost + parseFloat(equipment.cost.getCurrencyValue());
}
//Display cost and budget error
gs.addInfoMessage('The total cost of ' + evtname + ' is ' + cost + '.');
if(cost > budget){
gs.addErrorMessage('Equipment costs for ' + evtname + ' exceed the event budget.');
}
action.setRedirectURL(current);
4. Click Submit.

API components of the UI action


The Show event cost UI action uses the API classes, objects, and methods found in this lesson.

For more information about these classes, objects, and methods, see Scoped GlideRecord API Reference unless otherwise noted.

Table 1. API components of the Show event cost UI action

Class, object, or method Description

current An object that stores field values of the current record. See Glide Script Objects.

current.budget A dot-walking reference to a particular field of the current record. In this case, the values of
the Budget, Sys ID, andNamefields. SeeDot-walking.
current.sys_id

current.name

GlideRecord(x_snc_marketing_ev_equipment_request) A class for database operations you can use instead of writing SQL queries. A GlideRecord
object contains records for a single table. In this case, the object contains records for the
Equipment Request table.

addQuery(marketing_event, current.sys_id) A GlideRecord method to return records by specifying a query. In this case, the method adds a
filter to the current query, equivalent to an SQL WHERE clause, where the marketing event field
equals the system ID of the current record.

query() A GlideRecord method to run any queries added by previous method calls.

next() A GlideRecord method to determine if there is another record in the GlideRecord object.

parseFloat() A GlideSystem method to convert a currency value to a floating number. See Scripting Currency
and Price Fields.

getCurrencyValue() A GlideSystem method to convert a currency string to a numeric value for calculations.
SeeScripting Currency and Price Fields.

gs.addInfoMessage A GlideSystem method to display an information message on the top of the screen.
See Scoped GlideSystem API Reference.

action.setRedirectURL(current) A UI action method to redirect the user to another page. In this case, the system redirects the
client to the current record after updating it. See UI Actions.

Exercise 2: Test the UI action


In this exercise you test the UI action to see how it meets the business requirements of the marketing event users.

1. Navigate to Marketing Event > Marketing Events.


2. Click Dallas LUG.
3. Click Show event cost.
The system displays the total cost of the event.
4. From the Equipment Requests related list, select AV.
5. Change the cost from $1,000.00 to $2,000.00.
6. Click Update.
7. Click Show event cost.
Figure 1. Show event cost

The system displays both the total cost of the event and an error message that the budget has been exceeded.

Evaluate the UI Action


Currently, the Show event cost UI action meets some, but not all, of the Marketing Event users needs.

Table 1. UI action to marketing requirements comparison


Requirement Met? Evaluation

Tell users when a marketing event exceeds its Yes Requires user to manually select action.
budget. Users can still create events that exceed their budget.

Display the total equipment cost of a marketing Yes Requires user to manually select action.
event. Would be better to always display current cost total.

Display the available remaining budget for a No Could update UI action to compute remaining budget from
marketing event. thebudget and costvariables and display it.
This information might be better stored in a separate field or determined by a list
calculation.

Exercise 3: Add a list calculation


All lists have the option to calculate and display values. In this exercise, you add a list calculation to the Equipment Requests embedded list so that it always
displays the total cost of equipment.

1. Navigate to Marketing Event > Marketing Events.


2. Click Dallas LUG.
3. From the Equipment Requests embedded list, right click the Cost column label.
4. Select Configure > List Calculations.
5. Select Total Value.
Figure 1. List calculation options
6. Click OK.
The Cost column now always displays the total value of all equipment requests.
Figure 2. List calculation on column
03 Coding on ServiceNow - Module 3 - UI policies

Exercise 4: Create a UI policy


In this exercise you create a UI policy to make several fields mandatory.

A UI policy is a good fit for this business logic because it oers full control over the order in which client-side operations take place. Use the Order field to
specify which UI policy you want to run first.

Note: The system runs client scripts first, then UI policies.

You can also use list filters to query for specific UI policies if you decide later to change their behavior.

1. Navigate to System UI > UI Policies.


2. Click New.
3. Enter the following field values.

Field Value

Table Marketing Event [x_snc_marketing_ev_marketing_event]

Description Mandatory Marketing Event fields

4. Right-click the form header and select Save.


5. From the UI Policy Actions related list, click New.
6. Enter the following field values.

Field Value

Field name Name

Mandatory True

Visible Leave alone

Read only Leave alone

7. Click Submit.
8. Repeat steps 5 7 for the Sponsor and Budget fields.
9. Click Update.

Exercise 5: Test the UI policy


In this exercise you test the UI policy to see how it meets the needs of the marketing event users.

1. Navigate to Marketing Event > Marketing Events.


2. Click New.
Figure 1. Mandatory fields
The Name, Sponsor, and Budget fields have the mandatory field indicator on them.

3. Enter the following field values.

Field Value

Name Sydney LUG

Budget $2000.00

Start Date 07-01-2015

End Date 07-03-2015

City Sydney
4. Click Submit.
Figure 2. Mandatory fields warning message

The system displays a pop-up window with the message The following mandatory fields are not filled in: Sponsor.

5. Click OK.
6. In Sponsor, enter Sydney partners.
7. Click Submit.

03 Coding on ServiceNow - Module 4 - Client scripts


Exercise 6: Create a client script
In this exercise you create a client script to prevent a marketing event user from entering an end date that occurs before the start date.

A client script is a good API component to use for this validation effort because it runs before the client sends any data to the server. This prevents the server
from inserting or updating a marketing event containing bad data. It also prevents time-consuming queries to the server, which improves application
performance.

1. Navigate to System Definition > Client Scripts.


2. Click New.
3. Enter the following field values.

Field Value

Name End Date Validation

Table Marketing Event [x_snc_marketing_ev_equipment_request]

Type onSubmit

Message getMessage(must be after)

Script
function onSubmit() {
//Type appropriate comment here, and begin script below
if(g_form.getValue('end_date') == '')
return;

if(g_form.getValue('end_date') <= g_form.getValue('start_date')) {


g_form.clearMessages();

g_form.addErrorMessage(g_form.getLabelOf('end_date') + ' ' + getMessage('must be


after') + ' ' + g_form.getLabelOf('start_date'));
return false;
}

4. Click Submit.

API components of the client script


The End Date Validation client script uses the API classes, objects, and methods found in this table.

For more information about these classes, objects, and methods, see GlideForm (g_form) unless otherwise noted.

Table 1. API components of the date validation client script

Class, object, or method Description

function onSubmit() A JavaScript function call that occurs whenever the user submits form data. Enclosing code in a function prevents the
system API from erroneously re-using variable values in different scopes. See Client Scripts.

g_form.getValue(end_date) A JavaScript API call to the GlideForm class. In this case, to use the getValue() method to get the value of
theend_date andstart_date fields.
g_form.getValue(start_date)
g_form.clearMessages() A JavaScript API call to the GlideForm class. In this case, to use the clearMessages() method to remove any previous
error and info messages.

g_form.getLabelOf(end_date) A JavaScript API call to the GlideForm class. In this case, to use the getLabelOf() method to get the label of
theend_datefield.

Exercise 7: Test the client script


In this exercise you test the client script to see how it meets the needs of the marketing event users.

1. Navigate to Marketing Event > Marketing Events.


2. Click Dallas LUG.
3. Update the End Date to May 1, 2015.
4. Click Update.
Figure 1. Field entry validation error message
The system displays an error message that the End date must be after Start date.

5. Revert the End Date to May 18, 2015.

03 Coding on ServiceNow - Module 5 - Business rules


How Business Rules Work
This introduction explains how business rules work and their benefits over other types of coding components.

All business rules have the following characteristics:

A type that determines when they run in relation to database operations.


A list of database operations that can trigger them.
An action that can do one or more of the following.
Set one or more field values
Display a message
Abort the current database operation
Run custom code

Developers typically use custom code in business rules to:

Perform database operations, such as querying for a list of related records


Check for complex conditions, such as determining how long an incident has been in a resolved state
Check for dynamic values, such as the user currently assigned to a task
Display information to the user, such as validation errors
Change field values, such as changing the incident state from resolved to closed

Use a business rule when you want to:

Set when business logic runs in relation to a database operation.


Automate business logic rather than require user interaction.
Ensure business logic runs no matter what its source. For example, when:
A user submits a form
A web service requests a database operation
When Business Rules Run
The business rule type determines the timing of when it runs in relation to a database operation. A business rule can have only one type.

Table 1. Business Rule Types

Type Runs Use to

Before After the user submits the form but before Validate data before inserting or updating
the system takes any action on the record in into the database.
the database.

After After the user submits the form and after the Perform calculations or business logic on
system takes action on the record on the data, such as updating totals or counts.
database.

Async As an asynchronous scheduled job in the Perform calculations or business logic on


background after the user submits the form data in the background. Allows the system to
and after the system takes action on the do other tasks, such as loading a form or
record on the database. running other business rules.

Display Before the system displays the form to the Perform calculations or business logic on
user and just after the system reads a record data that may affect user input, such as the
from the database. current price of a catalog item.
Exercise 8: Create a before business rule
In this exercise you create a before business rule to validate the marketing event budget whenever a user inserts or updates a marketing request record. You
want to abort any insert or update where the marketing event budget is zero.

A before business rule is a good fit for this business logic because the system can validate all inserts and updates to the target table regardless of the input
method. Validation occurs whether a user submits a form, a user submits a service catalog record producer request, or there is an automated web services
request.

1. Navigate to System Definition > Business Rules.


2. Click New.
3. 3. Enter the following field values.

Field Value

Name Validate marketing event

Table Marketing Event [x_snc_marketing_ev_equipment_request]

Advanced Selected

When Before

Insert Selected

Update Selected

Script
function onBefore(current, previous) {
//This function will be automatically called when this rule is processed.
var evtbudget = current.budget.getCurrencyValue();
if(evtbudget < 1){
gs.addErrorMessage('Budget must be greater than zero');
current.setAbortAction(true);
}
}

4. Click Submit.

API components of the business rule


The Validate marketing event business rule uses the following new API classes, objects, and methods.

Table 1. API components of the business rule

Class, object, or method Description

function onBefore() A JavaScript function call that occurs after the user submits form data, but before any database operation. Enclosing code in
a function prevents the system API from erroneously re-using variable values in different scopes. See Business Rules.

current.setAbortAction(true) A GlideSystem method to abort the database operation on the current record. See Business Rules.
Exercise 9: Test the before business rule
In this exercise you test the before business rule to see if it validates all inserts and updates to the Marketing Events table regardless of source.

1. Navigate to Marketing Event > Marketing Events.


2. Click New.
3. Enter the following field values.

Field Value

Name Sydney LUG

Sponsor Sydney Partners

City Sydney

4. Click Submit.
Figure 1. Testing the before business rule
The system displays two error messages: Invalid insert and Budget must be greater than zero.

5. 5. Navigate to Self-Service > Service Catalog.


6. Navigate to Oce > Request Marketing Events.
7. Fill in the following field values.

Field Value

Event name Sydney LUG


Event Sponsor Sydney Partners

City Sydney

8. Click Submit.
Figure 2. Testing the before business rule with Service Catalog

The system displays an error message: Budget must be greater than zero.

Exercise 10: Create an after business rule


In this example you create an after business rule that automatically calculates and displays the total cost whenever a user inserts or updates a marketing event
record. This business rule reuses your existing code from the Show event cost UI action.

An after business rule is a good fit for this business logic. You want to use the most current data to compute the total cost and you can compute that cost with
every insert and update.

1. Navigate to System Definition > Business Rules.


2. Click New.
3. Enter the following field values.
Field Value

Name Calculate total cost

Table Marketing Event [x_snc_marketing_ev_equipment_request]

Advanced Selected

When After

Insert Selected

Update Selected

Script
function onAfter(current, previous) {
//This function will be automatically called when this rule is processed.
var cost = 0;
var budget = current.budget;
var mrkevent = current.sys_id;
var evtname = current.name;
//Get the total cost of all equipment for this event
var equipment = new GlideRecord('x_snc_marketing_ev_equipment_request');
equipment.addQuery('marketing_event', mrkevent);
equipment.query();
while(equipment.next()){
cost = cost + parseFloat(equipment.cost.getCurrencyValue() );
}
gs.addInfoMessage('The total cost of ' + evtname + ' is ' + cost + '.');
if(cost > budget){
gs.addErrorMessage('Equipment costs for ' + evtname + ' exceed the event budget.');
}
}

4. Click Submit.

Exercise 11: Test the after business rule


In this exercise you test the after business rule to see if it always calculates the total cost, regardless of source.

1. Navigate to Marketing Event > Marketing Events.


2. Click London LUG.
3. From the Equipment Requests related list, click New.
4. Enter the following field values.

Field Value

Type iPad Air 2 Wi-Fi + Cellular 64GB

Cost $800.00

Marketing Event London LUG

5. Click Submit.
6. In Number of attendees expected, enter 10.
7. Click Update.
Figure 1. Test after business rule

The system displays an information message with the total cost of the marketing event, proof the after business rule ran.

8. Navigate to Marketing Event > Equipment Requests.


9. Click New.
10. Fill in the following field values.

Field Value

Type Banner
Cost $200.00

Marketing Event London LUG

11. Click Submit.


12. Navigate to Marketing Event > Marketing Events.
13. Click London LUG.
14. Click Update.
Since the system did not insert or update any London LUG records in the Marketing Events table, it did not run the after business rule.

Evaluate Business Rules


Currently, the Validate marketing event and Calculate total cost business rules meet some, but not all, of the Marketing Event users needs.

Table 1. Business Rule Types

Requirement Met? Evaluation

Tell users when a marketing event exceeds its Yes Automatically calculates cost and warns user of exceeding budget oninserts and
budget. updates.
Could create a display business rule to show the total cost when displaying a marketing
event.
Users can still create events that exceed their budget.
Display the total equipment cost of a marketing Yes Automatically calculates and displays cost on inserts and updates.
event. List control calculation removes need to add display business rule.
Could display this information in a separate field.

Display the available remaining budget for a No Could update business rule to compute remaining budget from
marketing event. the budget andcostvariables and display it.
This information might be better stored in a separate field.

03 Coding on ServiceNow - Module 6 - Script includes

Exercise 12: Create a script include


In this exercise you move some of the logic from your existing UI action and business rule to a script include.

A script include is a good fit if you want multiple API components to use the same server code.

1. Navigate to System Definition > Script Includes.


2. Click New.
3. Enter the following field values.

Field Value
Name totalCost

Application Marketing Events

Accessible This application scope only

Description Generate the total cost of a marketing event based on the equipment requests associated with it. Compare the total cost to the
event budget.

Script
var totalCost = Class.create();
totalCost.prototype = {
initialize: function(mrkevent) {
this.mrkevent = mrkevent;
},

getCost: function() {
var cost = 0;
//Get the total cost of all equipment for this event
var equipment = new GlideRecord('x_snc_marketing_ev_equipment_request');
equipment.addQuery('marketing_event', this.mrkevent);
equipment.query();
while(equipment.next()){
cost = cost + parseFloat(equipment.cost.getCurrencyValue());
}
return cost;
},
type: 'totalCost'
};
Protection Read-only
Policy

4. Click Submit.

Exercise 13: Update the UI action to call the script include


In this exercise you update the existing Show event cost UI action to call the totalCost script include.

1. Navigate to System Definition > UI Actions.


2. Click the Updated column to sort by the most recent updates.
3. Click Show total cost.
4. Update this field value.

Field Value

Script
var budget = current.budget;
var mrkevent = current.sys_id;
var evtname = current.name;
//Get the total cost of equipment for this event
var equipment = new totalCost(mrkevent);
var cost = equipment.getCost();
gs.addInfoMessage('The total cost of ' + evtname + ' is ' + cost + '.');
//Compare cost to budget
if(cost > budget){
gs.addErrorMessage('Equipment costs for ' + evtname + ' exceed the event budget.');
}
action.setRedirectURL(current);

5. Click Update.

Exercise 14: Test the updated UI action


In this exercise you test your updated UI action to verify that it calls the totalCost script include.

1. Navigate to Marketing Event > Marketing Events.


2. Click Dallas LUG.
3. Click Show event cost.

Figure 1. Testing the updated UI action


The system shows the total event cost and an error message about the budget being exceeded.

Exercise 15: Update the after business rule


In this exercise you update the Calculate total cost business rule to call the totalCost script include.

1. Navigate to System Definition > Business Rules.


2. Click the Updated column to sort by the most recent updates.
3. Click Calculate total cost.
4. Update this field value.

Field Value

Script
function onAfter(current, previous) {
//This function will be automatically called when this rule is processed.
var budget = current.budget;
var mrkevent = current.sys_id;
var evtname = current.name;
//Get the total cost of equipment for this event
var equipment = new totalCost(mrkevent);
var cost = equipment.getCost();
gs.addInfoMessage('The total cost of ' + evtname + ' is ' + cost + '.');
//Compare cost to budget
if(cost > budget){
gs.addErrorMessage('Equipment costs for ' + evtname + ' exceed the event budget.');
}
}

5. Click Update.
Exercise 16: Test the updated after business rule
In this exercise you test your updated after business rule to verify that it calls the totalCost script include correctly.

1. Navigate to Marketing Event > Marketing Events.


2. Click New.
3. Enter the following field values.

Field Value

Name Sydney LUG

Sponsor Sydney partners

Budget $5000.00

City Sydney

Start Date July 1, 2015

End Date July 3, 2015

Number of attendees expected 50

4. Right-click the form header and click Save.


5. From the Equipment Requests related list, click New.
6. Enter the following field values.
Field Value

Type AV

Cost $2000.00

Needed From July 1, 2015

Needed Until July 3, 2015

Marketing Event Sydney LUG

7. Click Submit.
8. In Number of attendees expected, enter 50.
9. Click Update.
Figure 1. Test script include added to business rule
The system displays the total cost of the event.

API components of the script include


The TotalCost script include, Show event cost UI action, and Calculate total cost business rule use these API classes, objects, and methods.
For more information about these components, see Script includes unless otherwise noted.

Table 1. API components of the script include

Class, object, or method Description

Class.create() A JavaScript API call to create a class.

initialize: function(budget, A function declaration that defines two parameters, budget andmrkevent.
mrkevent)

current.sys_id A dot-walking reference to the value of the Sys ID field of the current record. The Sys ID uniquely identifies the record like a
foreign key in a SQL query. See Dot-walking.

current.budget A dot-walking reference to the value of the budget field of the current record. See Dot-walking.

totalCost(mrkevent) A reference to the totalCost script include with a parameter input.

getCost() A reference to the getCost function of the totalCost script include.

gs.addErrorMessage A GlideSystem method to display an error message on the top of the screen. See Scoped GlideSystem API Reference.

03 Coding on ServiceNow - Module 7 - Data model improvements


Exercise 17: Add fields for cost and remaining budget
In this exercise you add two fields to store the calculated values of marketing event cost and remaining budget.

1. Navigate to Marketing Event > Marketing Events.


2. Click Sydney LUG.
3. Right-click the form header, and click Configure > Form Design.
4. Click the Field Types tab.
5. Drag a Currency field directly beneath the existing Budget field.
6. Rename the field to Event cost.
7. Click the gear icon next to the Event cost field.
The system displays the Properties pop-up window for the Event cost field.
8. Enter the following field values.

Field Value

Name event_cost

Read-only Selected

9. Close the Properties pop-up window.


10. Drag a Currency field directly beneath the existing Event cost field.
11. Rename the field to Budget Remaining
12. Click the gear icon next to the Budget remaining field.
The system displays the Properties pop-up window for the Budget remaining field.
13. Enter the following field values.

Field Value

Name budget_remaining
Read-only Selected

14. Close the Properties pop-up window.


15. Drag the City field to the right column after the End date field.
16. Click Save.
17. Close the Form Design tab.
18. Click the context menu next to Marketing Event Sydney LUG, and click Reload form.

Figure 1. Improving the data model with two new fields


Exercise 18: Update the UI action for the data model addition
In this exercise you update the Show event cost UI action to populate the Budget remaining field and to remove the information message displaying the total
cost.

1. Navigate to System Definition > UI Actions.


2. Click the Updated column to sort by the most recent updates.
3. Click Show total cost.
4. Update this field value.

Field Value

Script
var budget = current.budget;
var mrkevent = current.sys_id;
var evtname = current.name;
//Get the total cost of equipment for this event
var equipment = new totalCost(mrkevent);
var cost = equipment.getCost();
//Compare cost to budget
if(cost > budget){
gs.addErrorMessage('Equipment costs for ' + evtname + ' exceed the event budget.');
}
//Populate cost
current.event_cost = cost;
//Populate Budget remaining
var remaining = budget - cost;
current.budget_remaining = remaining;
current.update();
action.setRedirectURL(current);

5. Click Update.
Exercise 19: Update the after business rule for the data model addition
In this exercise you update the Show event cost UI action to populate the Budget remaining field and to remove the information message displaying the total
cost.

1. Navigate to System Definition > Business Rules.


2. Click the Updated column to sort by the most recent updates.
3. Click Calculate total cost.
4. Update this field value.

Field Value

Script
function onAfter(current, previous) {
//This function will be automatically called when this rule is processed.
var budget = current.budget;
var mrkevent = current.sys_id;
var evtname = current.name;
//Get the total cost of equipment for this event
var equipment = new totalCost(mrkevent);
var cost = equipment.getCost();
//Compare cost to budget
if(cost > budget){
gs.addErrorMessage('Equipment costs for ' + evtname + ' exceed the event budget.');
}
//Populate cost
current.event_cost = cost;
//Populate Budget remaining
var remaining = budget - cost;
current.budget_remaining = remaining;
current.update();
}
5. Click Update.

Exercise 20: Test the data model updates


In this exercise you test your updates to the Show event cost UI action and Calculate total costbusiness rule to determine if they properly populate values in
theEvent cost and Budget remaining fields.

1. Navigate to Marketing Event > Marketing Events.


2. Click Sydney LUG.
3. Click Show event cost.
Figure 1. Show event cost and Budget remaining fields before a new request
The system no longer displays an information message with the total cost of the Sydney LUG event. Instead, the Event cost and Budget remaining fields
display the calculated values.

4. From the Equipment Requests related list, click New.


5. Enter the following field values.

Field Value

Type Wireless Mic


Cost $300.50

Needed From July 1, 2015

Needed Until July 3, 2015

6. Click Submit.
7. In Number of attendees expected, enter 50.
8. Right-click the form header and click Save.
Figure 2. Show event cost and Budget remaining fields after a new request
The system updates the values of the Event cost and Budget remaining fields.

Evaluate the data model updates


The Show event cost UI action and Calculate total cost business rule meet Marketing Event users needs, but there is still room for improvement.
Table 1. Data model update to marketing requirements comparison

Requirement Met? Evaluation

Tell user when a marketing event exceeds its Yes Automatically calculates cost and warns user of exceeding budget on inserts, updates,
budget. andShow event cost UI action.
Could create a display business rule to show the total cost when displaying a marketing
event.
Budget remaining field always displays current information.
Users can still create events that exceed their budget.

Display the total equipment cost of a marketing Yes Automatically calculates and displays cost inserts, updates, and Show event cost UI
event. action.
Event cost field always displays current information.

Display the remaining budget available for a Yes Budget remaining field always displays current information.
marketing event. Changes in currency type do not change currency values.

03 Coding on ServiceNow - Module 8 - Events and script actions


Business requirements: attendees
Marketing event users have requested additional improvements.

Rename Number of attendees registered to Attendees registered.


Rename Number of attendees expected to Max capacity.
Add an event coordinator to each marketing event.
Count the number of attendees registered for each marketing event and automatically populate the value on the form.

You meet these requirements by making the following changes.

Update the labels for two existing fields.


Add a new Event coordinator field.
Create a business rule to insert an event in the event queue whenever:
A new attendee is added to a marketing event.
The number of registered attendees reaches max capacity.
Register events for adding an attendee and reaching max capacity.
Create a script action to count the number of attendees for each marketing event and to add this value to the marketing event record.

Exercise 21: Update the Marketing Events form


In this exercise you create a new section, rename some fields, add a field, and reorganize the form.

1. Navigate to Marketing Event > Marketing Events.


2. Click London LUG.
3. Right-click the form header, and click Configure > Form Design.
4. Click the Field Types tab.
5. Click the Add a new section icon.
6. Rename the new section to Coordination.
7. From Field Types, drag Reference to the left column of the new section.
8. Rename the field to Event coordinator.
9. Click the gear icon next to the Event coordinator field.
10. Enter the following field values.

Field Value

Name event_coordinator

Reference User (sys_user)

Mandatory Selected

11. Drag the Sponsor field to the right column of the new section.
12. Click Number of attendees expected.
13. Rename the field to Max capacity.
14. Click Number of attendees registered.
15. Rename the field to Attendees registered.
16. Drag the Max capacity field underneath the Sponsor field.
17. Drag the Attendees registered field underneath the Event coordinator field.
Figure 1. Form design showing new section and fields
18. Click Save.
19. Close the Form Design tab.
20. Click the context menu next to Marketing Event London LUG, and select Reload form.
Figure 2. Reloaded Marketing Events form with new section
The system displays the total cost of the event.

21. In Event coordinator, select a user, such as Beth Anglin.


22. Click Update.
Exercise 22: Update the Attendee form
In this exercise you make the Email and Marketing Events fields mandatory on the Attendee form.

In a later exercise, you create an event that depends on the values of these mandatory fields.

1. Navigate to Marketing Event > Attendees.


2. Click New.
3. Right-click the form header and select Configure > Form Design.
4. Click the gear icon next to the Email field.
The Properties pop-up window appears.
5. Select Mandatory.
6. Close the Properties pop-up window.
7. Click the gear icon next to the Marketing Event field.
8. Select Mandatory and close the Properties pop-up window.
9. Click Save.
10. Close the Form Design tab.

How events work


An event is a message that a business rule creates when a particular set of conditions occur. Event handlers process events to take action using the values of
the event message. The platform typically uses events to pass information from one application to another.

Events consist of:

A unique name that indicates what triggered the event, such as incident.commented.
A copy of the object that triggered the event, such as the current or previous GlideRecord object.
One or more parameters to help the event handler process the event, such as field values in the current record or the user name of the person who
changed the record that triggered the event.
An event queue name to help administrators find particular types of events, such astext_index.

Event handlers listen to the event queue to identify matching events. When an event handler recognizes an event, it runs code or generates a notification,
depending on its logic. After processing the event, the system updates the status of the event and keeps the results available in the event log.

As a developer, you can use the following workflow to create and process events.

Create an after business rule to insert one or more events into the event queue when particular database operations and conditions occur.
Register each event created in the business rule.
Create one or more event handlers.
Create a script action to run when the system identifies a matching event.
Create a notification to run when the system identifies a matching event.
Review the event log to verify the system is properly generating and processing events.

Exercise 23: Create an event business rule


In this exercise you create a business rule to insert events into the event queue whenever someone creates, updates, or deletes an attendee record for a
marketing event.

Using a business rule that runs after database operations ensures the system has the most current information available for event processing. Your code
checks for each type of database operation that can change record data and then creates appropriate events.

1. Navigate to System Definition > Business Rules.


2. Click New.
3. Enter the following field values.

Field Value
Name Attendee Events

Table Attendee [x_snc_marketing_ev_attendee]

Advanced Selected

When After

Insert Selected

Update Selected

Script
function onAfter(current, previous) {
//This function will be automatically called when this rule is processed.
//Add event when attendee inserted
if(current.operation() == 'insert' && current.marketing_event.changes()) {
gs.eventQueue('x_snc_marketing_ev.attendee.added', current,
current.marketing_event, current.email);
}
//Add event when marketing event changes
if(current.operation() == 'update' && current.marketing_event.changes()) {
gs.eventQueue('x_snc_marketing_ev.attendee.deleted', previous,
previous.marketing_event, previous.email);
gs.eventQueue('x_snc_marketing_ev.attendee.added', current,
current.marketing_event, current.email);
}
//Add event when attendee deleted
if(current.operation() == 'delete') {
gs.eventQueue('x_snc_marketing_ev.attendee.deleted', current,
current.marketing_event, current.email);
4. Click Submit.

API components of the events business rule


The Attendee Events business rule uses these classes, objects, and methods.

Table 1. API components of the Attendee Events business rule

Class, object, or method Description

current.operation() A GlideRecord method that retrieves the current operation being performed, such as insert,
update, or delete. SeeGlideRecord.

current.marketing_event.changes() A GlideRecord method that indicates if an object changes value. In this case, the method
determines whether themarketing_event field changes value. See GlideRecord.

gs.eventQueue(x_snc_marketing_ev.attendee.added, A GlideSystem method that adds an event to the event queue. In this case, the method adds
current, current.marketing_event, current.email) thex_snc_marketing_ev.attendee.addedevent, passes the current object (an Attendee record),
and passes the current value of the marketing_eventand email fields. See GlideSystem.

previous An object that stores field values of the previous record. See Glide Script Objects.

previous.marketing_event previous.email A dot-walking reference to a particular field value of the previous record. In this case, it accesses
the values of themarketing event and email fields. SeeDot-walking.
Exercise 24: Register attendee events
In this exercise you register the events from the Attendee Events business rule that you created.

Registering an event allows an event handler to identify it in the event queue.

1. Navigate to System Policy > Events > Registry.


2. Click New.
3. Enter the following values.

Field Value

Suffix attendee.added

Table Attendee [x_snc_marketing_ev_attendee]

Fired by Attendee Events

Description Indicates an attendee was added to a marketing event.

4. Click Submit.
5. Click New.
6. Enter the following values.

Field Value

Suffix attendee.deleted
Table Attendee [x_snc_marketing_ev_attendee]

Fired by Attendee Events

Description Indicates an attendee was removed from a marketing event.

7. Click Submit.

Exercise 25: Test event creation


In this exercise you test your latest business rule to make sure it creates events under the proper circumstances.

1. Navigate to Marketing Event > Attendees.


2. Click New.
3. Enter the following field values.

Field Value

First name Alpha

Last name Beta

Email alpha.beta@example.com

Marketing Event Dallas LUG


4. Click Submit.
5. Click New.
6. Enter the following field values.

Field Value

First name Charlie

Last name Delta

Email charlie.delta@example.com

Marketing Event London LUG

7. Click Submit.
8. Click charlie.delta@example.com.
9. Change the Marketing Event to Dallas LUG.
10. Click Update.
11. Click New.
12. Enter the following fields.

Field Value

First name Echo

Last name Foxtrot

Email echo.foxtrot@example.com
Marketing Event Dallas LUG

13. Click Submit.


14. Select echo.foxtrot@example.com.
15. Click Delete.
16. From the Confirmation pop-up window, click Delete.
17. Navigate to System Policy > Events > Event Log.
18. Click the filter icon to display the filter controls.
19. Click AND.
20. Add the following filter row. [Name] [starts with] [x_snc].
21. Click Run.

Figure 1. System events generated from the event creation business rule
The system displays a list of events.

Common pitfalls during event creation


The events you created for exercises 23 and 24 intentionally avoided some common pitfalls that can occur during event creation. Here are some things to
consider when creating your own events.

Table 1. Event creation considerations

Symptom or error Root cause and solution

The system displays the following error Your business rule uses an event name that is missing the application namespace prefix. Make sure the
message when testing your business rule. business rule uses the full event name including the application namespace prefix.

Access to event event.name from scope For example, use the event namex_snc_marketing_ev_attendee.deleted rather than the event
Application Name has been refused. The nameattendee.deleted.
event is not defined.

The system displays the following error The system truncated the event name because it exceeded the maximum field length. By default, an event
message when testing your business rule. name can be a maximum of 40 characters long including the application namespace prefix. Make sure your
event name does not exceed the maximum length.
Access to event prefix.event.name from
scope Application Name has been For example, use the event namex_snc_marketing_ev_attendee.previous rather than the event
refused. The event is not defined. namex_snc_marketing_ev_attendee.marketing_event.previous.

Your events contain the wrong or outdated Verify the event business rule triggers after database operations.
information.
Exercise 26: Create Attendee script actions
In this exercise you create several script actions to automatically update the Attendees registeredfield of the affected marketing event.

1. Navigate to System Policy > Events > Script Actions.


2. Click New.
3. Enter the following field values.

Field Value

Name Add attendee

Event name x_snc_marketing_ev.attendee.added

Order 100

Active Selected

Script
//Get marketing event from event
var mrkevent = new GlideRecord('x_snc_marketing_ev_marketing_event');
mrkevent.get(event.parm1);
//Count attendees for marketing event
var numOfAttendees = 0;
var attendees = new GlideAggregate('x_snc_marketing_ev_attendee');
attendees.addQuery('marketing_event', event.parm1);
attendees.addAggregate('COUNT');
attendees.query();
if(attendees.next())
numOfAttendees = attendees.getAggregate('COUNT');
//Set attendees registered field
mrkevent.number_of_attendees_registered = numOfAttendees;
mrkevent.update();

4. Click Submit.
5. Click New.
6. Enter the following field values.

Field Value

Name Remove attendee

Event name x_snc_marketing_ev.attendee.deleted

Order 100

Active Selected

Script
//Get marketing event from event
var mrkevent = new GlideRecord('x_snc_marketing_ev_marketing_event');
mrkevent.get(event.parm1);
//Count attendees for marketing event
var numOfAttendees = 0;
var attendees = new GlideAggregate('x_snc_marketing_ev_attendee');
attendees.addQuery('marketing_event', event.parm1);
attendees.addAggregate('COUNT');
attendees.query();
if(attendees.next())
numOfAttendees = attendees.getAggregate('COUNT');
//Set attendees registered field
mrkevent.number_of_attendees_registered = numOfAttendees;
mrkevent.update();

7. Click Submit.

API components of the script action


The Add attendee and Remove attendee script actions use these API components.

Table 1. API components of the Show event cost UI action

Class, object, or method Description

get(event.parm1) A GlideRecord method that retrieves a particular record given a Sys ID value. In this case, the
event.param1 variable contains the Sys ID value. SeeGlideRecord.

GlideAggregate(x_snc_marketing_ev_attendee) A class for performing database aggregation queries, such as COUNT, SUM, MIN, MAX, and AVG. In
this case, the system makes aggregation queries available for the Attendees table.
SeeGlideAggregate.

addAggregate(COUNT) A GlideAggregate method to specify a database aggregation query. In this case, it is a COUNT
aggregation query. See GlideAggregate

getAggregate(COUNT) A GlideAggregate method to retrieve the value of a database aggregation query. In this case, it is a
COUNT aggregation query. See GlideAggregate

update() A GlideRecord method that saves any changes you have made to a GlideRecord object.
See GlideRecord.

Exercise 27: Test the Attendee script actions


In this exercise you test your two script actions to verify that they properly update the attendance of marketing events.

1. Navigate to System Policy > Events > Event Log.


2. Click the filter icon to display the filter controls.
3. Click AND.
4. Add the following filter row. [Name] [starts with] [x_snc].
5. Click Run.
Figure 1. Filtered event list
The system displays a list of events.

6. Click the Created column to sort the events.


7. Click the creation time of the earliest event.

The earliest event should be the creation of the alpha.beta@example.com attendee.

8. From Related Links, click Reprocess Event.


9. Repeat steps 7 and 8 for each event in the list.
10. Navigate to Marketing Event > Marketing Events.
11. Click Dallas LUG.
12. Check the value of the Attendees registered field.
Figure 2. Attendees registered for Dallas LUG

13. Navigate to Marketing Event > Marketing Events.


14. Click London LUG.
15. Check the value of the Attendees registered field.
Figure 3. Attendees registered for London LUG

The value should be 0.


Evaluate events and script actions
Our events and script actions meet the original business requirements

Table 1. Events and script actions compared to marketing requirements

Requirement Met? Evaluation

Rename Number of attendees registered to Attendees registered. Yes A field label on the form has a separate value from the
column name in the list.
The column name remains
number_of_attendees_registered.

Rename Number of attendees expected to Max capacity. Yes A field label has a separate value from the column name.
The column name remains
number_of_attendees_expected.

Add an event coordinator to each marketing event. Yes The reference field allows users to quickly select a value.
The event coordinator must always have a user record.

Count the number of attendees registered for each marketing event and Yes The script actions properly count marketing events
automatically populate the value on the form. during inserts, updates, and deletes.
Could make the Attendee field on the marketing event
form read-only.
03 Coding on ServiceNow - Module 9 - Events and notifications

Business requirements: notifications


Marketing event users have requested still more improvements.

The event coordinator needs the following communication.

An email message when the number of registered attendees is at the max capacity
An email message when the number of registered attendees is over capacity
A text message for each condition if email is unavailable

You meet these requirements by making the following changes.

Create a business rule to insert events in the event queue.


Insert an event whenever a marketing event is at attendee capacity.
Insert an event whenever a marketing event is over capacity.
Register the marketing event capacity events.
Create notifications to the event coordinator containing the following information.
The name of the marketing event
A link to the marketing event record
The maximum capacity of a marketing event
The number of attendees registered
An SMS message alternative
Exercise 28: Create another event business rule
In this exercise you create the Marketing Event Events business rule to add events when attendance meets or exceeds the maximum capacity of a marketing
event.

Earlier, you created the Attendee Events busines rule. It inserts an event whenever an attendee record is created, updated, or deleted.

1. Navigate to System Definition > Business Rules.


2. Click New.
3. Enter the following field values.

Field Value

Name Marketing Event Events

Table Marketing Event [x_snc_marketing_ev_marketing_event]

Advanced Selected

When After

Order 200

Insert Selected

Update Selected

Script
function onAfter(current, previous) {
//This function will be automatically called when this rule is processed.
//Add event when attendees reaches capacity
if(current.number_of_attendees_registered == current.number_of_attendees_expected) {
gs.eventQueue('x_snc_marketing_ev.at_capacity', current, current.sys_id,
current.event_coordinator);
}
//Add event when attendees exceeds capacity
if(current.number_of_attendees_registered > current.number_of_attendees_expected) {
gs.eventQueue('x_snc_marketing_ev.over_capacity', current, current.sys_id,
current.event_coordinator);
}
}

4. Click Submit.

Exercise 29: Register marketing event events


In this exercise you register the events from the Marketing Event Events business rule.

Registering an event allows an event handler to identify it in the event queue.

1. Navigate to System Policy > Events > Registry.


2. Click New.
3. Enter the following values.

Field Value
Suffix at_capacity

Table Marketing Event [x_snc_marketing_ev_marketing_event]

Fired by Marketing Event Events

Description Indicates a marketing event has reached capacity.

4. Click Submit.
5. Click New.
6. Enter the following values.

Field Value

Suffix over_capacity

Table Marketing Event [x_snc_marketing_ev_marketing_event]

Fired by Marketing Event Events

Description Indicates a marketing event is over capacity.

7. Click Submit.
Exercise 30: Create email notifications
In this exercise you create email notifications to inform the event coordinator when a marketing event has reached or exceeded capacity.

1. Navigate to System Policy > Email > Notifications.


2. Click New.
3. From Related Links, click Advanced view.
4. Enter the following values.

Field Value

Name At capacity

Table Marketing Event [x_snc_marketing_ev_marketing_event]

Send when Event is fired

Event name x_snc_marketing_ev.at_capacity

Weight 10

Event parm 2 contains recipient Selected

Subject Marketing event ${name} has reached capacity

Message HTML The marketing event ${URI_REF} has reached its attendee capacity of ${number_of_attendees_expected}.

SMS alternate ${name} has reached its capacity of ${number_of_attendees_expected}.


5. Click Update.
6. Click New.
7. Enter the following values.

Field Value

Name Over capacity

Table Marketing Event [x_snc_marketing_ev_marketing_event]

Send when Event is fired

Event name x_snc_marketing_ev.over_capacity

Weight 20

Event parm 2 Selected


contains recipient

Subject Marketing event ${name} is over capacity

Message HTML The marketing event ${URI_REF} is over capacity with ${number_of_attendees_registered} registered attendees and a max
capacity of ${number_of_attendees_expected}.

SMS alternate ${name} is over capacity with ${number_of_attendees_registered} attendees.

8. Click Update.
Exercise 31: Test email notifications
In this exercise you test whether your events generate the expected email notifications.

Steps 1-9 bring the event to capacity and reveal the resulting message.

1. Navigate to Marketing Event > Marketing Events.


2. Click Sydney LUG.
3. In Max capacity, enter 10.
4. In Attendees registered, enter 10.
5. Click Update.
6. After one minute, navigate to System Mailboxes > Outbound > Outbox.
Note: The system processes events in one-minute intervals.
7. Click the Created column to sort.
Figure 1. Outbox view with at-capacity email message

The subject of the first email message should be Marketing event Sydney LUG has reached capacity.

Note: The recipients email address was automatically populated from the Event Coordinator information associated with that marketing event.
8. Select the first email message.
9. Verify the Body field contains a link to a marketing event record and the capacity of the marketing event.
Figure 2. Body of at-capacity email message
Steps 10-16 place the marketing event over capacity and show the resulting message.

10. Navigate to Marketing Event > Marketing Events.


11. Click Sydney LUG.
12. In Attendees registered, enter 11.
13. Click Update.
14. After one minute, navigate to System Mailboxes > Outbound > Outbox.
Figure 3. Outbox view with over capacity email message

The subject of the first email message should be Marketing event Sydney LUG is over capacity.

15. Select this email message.


16. Verify the Body field contains a link to a marketing event record and the capacity of the marketing event.
Figure 4. Body of over capacity email message
Evaluate events and notifications
Our events and notifications meet the original business requirements.

Table 1. Events and notifications compared to marketing requirements

Requirement Met? Evaluation

Send the event coordinator an email message Yes The event coordinator gets emails when a
when the number of registered attendees is at marketing event reaches capacity.
the max capacity. Future enhancement: display an information
message whenever viewing a marketing
event record at capacity.

Send the event coordinator an email message Yes The event coordinator gets emails when a
when the number of registered attendees is over marketing event exceeds capacity.
capacity. Future enhancement: create a before
business rule to prevent inserts and updates
that exceed marketing event capacity.
Send the event coordinator text messages if Yes Each notification has an SMS alternative.
email is not available. Requires the event coordinator to set a
primary notification device: email or SMS.

03 Coding on ServiceNow - Module 10 - Debugging

Available debugging tools


All instances include the following debugging tools.

Table 1. Tools for debugging

Type Features Use to

JavaScript Debugger Set breakpoints Debug business rules and script includes.
See the call stack
See variable values
Edit code and save changes
JavaScript Log See the JavaScript log file Debug JavaScript that runs on the browser, such as
See transaction times client scripts.
Clear the contents of the log

Field Watcher See all actions the system performs on a field Determine how field values change while on a form.
See field values
See a dedicated log for a field

Scripts Background Run freeform code on the server Run JavaScript and test output.
module Select the application scope
See output and log messages

Session Debug modules Separate modules for common components Determine what components affect a given record or
See log output in the Debug Output pane at the bottom of table.
every page
See which components run or are skipped

Exercise 32: Create an alternate after business rule


In this example you create an alternate Calculate total cost business rule.

This business rule has a flaw in it that you uncover and fix during debugging later.
1. Navigate to System Definition > Business Rules.
2. Click the Updated colum to sort by the most recent updates.
3. Click Calculate total cost.
4. Clear the Active checkbox.
5. Click Update.
6. Enter the following field values.

Field Value

Name Debug total cost

Table Marketing Event [x_snc_marketing_ev_equipment_request]

Advanced Selected

When After

Insert Selected

Update Selected

Script
function onAfter(current, previous) {
//This function will be automatically called when this rule is processed.
var cost = 0;
var budget = current.budget;
var mrkevent = current.sys_id;
var evtname = current.name;
//Get the total cost of equipment for this event
var equipment = new GlideRecord("x_snc_marketing_ev_equipment_request");
equipment.addQuery("marketing_event", mrkevent);
equipment.query();
while(equipment.next()){
cost = cost + equipment.cost;
}
//Compare cost to budget
if(cost > budget){
gs.addErrorMessage('Equipment costs for ' + evtname + ' exceed the event
budget.');
}
//Populate cost
current.event_cost = cost;
//Populate Budget remaining
var remaining = budget - cost;
current.budget_remaining = remaining;
current.update();
}

7. Click Submit.

Exercise 33: Use the JavaScript debugger


In this exercise you track down some coding errors with the JavaScript debugger.

Important: This exercise works best with a Firefox browser. Some features, such as breakpoints, may not work with a Chrome browser.

In steps 1-10 you open the Debug total cost business rule in the JavaScript debugger and set four break points.

1. Navigate to Marketing Event > Marketing Events.


2. Click Dallas LUG.
3. From the banner frame, click the gear icon next to the Logout button.
4. Scroll to the bottom of the menu, and click JavaScript Log and Field Watcher.
The system displays a new pane at the bottom of the form.
5. Click the JavaScript Debugger tab.
6. Click Scripts.
7. In Search, enter Debug.
The system displays scripts containing debug in the name.

8. From the search results, click Debug total cost.


The system displays the JavaScript code in an editable pane.
9. From the left pane, click Breakpoints.
10. In the edit pane, click slightly to the left of lines 8, 11, 15, and 23 to add breakpoints.
Business rule with four breakpoints.

In steps 11-22 you update a Marketing Event. You then run the Debug total cost business rule through four breakpoints, observing the changes to variables and
field values at each break.

11. On the Marketing Event form, change the Max capacity to 12.
12. Right-click the form header and click Save.
The system runs the Debug total cost business rule until it reaches the first breakpoint at line 8.
13. From the right pane, click Variables.
14. Expand the Local section.
The JavaScript debugger displays the values of local variables.

15. Expand the current ScopedGlideRecord object.


The JavaScript debugger displays field values for the current object.
16. Note the value of the cost variable is 0, and the value of Budget_remaining field in the current record is -300.
17. From the left pane, under the Breakpoints button, click the Go icon to advance to the next breakpoint at line 11.
18. Notice there have been no changes in variable or field values.
19. Click Go to advance to the next breakpoint at line 15.
20. Notice that the value of the cost variable changed to 02000300.
21. Click Go to advance to the next breakpoint at line 23.
22. Notice that value of the budget_remaining variable changed to -1998300 and the value of the event_cost field changed to 2000300.
23. From the left pane, click the Toggle debugger On | Off icon to stop debugging the script include.

Evaluate debugging results


Our debugging results indicate that the business rule is not generating the cost of marketing events correctly.

Table 1. Business rule debugging results


Observation Evaluation Recommendation

The cost variable changed from 0 to 02000300. The calculation at line 12 does not properly generate the cost Update the calculation to use
of a marketing event. numeric values.
It should have changed to 2300.
It appears the calculation uses string values rather than
numeric values.

The budget_remaining andevent cost fields These values are derived from the calculation at line 12. Fixing the cost calculation should fix
display incorrect values. these values.

Exercise 34: Fix the cost calculation


In this exercise you update the cost calculation and then use the debugger to determine if your changes produced the correct results.

In steps 1-11, you edit a line of code in the debugger, update an event record in the application, and then advance to the first breakpoint in the debugger.

1. Navigate to Marketing Event > Marketing Events.


2. Click Dallas LUG.
3. If the JavaScript debugger is not already open, open it.
4. If the JavaScript debugger does not already display the Debug total cost business rule, open it.
5. From the middle pane, change line 12 to cost = cost + equipment.cost.getCurrencyValue();.
Figure 1. Edit to line 12
6. From the middle pane, click Save.
7. From the left pane, click the Toggle debugger On | Off icon to enable debugging.
8. In the edit pane, click slightly to the left of lines 8 and 11 to remove their breakpoints.
The only remaining breakpoints are at lines 15 and 23.
9. On the Marketing Event form, change the Max capacity to 11.
10. Right-click the form header and click Save.
The system runs the debug total cost business rule until it reaches the first breakpoint at line 15.
Figure 2. Breakpoint line 15
11. Notice that the value of the cost variable is still 02000300.

In steps 12-19, you make a different change to the same line of code, and then step through the breakpoints in the debugger to determine if your change fixed
the calculation error.

12. From the middle pane, change line 12 to cost = cost + parseFloat(equipment.cost);.
Figure 3. Change to line 12
13. From the middle pane, click Save.
14. From the left pane, click Go to advance to the next breakpoint at line 23.
15. Click Go again to advance to the next breakpoint at line 15.
16. Note the value of the cost variable changed to 2300.0
Figure 4. Breakpoint line 15
17. Click Go to advance to the next breakpoint at line 23.
18. Notice that the value of the budget_remaining field changed to -300 and the value of theevent_cost field changed to 2300.
Figure 5. Breakpoint line 23
19. From the left pane, click the Toggle debugger On | Off icon to stop debugging the business rule.

In steps 20-32, you return to the Marketing Event application, update both an equipment request and an event, and then step through the breakpoints in the
debugger to confirm that costs are still calculating correctly.

20. Navigate to Marketing Event > Equipment Requests.


Figure 6. Equipment Requests table
21. Click the AV record with a cost of $2000.00.
22. Change the Cost from $2000.00 to $1000.51.
23. Click Update.
24. Navigate to Marketing Event > Marketing Events.
25. Click Dallas LUG.
26. From the left pane, click the Toggle debugger On | Off icon to enable debugging.
27. Change the Max capacity to 12.
28. Right-click the form header and click Save.
The system runs the debug total cost business rule until it reaches the first breakpoint at line 15.
Figure 7. Breakpoint line 15
29. Notice that the value of the cost variable changed to 1300.51.
30. Click Go to advance to the next breakpoint at line 23.
31. Notice that the value of the budget_remaining field changed to 699.49 and the value of the event_cost field changed to 1300.51.
Figure 8. Breakpoint line 23
32. From the left pane, click the Toggle debugger On | Off icon to stop debugging the business rule.
Evaluate fix results
Our fix results indicate that the original cost calculation could be simplified.

Table 1. Business rule fix results

Observation Evaluation Recommendation

The cost calculation in the Debug total cost business rule generates the same The getCurrencyValue()method is not Remove the
results as the Calculate total costbusiness rule, but with less code. necessary in our business rule cost unnecessary
calculation. method call.

03 Coding on ServiceNow - Module 11 - Considerations and conclusions

Evaluate coding components


The following table summarizes the coding components you worked with in this training.

Table 1. Summary of coding components

Coding Good for Future considerations


component
Automating record processing Business rules ensure record processing always occurs no matter
Business
Specifying when to take action, such as before or after a the input source.
rules
database operation A business rules table determines what records are available to
Validating data the current object.
Inserting events into the event queue A tables scope and access settings determine whether you can
create a business rule for it.
You can create multiple types of business rules on the same table.
There are many existing event business rules to use.

Script Reusing server code Functions are good candidates for script includes.
includes Allowing client access to server code There are many existing script includes to use.
Editing existing script includes may break existing functionality.

Events Taking action when certain database operations occur Events are not a good choice for schedule-driven conditions.
Communicating with other applications SeeScheduled Jobs instead.
Notifications do not require creating custom events. SeeEmail
Notifications.

Script actions Taking action when events occur Script actions are intended for event handling.
Adding business logic to records that do not directly allow Notifications do not use script actions.
coding

UI actions Allowing the user to take action on records UI actions are intended for optional actions.
Actions that require a users decision Require screen presentation in the user interface.
UI actions can run code from the server side, client side, or both.
Validating data before submitting it to the server Client scripts should not duplicate logic in UI policies.
Client scripts Reducing queries to the database Client scripts do not affect non-interactive input sources, such as
web services.
Use the GlideAjax class to improve performance of server-side
calls.
Client scripts do not run in a specific order.

UI policies Enforcing data integrity by making form elements read- UI policies can conflict with or overwrite client scripts logic. Avoid
only, required, or hidden duplication.
Quickly changing form elements without having to write UI policies do not affect non-interactive input sources, such as web
code for each element services.
UI policies apply only to fields on the form. Be sure to add
necessary fields to the form.

Evaluate API components


The following table summarizes the API classes and objects you worked with during this training.

Table 1. Summary of API components

Coding Good for Future considerations


component

GlideRecord Getting data from tables Each GlideRecord query requires database access and resources.
Performing database operations on records Avoid complex queries of large data sets to prevent performance
issues.
There are many methods to use.

GlideSystem Getting information about the system Each GlideSystem query requires database access and resources.
Displaying information, warnings, and errors There are many methods to use.
Adding events into the event queue

GlideAggregate Performing calculations on records Each GlideAggregate query requires database access and
Server-side calculations resources.
There are many methods to use.

current Working on current record values Each table has its own current object.
Business rules Use GlideRecord to compare records in one table to another.

previous Working on previous record values Each table has its own previous object.
Business rules Use GlideRecord to compare records in one table to another.

Dot-walking Getting the value of specific fields Dot-walking requires a GlideRecord object.
Getting information from a related table through a Dot-walking requires knowing a tables underlying dictionary
reference field schema.

g_form Working on field values before submitting them to the This class only applies to data on a users browser.
server This class no effect on non-interactive inserts and updates, such as
Enforcing data integrity from the UI web services.
Further challenges
Improve your skills by attempting these tasks on your own.

Create a record producer for the Attendees table to allow people to sign up for marketing events.
Create a field to track a marketing events status, such as New, Planning, and Complete.
Create a business rule to automatically set a marketing events status based on whether it has a budget, sponsor, and attendees.
Send an email notification to the event coordinator one week before a marketing event is scheduled to start.

04 Building a sample ServiceNow application - Exercise 1 - Creating an


application

Application Requirements
To help meet the needs of the event coordinators and all stakeholders for the event, build an application on the ServiceNow platform with the following
capabilities.

Table 1. Application requirements


Stakeholder Requirements

Marketing events manager Centralized location to manage all details of the event, including
required equipment, attendee lists, and attachments.
Ability to provide real-time status

Marketing people manager Visibility into all aspects of the event


Ability to track performance

IT administrator Easy data import from legacy systems


Integration with corporate LDAP
Ability to enforce security rules
Automatic platform upgrades

Attendee Self-serve, intuitive registration process


Timely email reminders

Create the application


Create an application based on sample application requirements.

Obtain access to an instance and log in as administrator.


1. Navigate to System Applications > Applications.
2. Click New.
The Getting started building applications home appears.

3. Next to Start from scratch, click Create.


The Create Application from Scratch form opens.
4. Enter the name Marketing Events Application.
The Scope field is populated automatically.

5. Click Create and click OK to confirm that you want to create the application.
Figure 1. Confirm application
The Marketing Events Application is created and the Application Creation: Successwindow appears.

Note: When you create an application, the Application Creator creates a new role (called u_marketing_events_application_user) that you can assign to
users who need access to this application.
6. Click View app record.
The Marketing Events Application opens.
Figure 2. Marketing Events Application
You have a new application but it doesnt do anything yet. In the next exercise, you will start to make the application functional.

04 Building a sample ServiceNow application - Exercise 2 - Creating the


database tables
Required tables
ServiceNow provides a relational database model for business objects. You can store the attributes of a business object and the relationships between them.

The sample application you will be building requires three database tables:

Marketing Event
Equipment request
Attendee

The Marketing Event table has a one-to-many relationship with the Equipment Request table and the Attendee table.

Create the Marketing Event table


Build the Marketing Event table, the first component of your application.

1. From the Marketing Events Application, scroll to the Tables section and click New.
2. Enter Marketing Event in the Label field.
The Name field populates automatically, based on the label and application name.
3. Create the columns for the table, using the following information.

Column label Type Display

Name String true


City Choice false

Start Date Date false

End Date Date false

Budget Currency false

Sponsor String false

1. Double-click Insert a new row.

2. Enter a column label and click the checkmark.


3. Double-click the space under Type, enter a type, and click the checkmark.
4. Double-click the space under Display, set to either true or false, and click the checkmark.
Note: When you set Display to true for Name, the user-friendly value for the event name displays, rather than the unique system-generated ID number.
The generated ID is used by the system when a record references a marketing event.
4. Click Submit.

You have created the first of the three required tables.


Create the Equipment Request table
Build the Equipment Request table, the second table for your application.

1. From the Marketing Event Application, scroll to the Tables section and click New.
2. Enter Equipment Request in the Label field.
The Name field is filled in automatically, based on the label and application name.

3. In the Extends table field, select Task.


4. In the Add module to menu field, select Marketing Event.
5. Create the table rows, using the following information.
Column lab Type Reference Display

Type String true

Cost Currency false

Needed From Date false

Needed Until Date false

Marketing Event Reference Marketing Event false

Note: The Marketing Event field is a reference to the Marketing Event table. A reference field creates a relationship between two tables and allows you to
display information from another table. It is similar to the primary and foreign keys in a relational database. In this case, a particular piece of equipment is
related to a particular marketing event.
6. Click Submit.

You have created the second of the three required tables. The third table, Attendee, is created inExercise 7: Extending the data model.

04 Building a sample ServiceNow application - Exercise 3 - Building the


user interface
Configure the Marketing Events list
Change the order of the columns in the table list.

1. Navigate to Marketing Event > Marketing Events.


2. Right-click the column heading and select Configure > List Layout.
3. Use the Move up and Move down arrows to arrange the column headers in the Selected list in the following order: Name, City, Budget, Sponsor, Start Date,
and End Date.
4. Click Save.
5. Click New.
A form appears. You will configure the form in the next exercise.

Configure the Marketing Events form


Configure the Marketing Events form.

1. Right-click the title bar of the Marketing Events form and select Configure > Form Design.
2. Drag and drop the items in the order you want them to appear.
3. Add city values.
1. Hover over the City field and click the gear icon.
2. In the Properties dialog box, click Create choices.
3. For Choice 1, 2, and 3, enter Dallas, Kansas City, and London.
4. Click in the empty row and create new entries for San Jose, Portland, andSydney.
5. Close the Properties dialog box.
4. Make the Name field mandatory.
1. Hover over the Name field and click the gear icon.
2. Select the Mandatory check box.
3. Close the Properties dialog box.
5. Click Save.
6. On the Marketing Event form, right-click the title bar, and select Reload form.

Configure the Equipment Requests list


Change the order of the columns in the table list.

1. Navigate to the Marketing Event Application > Equipment Requests.


2. Right-click a column header and select Configure > List Layout.
Because the Equipment Request table extends from the Task table, there are a number of fields in the Available list and a smaller number of fields in
the Selectedlist.
3. Remove the default fields from the Selected list by double-clicking the field names.
Note: Removing fields with personalization does not change the table structure.
4. Add the following fields to the Selected list: Type, Cost, Needed From, and Needed Until, and Marketing Event.
Note: Selecting Marketing Event without expanding it adds a reference field to the table.ServiceNow displays tables in green text with a [+] next to the table
name.
5. Click Save.
6. Click New.

A form appears. You will customize the form in the next exercise.

Configure the Equipment Request form


Customize the Equipment Request form to improve its workflow.

1. Right-click the form header and select Configure > Form Design.
2. Drag and drop the items in the order you want them to appear.

3. Click Save.
04 Building a sample ServiceNow application - Exercise 4 - Adding event
records

Create the event records


Populate the tables with event information.

1. Navigate to Marketing Events Application > Marketing Events.


2. Create event records containing the following information:

Name City Budget Sponsor Start Date End Date

London LUG London $6000.00 Platinum Partners 2015-05-01 2015-05-01

Dallas LUG Dallas $2000.00 Dallas Partners 2015-05-15 2015-05-18

1. Click New.
2. Populate the fields.
3. Click Submit.
3. Navigate to Marketing Events Application > Equipment Requests.
4. Click New.
5. Create event records containing the following information:

Type Cost Needed From Needed To Marketing Event

AV $1000.00 2015-05-01 2015-05-01 London LUG


Wireless Mic $300.00 2015-05-01 2015-05-01 London LUG

AV $1000.00 2015-05-15 2015-05-15 Dallas LUG

Wireless Mic $300.00 2015-05-15 2013-05-15 Dallas LUG

1. Click New.
2. Populate the fields.
3. Click Submit.

Associate events with equipment requests


Configure related lists so that you can see events and equipment requests on the same page.

1. Navigate to Marketing Events Application > Marketing Events.


2. Click New.
3. Right-click the header of the event and select Configure > Related Lists.
4. From the Available list, double-click the Equipment Request > Marketing Event list.
You can also add the Attachments related list. This is a built-in functionality that allows you to add a file, document, or image to a record.
5. Click Save.
The related Equipments Requests now appear at the bottom of the form.
04 Building a sample ServiceNow application - Exercise 5 - Creating
reports and dashboards

Create a report
Build a calendar report to display the upcoming marketing events in a calendar view.

1. Navigate to Reports > View/Run.


2. Click Create a report.
3. Fill in the new report form with the following information.

Field Value to use

Report title Marketing Events Calendar

Type Calendar

Data > Table Marketing Event [x_snc_marketing_event]

Calendar by Start Date

4. Click Run.
5. Click Save.
04 Building a sample ServiceNow application - Exercise 6 - Importing
data

Create a CSV file for import


Create a comma-separated values (CSV) file with event information, which you can use to import data into the database.

Create a comma-separated values (CSV) file using the following data.

Name City Start date End date Budget Sponsored by

Sydney LUG Sydney 2014-06-22 2014-06-22 2000 ANZ Partner

Dublin Launch Dallas 2014-05-23 2014-05-23 1000 TX Partner

Dublin Workshop London 2014-05-24 2014-05-24 20,000 UK Partner

Note: There is a close match to the columns in the CSV file and the column names in the Marketing Event table. You will import this data into the Marketing
Event table.
Import the data
Load the data from a spreadsheet into the marketing events table.

1. In the left navigation pane, navigate to System Import Sets > Load Data.
2. Select Create table.
3. Enter the following information.

Field Value to use

Label Marketing Events CSV

Table name Populates automatically

Source of import File

File Path to your CSV file

Sheet number 1

Header row 1

4. Click Submit.
ServiceNow displays a success message after importing the file.

After you import the data, create the transformation logic.


Run the transform
Build the transformation logic to map data from the staging table to a target table.

A transform takes data from the staging table, maps it according to the transform logic, and loads it into the target table.

1. Below the Next steps heading, click Create transform map.


2. Fill in the Table Transform Map with the following information and click Submit.

Field Value to use

Name Marketing Event CSV 2 Table

Source This field populates automatically.

Target table Marketing Events [x_snc_marketing_event_marketing_event]

3. In Related Links, click Auto map matching fields.


ServiceNow adds the Field Maps related list.
4. In Related Links, click Mapping Assist.
5. Drag and drop the Sponsored by and Sponsor fields from the center Field Map column so that Sponsored by is in the left column and Sponsor is in the right
column, and click Save.
6. Verify that any incoming dates are in a format ServiceNow recognizes.
1. From the Fields Maps list, click u_start_date.
2. If the default date format does not match the date format in the CSV source file, click the light bulb icon to select a new date format.
3. Select the yyyy-MM-dd format to match the date format in the CSV file and clickUpdate.
7. Verify that any end dates are in a format ServiceNow recognizes.
1. From the Fields Maps related list, click u_end_date
2. If the default date format does not match the date format in the CSV source file, click the light bulb icon to select a new date format.
3. Select the yyyy-MM-dd format to match the date format in the CSV file and clickUpdate.
8. In the Related Links list, click Transform.
ServiceNow displays the import set and transform map to be used in the transform.
9. Click Transform.
ServiceNow takes data from the temporary staging table and uses the transformation logic to insert new records in to the marketing event table.

04 Building a sample ServiceNow application - Exercise 7 - Extending the


data model

Add fields to the Marketing Event table


Add fields to the Marketing Event table so you can capture the number of attendees expected and the number of attendees registered.

1. To return to the Marketing Event table, click the gear icon in the upper right, scroll to the Application section and click the information icon (i).
2. Click the Marketing Event table.
3. Create the fields with the following information.

Column label Type Display

Number of attendees expected Integer false

Number of attendees registered Integer false

1. Double-click Insert a new row.


2. Enter a column label and click the checkmark.
3. Double-click the space under Type, enter a type, and click the checkmark.
4. Double-click the space under Display, set to either true or false, and click the checkmark.
4. Click Update.

Create the Attendee table


Create the third database table, the Attendee table, to capture attendee information.

1. Scroll to the Tables section and click New.


2. Enter the label Attendee.
The Name field is filled in automatically, based on the label and application name.
3. Create the table rows, using the following information.

Column Label Type Reference Display

First name String false

Last name String true

Email String false

Phone String false

Marketing Event Reference Marketing Event false

4. Click Submit.
5. Navigate to Marketing Events Application > Attendees.
6. Add a few attendees.
1. Click New.
2. Enter attendee information.
3. Click Submit.

04 Building a sample ServiceNow application - Exercise 8 - Using


ServiceNow Email

Create an email template


Create an email template so you can email for each attendee without having to hard-code values.

1. Navigate to System Policy > Email > Templates.


2. Click New.
3. Enter the following information.

Field Value to use

Name Marketing Event Registration

Table Attendee [x_marketing_events_attendee]

Subject Thank you for registering for ${u_marketing_event.u_name}


Message Dear ${u_first_name},

This is to confirm that you are registered for


${u_marketing_event.u_name}. We look forward to seeing you at the
event. If you have any questions, please contact the event team at 1-888-
555-1212.

Thank you!

4. Click Submit.

Create an email notification


Create an email notification to send a confirmation email to users when they register for your event.

1. Navigate to System Policy > Email > Notifications.


2. Click New.
3. Enter the following information. Keep the default value for the remaining fields.

Field Value to use

Name Marketing Event Email Attendee

Table Attendee [x_marketing_event_attendee]

Active True (checkmark)


When to send > Inserted True (checkmark)

When to send > Updated True (checkmark)

Who will receive > Users/Groups in fields Email

What it will contain > Email template Marketing Event Registration

4. Click Submit.

Add a few test attendee records to test the email notification functionality. Navigate to System Mailboxes > Outbound > Sent to see the email
records ServiceNowgenerates. It may take 15-30 seconds for messages to show up. You may also want to check Outlook.

04 Building a sample ServiceNow application - Exercise 9 - Using the


service catalog

Service Catalog
Using the ServiceNow platforms built-in Service Catalog ensures that users have a single interface for all of their request-based needs without having to
navigate multiple applications and interfaces.

The application you have built so far is a big hit with the marketing department. Spurred by that initial success, they want to expand the application to solve
other common issues they face.

Currently, requests to hold marketing events arrive via email to sales managers. These requests are often missing key information and are rarely handled
consistently. Marketing now want requestors to fill out an online form instead of using current inconsistent methods. The marketing department can then
receive, review, and track the requests online, and process them more consistently and efficiently.

There are two ways that you can implement these changes:

Give access to the existing application to the sales managers


Create a service catalog request process

In this exercise, you will create a service catalog item for the application.

Create a record producer


Create a record producer. Before you can add your application to the Service Catalog, you have to publish it. To publish an application, you must first create a
record producer.

A record producer creates an input form within the Service Catalog to capture requests and then uses the request data to create a new record in a destination
table. For our purposes, we want a record producer that creates new records in the Event Marketing table when someone uses the Service Catalog to request a
new event.

1. Navigate to Service Catalog > Catalog Definitions > Record Producers.


2. Click New.
3. Enter the following information.

Field Value to use

Name Request Marketing Event


Table name Marketing Event [x_marketing_events]

Accessibility > Catalogs Service Catalog

Accessibility > Category Services

What it will contain > Description Please fill out the details to request a marketing event in your region. The
marketing team will review your request and get back to you.

4. Click Submit.

Complete the Service Catalog item


In this exercise you will create variables within the record producer to record required data and add it to the table you configured within the record producer.

1. From the Record Producers list, click Request Marketing Event.


2. Create the following records.

Type Order Question > Name Question > Question Reference

Reference 100 u_requested_by Your Name User [sys_user]

Single Line Text 200 u_name Event Name

Single Line Text 300 u_sponsor Event Sponsor


Single Line Text 400 u_city City

Date 600 u_start_date Event Start Date

Date 700 u_end_date Event End Date

Single Line Text 800 u_number_of_attendees_expected Number of Attendees


Expected

Single Line Text 900 u_budget Expected Budget

1. From the Variables list, click New


2. Enter the record information.
3. Click Submit.

04 Building a sample ServiceNow application - Exercise 10 - Publishing


your application

Publish the application


In this exercise you will publish your application to an XML file, which packages all the artifacts related to the application and allows you to move it between
environments.

Typically, enterprises using ServiceNow have separate environments (or instances) to support development, test, and production. This ensures production
users are insulated from changes before they are thoroughly tested.

1. Navigate to System Applications > Applications.


2. Click Edit next to Marketing Events Application.
3. Under Related Links, click Publish to Update Set.

4. Enter the following information.

Field Value to use

Application name Popuated automatically

Version Populated automatically

Description My first application on the ServiceNow platform


Include demo data True (checkmark)

5. Click Publish.
ServiceNow creates a package with all the artifacts related to our application.
6. Click Done.
7. Under Related Links, click Export to XML and save the file to your computer.

Import the application into a different instance


Import your application into other instances, which makes it available to different users.

1. Log into another instance.


2. Navigate to System Update Sets > Retrieved Update Sets.
3. Under Related Links, click Import Update Set from XML.
4. Browse for the update set that contains your application and click Upload.
ServiceNow processes the update set.
5. Click Preview Update Set.
Preview allows you to validate the contents of the update set in the new instance. If there are conflicts that cause errors, you must decide how to handle
them.
6. Do one of the following actions.

Option Description

If there are Examine each error in the Update Set Preview Problems list, and accept or skip the update responsible for it.
errors
Note: You can decide row by row, using the Available Actions column, or you can select multiple rows and make a group decision
via the Actions on selected rows choice list.

After resolving all errors, click Commit Update Set.

If there are no Click Commit Update Set.


errors

7. From the application navigator, select Refresh.


8. Navigate to the Marketing Events Application and check the application.

04 Building a sample ServiceNow application - Exercise 11 - Building


workflows and approvals

Build a workflow
Build a workflow for approving and rejecting requests.

Business processes are often implemented by a combination of e-mail, conversations, and other inefficient, manual methods. Workflows can automate this,
resulting in increased efficiency and reduced errors. Additionally, workflows provide an audit trail, which can be critical for an application that has to comply with
internal or external regulations.

In this sample scenario, the marketing VP has to approve the request for any equipment that costs over $500. As soon as a user enters request for an
equipment costing over $500, the workflow you create is triggered. This is a very simple, but common, scenario. The platform workflow capabilities allow
complex criteria for triggering, approvals, branching as well as integration with external systems.

1. Navigate to Service Level Management > Administration > Workflow Editor.


2. Click the + icon on the Workflows tab to create a new workflow.

3. Enter the following information, leaving the rest of the fields with default values.

Field Value to use

Name Equipment Request Workflow


Table Equipment Request

Condition [Cost] [greater than] [500] [USD]

4. Click Submit.
An empty workflow appears. On the right is the palette of tasks and other activities that you can add to the workflow.
5. Click the Core tab and expand the Approvals folder, then drag the Approval-User activity between Begin and End.
6. Enter the name Get VIP Approval.
The New Activity: Approval User form appears.
7. Click the Users lock icon and search for a user (for example, Fred Luddy).
Note: You can send the request to a particular person (for example, Fred Luddy) or group (for example, Procurement).
8. Click Submit.
The workflow is updated.
9. Create a point on the workflow for Set Status to Requested.
1. In the Utilities folder, navigate to Set Values.
2. Drag and drop Set Values between Begin and Approval User.
The New Activity: Set Values window appears.
3. Enter the name Set Status to Requested.
4. Select Approval from the choose field choice list and Requested from the Nonechoicelist.
5. Click Submit.
The workflow is updated.
10. Create a point on the workflow for Set Approval to Approved.
1. Drag and drop Set Values between Approved User and End.
2. Enter the name Set Approval to Approved.
3. Select Approval from the choose field choice list and Approved from the Nonechoice list.
4. Click Submit.
The workflow is updated.
11. Create a point on the workflow for Set Approval to Rejected.
1. Drag and drop Set Values between Approval User Rejected and End.
2. Enter the name Set Approval to Rejected.
3. Select Approval from the choose field choice list and Rejected from the Nonechoicelist.
4. Click Submit.
The workflow is updated and the Set Values node for Set Approval to Rejected is added to the workflow but it is not connected to Approval
User and End.
12. Connect the Set Values node for Set Approval to Rejected.
1. Click Rejected in the Approval User node and draw the line to the Set Values node for Set Approval to Rejected.
2. Click Always in the Set Values node for Set Approval to Rejected and draw the line toEnd.

You can track the status of the workflow in a field on the record itself by using the Approval field from the task table. The equipment table extends task so you
have access to all the fields in the task table. This field can have four possible values:

Not Yet Requested


Requested
Approved
Rejected

Publish a workflow
In this exercise you will publish the workflow you created to make it accessible to users.

1. Click the hamburger icon in the title bar and select Publish.
2. Click OK.
The status at the top shows Published.
3. Add an Approval field to the Equipment Request table list and form.
Note: Refer to Lab 3 if you have forgotten how to configure list and form views.
4. Test the approval process.
1. Enter an equipment request for more than $500.
2. Select Requested for the Approval value.
3. Click Submit.
Approve a workflow request
Approve a workflow request using the system administrator role.

1. Navigate to My Approvals.
The list view of all approval requests appears.
2. Click the Requested link for the recently submitted request.
3. Approve the request.
Note: In this example you can change the approval field status directly. In a real-world scenario, you may want to make this field read-only for the user who
submits the request.
The state changes on the next screen. The state is also reflected in the equipment list view.

04 Building a sample ServiceNow application - Exercise 12 - Securing the


application

Security basics
The ServiceNow platform provides a variety of administrative controls and a fine-grained application security model to secure your applications.
The diagram below depicts one way to think about the security of the applications and some of the platform capabilities provided to address it. At the bottom are
the controls that are mandated by your companys security policies. On top of that may be industry-specific requirements and best practices. These two layers
may be common across multiple applications. Finally, there is application-specific security that controls access to individual application.

The platform security capabilities should not be looked at in isolation, but should be used together to secure the application. Though in this tutorial we have
deferred security to a later chapter, as a best practice you should understand the security requirements for your applications and incorporate them into the early
stages of the implementation cycle.

Roles and Access Control Lists


Roles and access control lists (ACLs) are two of the capabilities provided by the ServiceNowplatform to secure your applications.

A role is a category that can be assigned to a user, and can be granted access to particular parts of the system in this case, the marketing event application.
When you used the application creator in exercise 1, it created a new role, called u_marketing_events_application_user) that you can assign to users who need
access to this application. By defining a role, you give visibility to the application only to users in that role. However, you may want to further restrict what a
particular role or user is allowed to do.

Access control lists are one of the mechanisms provided to restrict access at a fine level of granularity.

Test application security


In this exercise you will ensure that the access controls and roles applied to your application work properly.

1. Impersonate a user (Beth Anglin) who doesnt have the u_marketing_events_application_user role and verify that the Marketing Event Application isnt
visible.
1. Click the Impersonate icon.
2. Search for Beth Anglin and click OK.

3. Verify that the Marketing Event Application is not visible.


2. Go back to the System Administrator role and give Beth the role u_marketing_events_application_user.
1. Navigate to Users and search for Beth Anglin.
2. Click Edit in the Roles section.
3. In the form, add u_marketing_events_ application_user from the bucket on the left to the bucket on the right.
4. Click Save.
3. Impersonate Beth again. Verify that the application is visible.
04 Building a sample ServiceNow application - Exercise 13 - Making your
application mobile

Create a mobile-specific view


In this exercise you will create a view for your application that is optimized for a mobile-device.

When access is through a mobile device, the screens are automatically reformatted to make your application more mobile-friendly. Below is a non-mobile-
specific view:

Figure 1. Non-mobile specific view of the Marketing Events application


1. Navigate to the Marketing Events Application.
2. Click the Application Menus tab.
3. Click Marketing Events.
4. Click New next to Modules.
5. Enter the following information and click Submit.

Field Value

Title Event List Mobile

Link Type > Table Marketing Event

Link Type > View Name Mobile

A new module appears in the list.


6. In the application navigator, select the new module.
7. Right-click any of the column headers and select Configure > List Layout.
8. Remove all columns from the Selected list except Name and City and click Save.
9. Access this view from a mobile browser.
You should only see two fields.
Figure 2. Mobile-specific view of the Marketing Events application
ServiceNow iPad interface
Test your mobile-device user interface on an iPad.

For Apple iPad users, the ServiceNow platform delivers an iPad-specific view. The UI on the iPad looks and feels more like a native application than just
browser-based access. The platform recognizes it if you access an application from an iPad and automatically sends an iPad-specific view. The figure below
shows the iPad view of the Marketing Event form.

Figure 1. iPad interface


04 Building a sample ServiceNow application - Exercise 14 - Making your
application social
Configure live feed for events
Configure a live feed for events that allows you to track conversations.

Most real-world business scenarios involve some form of ad-hoc conversation and problem solving with various stakeholders. In the case of event management
application, it may be finding a person to cover an event, sharing some insight with the team, or other related tasks. This is typically done outside of the
application via email.

The problem with this approach is that context is lost. Having the conversation inside the application means greater immediacy and contextual relevance. If, for
example, the conversation is around a specific event in a specific location, the conversation can focus on the relevant record.

1. Navigate to the Marketing Events table.


2. Scroll to the Controls section and select the Live Feed checkbox.
3. Click Update.
4. Open a record in the Marketing Events table.

5. Click the Live Feed icon.


The Live Feed window appears. You can now have a conversation about the event.

04 Building a sample ServiceNow application - Exercise 15 - Writing


business rules
Write a business rule
In this exercise you will write a business rule to calculate the number of attendees and update the registered attendee field on the marketing event table.

The ServiceNow Service Automation Platform is designed to help you build your application declaratively (with mouse clicks) instead of writing code. However,
there may be instances where the declarative features are not sufficient. In such cases, you can use JavaScript code to create business rules. Almost
all ServiceNow platform capabilities (including workflow, security, UI, and database) can be customized with a business rule.

In this exercise, you will look at one of the more common scenarios that can benefit from custom code, in conjunction with a database operation like insert,
update or delete. Business rules can be made to execute before or after a database operation. If you are familiar with relational database triggers, you will
notice that business rules are similar to triggers in relational databases.

Note: The business rule you are creating in this exercise is a very simple rule for illustrative purposes. Code written for the real world can be as complex as you
wish.

1. Navigate to System Definition > Business Rules.


2. Click New.
3. Enter the following information.

Field Value

Name Update attendee count

Table Attendee [x_snc_marketing_ev_attendee]

Active Selected

Advanced Selected

Insert Selected
When After

Script
function onAfter(current, previous) {
//This function will be automatically called when this rule is processed.
var gr = new GlideRecord('x_snc_marketing_ev_marketing_event');
gr.get(current.marketing_event);
gr.number_of_attendees_registered += 1;
gr.update();
}

4. Click Update.
5. Test by adding a few attendees.
The current registration count should reflect the addition.

04 Building a sample ServiceNow application - Exercise 16 - Building a


custom user interface

Create custom attendee page


In this exercise you will write a UI page based on Jelly, an open standard from the Apache Software Foundation.

The common elements and functionality of UIs automatically generated by the ServiceNowService application make it easy to use and navigate, which
increases user adoption and satisfaction. This is the recommended way to build UI.

However, there may be situations where you may want to have a different look and feel for your application, perhaps to match corporate standards. You can
accomplish this on the platform by writing a UI Page based on Jelly, an open standard from the Apache Software Foundation.

Note: UI Pages also allow you to incorporate your own stylesheets (CSS) as well as Javascript libraries. For a customer example, look
athttps://it.byu.edu/byu/default.do

1. Navigate to UI Pages.
2. Click New.
3. Enter the name AttendeeForm (no space).
4. Copy the following code into the HTML field.

<style type=text/css>
body{
font-family:Lucida Grande, Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
}
p, h1, form, button{border:0;
margin:0; padding:0;}
.spacer{clear:both;
height:1px;}
/* ----------- My Form ----------- */
.myform{
margin:0 auto;
width:400px;
padding:14px;
}
/* ----------- stylized ----------- */
#stylized{
border:solid 2px #b7ddf2;
background:#ebf4fb;
}
#stylized h1{
font-size:14px;
font-weight:bold;
margin-bottom:8px;
}
#stylized p{
font-size:11px;
color:#666666;
margin-bottom:20px;
border-bottom:solid 1px
#b7ddf2;
padding-bottom:10px;
}
#stylized label{
display:block;
font-weight:bold;
text-align:right;
width:140px;
float:left;
}
#stylized .small{
color:#666666;
display:block;
font-size:11px;
font-weight:normal;
text-align:right;
width:140px;
}
#stylized input{
float:left;
font-size:12px;
padding:4px 2px;
border:solid 1px #aacfe4;
width:200px;
margin:2px 0 20px 10px;
}
#stylized button{
clear:both;
margin-left:150px;
width:125px;
height:31px;
background:#666666
url(img/button.png) norepeat;
text-align:center;
line-height:31px;
color:#FFFFFF;
font-size:11px;
font-weight:bold;
}
</style>
<div id=stylized class=myform>
<g:ui_form id=form name=form>
<h1>Sign-up form</h1>
<p>Please sign up here for an fun and informative session</p>
<label>First Name<span class=small>First Name</span>
</label>
<input type=text name=fname id=name />
<label>Last Name<span class=small>Last Name</span>
</label>
<input type=text name=lname id=name />
<label>Email<span class=small>Add a valid address</span>
</label>
<input type=text name=email id=email />
<label>Phone<span class=small>Your Phone Number</span>
</label>
<input type=text name=phone id=phone />
<button type=submit>Sign-up</button>
<div class=spacer></div>
</g:ui_form>
</div>
5. Copy the following Javascript in the Processing script field.

var attendee = new GlideRecord("u_attendee");


u_attendee.u_first_name = fname ;
u_attendee.u_last_name = fname ;
u_attendee.u_email = email;
u_attendee.u_phone = phone;attendee.u_marketing_event = "<sys_id_of_event_record>" ; // HARDCODED
u_attendee.insert();

6. Substitute the placeholder sys_id with an actual sys_id. To obtain this open a record, right-click the grey bar and select Copy sys_id.
7. Go to the bottom of the page and click Update.
8. Access the page by going to http://<instance_name&gt;.service-now.com/AttendeeForm.do.
Note: Replace <instance_name> with your instance name.
9. Add a new attendee to test that everything is working as expected.

04 Building a sample ServiceNow application - Exercise 17 - Web services

Access web services


In this exercise you will access web services, which provide a standards-based mechanism to connect systems together.
The platform provides support for both SOAP and REST services. A SOAP based web service is automatically generated for all the tables.

To access the definition, type this URL into your browser:


http://<instance_name>.service-now.com/u_marketing_event.do?WSDL
Note: Replace <instance name> with the name of your instance.

Try the same for the Equipment Request table.

05 Deploying applications - Module 1 - Update sets

Exercise 1: Request additional instances


Request a second development instance now so that you have somewhere to deploy your Marketing Events application when the exercises call for it. Instance
requests require two days of lead time.

Until now, a single development instance was all you needed to create and update an application. You need at least one more to deploy your application.

1. Log in to HI.
2. From the Self-Service > Clone an instance page in HI, submit a clone request.
3. [Optional] Repeat step 2 and request two more cloned instances.
Note:

Request the additional clones if you have multiple developers working on the same application simultaneously.
Request the additional clones if you have a hierarchichal development environment that includes development, test, beta, production, or other tiers.
If neither of these situations apply to your organization, order only one clone and skip module 3.
Business requirements
In previous training, you created and enhanced a Marketing Events application. Now you need to distribute it to other instances for testing.

To facilitiate testing, you need to:

Transfer the application from your development instance to your test instance.
Include demo data with the application.
Back up the application to an external file.

You meet these requirements by:

Creating an update set.


Creating application files from application records.
Exporting the update set as an XML file.

Update set features


An update set allows you to store configuration changes as a named collection of records. Transferring an update set from one instance to another allows
administrators to apply the changes contained within the update set to the target instance. This table summarizes the features of update sets.

Table 1. Update set features

Feature Description

Specify the update set The system stores application changes in a matching update set. For example, the system stores the Marketing Events
where the system stores Application in the Marketing Events Application update set.
changes.
You can create a new update set to store application changes. SeeApplication Files.

Export an update set as You can manually export an update set as an XML file.
an XML file.

Identify differences The system automatically identifies application files from an incoming update that match existing application files on the local
between update sets system. Administrators have the option to select the version they want by choosing to keep the local version or to apply the
incoming remote version.

Merge update sets If you store changes in multiple update sets, you can merge them to create a new update set that combines the application files
from both update sets.

Merging update sets ensures that the system applies changes in the proper order.

Exercise 2: Create application files from records


Specify what demo data to include when installing or updating your application on a different instance.

1. Navigate to Marketing Event > Marketing Events.


2. Right-click the lists column labels and select Create Application Files.
Figure 1. Column label context menu
The system displays the Create Application Files from Records dialog box.
3. From Load When, select New Installs and Upgrades.
4. Click OK.
The system creates application files from the selected records.
Figure 2. Newly created application files

5. Navigate to these Marketing Event tables and create a similar set of application files for each table.
Table

Equipment Requests

Attendees

Sales Prospects

Exercise 3: Update the application record


Update the application record with a new version and a description in preparation for sharing the application on other instances.

1. Navigate to System Applications > Applications.


2. Click Marketing Events Application.
3. Enter these field values.

Field Value

Version 1.0

Short description Manage marketing events by tracking budgets, equipment requests, and attendees. Includes REST web service.

Logo <Choose a suitable logo>

4. Click Update.
The applications list displays the updated details.
Figure 1. Updated Applications list

Exercise 4: Publish to an update set


Publish the finished application as an update set.

1. Navigate to System Applications > Applications.


2. Click Marketing Events Application.
3. From Related Links, click Publish to Update Set.
The system displays the Publish to Update Set dialog box.
Figure 1. Publishing an update set
4. Select Include demo data.
5. Click Publish.
The system publishes the application as an update set.
Figure 2. Publishing progress window
6. Click Done.
The system displays the Marketing Events Application update set.
7. From Related Links, click Export to XML.
The browser displays a dialog box to save the file.
Figure 3. Saving the exported remote update set

8. Save the file to your local file system.


You now have a copy of your application you can use for auditing, backup, or distribution purposes.

Exercise 5: Apply the update set


Apply the update set to another instance. This exercise assumes you have access to a second instance that does not contain the Marketing Events application.

Consider this exercise optional if you cannot access a second instance and proceed to the next lesson.

1. Log in as an administrator to the target instance where you want to apply the update set.
2. Navigate to System Update Sets > Update Sources.
3. Click New.
4. Enter these field values.

Field Value

Name Development

Type Development

URL [Enter URL to your development instance]

Username [Enter credentials]

Password [Enter credentials]

5. Click Test Connection.


The system displays Connection is OK.
6. Click Submit.
The system displays the list of remote instance records.
7. Click Development.
8. From Related Links, click Retrieve Completed Update Sets.
The system connects to the remote instance and retrieves a list of update sets.
Figure 1. Retrieved update sets

9. From the Retrieved Update Sets related list, click Marketing Events Application.
The system displays the update set record.
10. Click Preview Update Set.
The system compares the application files in the update set to the application files on the local system.

If this instance has never installed the Marketing Events application, there should be no errors. If this instance has an earlier version of the application, the
system displays a list of update set conflicts.

11. Resolve any update set conflicts by selecting the option to Accept remote update.
12. Click Commit Update Set.

The system displays the Marketing Events application in the application navigator and in the list of Applications.

Figure 2. System Applications


Update sets evaluation
Currently, update sets meet our business requirements. In later exercises, you will see how the application repository can automatically manage update sets.

Table 1. Business requirements review for update sets


Table 1. Business requirements review for update sets

Requirement Met? Evaluation

Transfer the application from your Yes Requires manually creating an update set to transfer.
development instance to your test The preview process identifies conflicts with existing records.
instance. Can resolve conflicts by selecting the version to apply.

Include demo data in the application. Yes Requires manually selecting records to include as application files.
Can select when to install demo data.

Back up the application to an external Yes Requires manually creating an update set to export to a file.
file. File only contains a fixed version of the application.
Capturing future updates requires regenerating the file.

05 Deploying applications - Module 2 - Application repository

Application distribution business requirements


Marketing events users and application developers have further requirements for application distribution.

Application users need to know when there are application updates to install.
Application developers need to control when application updates appear to application users.
Application developers need to identify the latest application version.

You meet these business needs by publishing an application to the ServiceNow application repository.

Instance requirements for using the application repository


To use the application repository, an instance must meet these requirements.

Table 1. Application repository instance requirements

Requirement Description

Valid subscription The instance must be registered to a company with a valid subscription.

Personal developers instances do not have a subscription and cannot connect to the application
repository.

Matching application scope The application repository can share applications only with instances belonging to the same
application scope. All of the applications must belong to the subscribers application scope.

Network access The instance must be able to reach the application repository on the network. If you enable IP
access restrictions, allow connections from the application repository.
Exercise 6: Publish an application to the repository
Make your application available to all instances that belong to the same company by publishing it to the ServiceNow repository.

1. Navigate to System Applications > Applications.


2. Click Marketing Events Application.
3. In the Version field, enter 1.1.
4. Click Submit.
The system displays the Applications page, with the Marketing Events applications new version number.
5. Click Marketing Events Application.
6. From Related Links, click Make app available on other instances.
The system displays the Make App available on other instances dialog box.
Figure 1. Making the app available on other instances
7. In the Dev Notes field, enter Ready for test.
8. Click Submit.
The system uploads the current version of the application to the application repository. Other instances with the same application scope can now download
it.
Figure 2. Upload success message
9. Click OK.

Exercise 7: Install the application from the repository


Install an application from the ServiceNow repository onto an instance that does not contain the Marketing Events application. This exercise assumes that you
successfully acquired a target instance earlier.

Treat this exercise as optional if you were unable to acquire an instance earlier.

Note: The target instance must belong to the same company as the instance in the previous exercise. A personal development instance will not work here.

1. Log in as an administrator to the target instance.


2. Navigate to System Applications > Applications.
3. Click the Download tab.
The system displays a list of applications you can install.
4. In the Search applications box, enter Marketing Events.
The system displays a list of matching application names.
Figure 1. List of applications that match Marketing Events

5. In the Marketing Events Application row, click Install.


The system installs the application on the instance.

Exercise 8: Update the Marketing Events application


Create a new version of the Marketing Events application with an update.

1. Login as an administrator to the development instance.


2. Navigate to System Applications > Applications.
3. From the Develop tab, click Marketing Events Application.
4. From the Tables related list, click Attendee.
5. From Controls, enter these field values.

Field Value
Auto-number Selected

Prefix ATTEND

Number 1,000

Number of digits 7

6. Right-click the form header and click Save.


7. From Related Links, click Design Form.
8. Add the Number field to the form.
9. Click Save.
10. Close the Form Design tab.

Exercise 9: Publish an update to the repository


Publish your Marketing Events application update to the ServiceNow repository.

1. Navigate to System Applications > Applications.


2. Click Marketing Events Application.
3. In the Version field, enter 1.2.
4. From Related Links, click Make app available on other instances.
5. In the Dev Notes field, enter Numbering updates.
6. Click Submit.

The system uploads the updated version of the application to the application repository. It is now the current version ready for other instances to download.
Exercise 10: Update the test instance
Update the Marketing Events application on the test instance with the current version on the development instance. This exercise assumes you installed the
application on the test instance previously.

Treat this exercise as optional if you were unable to acquire an instance earlier.

1. Log in to the test instance as an administrator.


2. Navigate to System Applications > Applications.
The system displays an update indicator on the Update tab.
Figure 1. Available application updates

3. Click the Updates tab.


4. Click the Update button next to Marketing Events Application.
The system updates the Marketing Events application to the latest version.

Figure 2. Application update installed


Application repository evaluation
The application repository meets our business needs. It improves on the update set experience because it restricts to the latest application version only.

Table 1. Business requirements review for update sets

Requirement Met? Evaluation

Application users need to know when Yes The Update option is available only when developers publish an
there are application updates to install. update.
Developers can provide release notes for each update.

Application developers want to control Yes The Update option is available only when developers publish an
when application updates appear to update.
application users. Use the version value and development notes to bundle changes
in a single update.

Application developers need to identify Yes The Downloads tab lists the most current application version only.
the latest application version. The Updates tab lists the most current update only.
05 Deploying applications - Module 3 - [Optional] Team development

Parallel development business requirements


Your organization needs to speed up the development process.

Specifically, multiple developers need to be able to:

Work on the same applications simultaneously.


Retrieve changes from a central instance.
Send changes to a central instance.
Identify and resolve change conflicts.

You meet these requirements by configuring Team Development on multiple instances.

Team development components


Team development consists of these components.

Component Description Use to

Parent An instance that becomes the central repository for all changes. Can be a Identify differences between instances.
instance production or a test instance. Pull changes from an instance below it in the
hierarchy.
Push changes to an instance below it in the
hierarchy.

Development A sub-production instance managed by one or more developers. Create new applications and features.
instance Replicate the production environment.
Avoid causing outages on a production instance.

Test instance A sub-production instance where new applications and features are tested. Test all new applications and features on a sub-
Typically this is a parent instance to the development instances. production instance.
Replicate the production environment.
Avoid causing outages on a production instance.

Peer or A sub-production instance that shares a parent instance with other sub- Provide individual developers or teams with their
sibling production instances. own instance.
instance Allow divisions of labor such as new application
development and patch development.

Reconcile An action that identifies the differences between two instances. Identify changes between a parent and a
development instance.
Identify changes between peer instances.

Push An action that copies changes from a development instance to a parent instance. Bring a parent instance up to date with the latest
Always requires a reconciliation. changes.
Identify which local changes to ignore.
Pull An action that copies changes from the parent instance to a development Bring a development instance up to date with the
instance. Always requires a reconciliation. latest changes.
Identify change collisions.

Queue for An action that identifies which local changes to push to the parent instance Identify local changes to push to the parent
push instance.
Allow developers to push completed changes
and continue work.

Ignore An action that prevents a local change from being part of a push action. Stop tracking local versions for particular files.
Allow developers to control what changes
appear in the change list.

Collision An incoming change that conflicts with a local change. Select which change to accept.
Select which change to archive.

Exercise 11: Enable team development


After enabling Team Development on two instances, you designate one as the parent instance.

Define the instance and make it the parent.

Note: The parent instance should not be the instance where you installed the application from the application repository. Best practice is not to mix these two
means of deployment on the same instance. Use team development is to make applications and move them to other instances for testing. Use the application
repository to deploy completed applications

1. Log in to the development instance.


2. Navigate to Team Development > Remote Instances.
3. Click New.
4. Enter these field values.

Field Value

Name Parent

Type Development

URL <Click lock icon to access field, then enter URL to parent instance>

Username <Enter credentials>

Password <Enter credentials>

Note: The user credentials must be valid on the target instance.


5. Click Test Connection.
The system displays an information message if successful.
6. Right-click the Remote Instance form header and click Save.
The system creates the Remote Instance record.
Figure 1. Remote instance record for new parent instance
7. From Related Links, click Make This Your Parent.
The system reconciles changes with the parent instance. When complete, it displays the results.
Figure 2. Reconciling the local instance with the parent
Pull the changes from the parent and resolve any conflicts.

8. From Next steps, click Team Dashboard.


The system displays a summary of changes between the current instance and the parent instance.
Figure 3. Team development dashboard summary of changes
9. Click Pull.
The system pulls the latest changes from the parent instance and identifies any collisions with local changes.
Figure 4. Results of the pull from the parent instance
10. Click Close.
The system displays the Team Dashboard.
Figure 5. Team dashboard
Note: Conflicts often exist between the records pulled and those already on the instance. When they do, a Collisions button appears
11. If visible, click Collisions.
The system displays a list of change collisions for you to resolve by choosing which version of each file to keep.
12. Select the check boxes for the collision records to resolve.
13. Click the checkbox next to Actions on selected rows
14. Resolve the selected colisions by performing one of the following actions.
Option Description

Keep the In the Actions choice list, select Use Pulled Version. This is commonly used the first time you pull to make sure your development
parent version instance reflects what exists before beginning application development.

Keep the local In the Actions choice list, select Use Local Version. This is commonly used when you have modified the record as part of
version developing the application.

When complete, the team dashboard should display OK for both the parent and local instance.

Figure 6. Team development dashboard after reconciling collisions


Exercise 12: Update the application
Update the Marketing Events application from the development instance by adding a vendor field to the Equipment Requests table.

1. Log in to the development instance as an administrator.


2. Navigate to Marketing Event > Equipment Requests.
3. Right-click any column heading and click Configure > Table.
4. From the Related Links, click Design Form.
5. Click the Field Types tab.
6. Drag a Reference field below the Marketing event field.
7. Rename the field to Vendor.
8. Click the Edit this field gear icon for Vendor.
9. Enter these field values.

Field Value

Name Vendor

Reference Company

10. Close the Properties dialog box.


11. Click Save.
12. Close the Form Design tab.
13. From the Table Columns related list, click the List controls icon.
14. Click Refresh List.
The list displays a new row for the Vendor field.
15. Click Vendor.
The system displays the dictionary entry for the Vendor column.
16. In Reference Specification, select [Vendor] [is] [true] as the Reference qualifier condition.
17. Click Update.
18. Navigate to Marketing Event > Marketing Requests.
19. Click Amazon Web Services.
The system displays the Equipment Request record.
Figure 1. Vendor equipment request record
20. From Vendor, select Amazon.
21. Click Update.
22. Right-click any column label, and click Create Application Files.
The Create Application Files from Records dialog box appears.
Figure 2. Creating application files from the Equipment Request table
23. Verify Load When is set to New Install and Upgrades.
24. Click OK.

The system updates the existing application files in the Marketing Events Application.

Figure 3. Updated application files message


Exercise 13: View local changes
View the list of local changes awaiting push to the parent instance.

1. Navigate to Team Development > Team Dashboard.


The system displays the list of local changes awaiting action.
2. From Local Changes, click the Show / hide filter icon.
3. Update the filter as follows. [State] [is] [New] [AND] [Remote Instance] [is] [Parent] [AND] [Update set.Application] [is] [Marketing Events Application].
4. Click Run.
The system displays application changes you made in the previous exercise.
Figure 1. Local Marketing Events application changes
5. From the end of the list, click the checkbox to select all records.
6. Select Actions on selected rows.
The actions list appears.
Figure 2. Choices for local changes

7. Select Queue for Push.


The system updates the Team dashboard with a Ready to Push row.
Figure 3. Team dashboard with Ready to Push row
Exercise 14: Push changes to the parent instance
Push your local changes to the Marketing Events application from your development instance to its parent.
1. Navigate to Team Development > Team Dashboard.
2. Click Push.
The system displays the Push Changes form.
3. Enter these field values.

Field Value

Name Vendors

Comments Added Vendor field to Equipment Requests.

4. Click Push Changes.


The system pushes the queued local changes to the parent instance.
Figure 1. Pushing changes to the parent instance

5. Click Close.
The Team Dashboard no longer displays a Ready to Push row.
Figure 2. Team Dashboard with nothing to push

Exercise 15: Register another development instance


Register an additional development instance with your team development environment. This exercise assumes you have access to the third cloned instance
requested during exercise 1.
This final cloned instance that you requested earlier serves as an additional developers instance in the remaining exercises. From it, you generate a conflicting
change that you resolve as part of the collision and manual merge exercises.

Define the instance and make it the parent.

1. Identify an instance you want to use as another development instance.


Note: This instance must belong to the same company and have the same vendor prefix as the existing team development instances.
2. Log in as an admin user to the development instance you want to register.
3. Navigate to Team Development > Remote Instances.
4. Click New.
5. Enter these field values.

Field Value

Name Parent

Type Development

URL <Click lock icon to access field, then enter URL to parent instance>

Username <Enter credentials>

Password <Enter credentials>

Note: The user credentials must be valid on the target instance.


6. Click Test Connection.
The system displays an information message if successful.
7. Right-click the Remote Instance form header and click Save.
The system creates the Remote Instance record.
8. From Related Links, click Make This Your Parent.
The system reconciles changes with the parent instance. When complete, it displays the results.
Figure 1. Reconciling the local instance with the parent
Pull the changes from the parent and resolve any conflicts.

9. From Next steps, click Team Dashboard.


The system displays a summary of changes between the current instance and the parent instance.
10. Click Pull.
The system pulls the latest changes from the parent instance and identifies any collisions with local changes.
11. Click Close.
The system displays the Team Dashboard.

Note: Conflicts often exist between the records pulled and those already on the instance. When they do, a Collisions button appears
12. If visible, click Collisions.
The system displays a list of change collisions for you to resolve by choosing which version of each file to keep.
13. Select the check boxes for the collision records to resolve.
14. Click the checkbox next to Actions on selected rows
15. Resolve the selected colisions by performing one of these actions.
Option Description

Keep the In the Actions choice list, select Use Pulled Version. This is commonly used the first time you pull. It ensures that your development
parent instance mirors what exists on the parent instance before beginning application development.
version

Keep the In the Actions choice list, select Use Local Version. This is commonly used when you have modified the record as part of developing
local version the application.

Exercise 16: Queue change from the new development instance


Update the Marketing Events application from the newest development instance by modifying the Attendee table, and push the change to the parent instance.

1. Log in to the newly registered development instance.


2. Navigate to Marketing Event > Attendees.
3. Right-click the list headers and click Configure > Table.
4. Enter these field values.

Field Value

Can create Selected

Can update Selected

Allow configuration Selected


5. Click Update.
6. Navigate to Team Development > Team Dashboard.
7. From Local Changes, click the Show / hide filter icon.
8. Update the filter as follows. [State] [is] [New] [AND] [Remote Instance] [is] [Parent] [AND] [Update set.Application] [is] [Marketing Events Application].
9. Click Run.
The system displays application changes you made earlier in the exercise.
Figure 1. Local Marketing Events application changes

10. Click the checkbox to select all rows.


11. Select Actions on selected rows.
The actions list appears.
Figure 2. Choices for local changes
12. Select Queue for Push.
The system updates the Team dashboard with a Ready to Push row.
13. From the Team Dashboard, click Push.
The system displays the Push Changes form.
14. Enter these field values.
Field Value

Name Attendee table changes

Comments Allow create, update, and configuration from other scopes.

15. Click Push Changes.


The system pushes changes to the parent instance.
Figure 3. Results of the push to the parent instance
16. Click Close.

Exercise 17: Queue change from another development instance


Queue a different change to the same table in the Marketing Events application, from the other registered development instance.

The steps for queueing changes and pushing them to the parent instance are the same as they were in the previous exercise. However, the update to the
application is different. It conflicts with the change queued from the initial development instance.

1. Log in to the other registered development instance.


2. Navigate to Marketing Event > Attendees.
3. Right-click the list headers and click Configure > Table.
4. Enter these field values.

Field Value
Allow configuration Selected

5. Click Update.
6. Navigate to Team Development > Team Dashboard.
7. From Local Changes, filter the list to show changes to the Marketing Events application.
8. Click the checkbox to select all rows.
9. From Actions on selected rows, select Queue for Push.
The Team Dashboard displays a Ready to Push row.
10. From the Team Dashboard, click Push.
The system displays the Push Changes form.

Exercise 18: Identify colliding changes


Find the collisions between the two application updates.

1. Navigate to Team Development > Team Dashboard.


The team dashboard displays a collision.
Figure 1. Team dashboard with a collision
2. Click Collisions.
In this case, there is only one collision.
Figure 2. Push and pull versions list of the attendee table
3. In the Type column, click Table.
The system displays the Push or Pull Version record for the change.
Figure 3. Push or pull version
4. From Related Links, click Compare to Current.
The system displays a list of changes between the two records.
Figure 4. Pulled version vs. local version
Note: In this case, the local developer can see that the values for create_access and update_access are true.
5. Close the pop-up window.

Exercise 19: Manually merge changes


Developers can resolve collisions by using the pulled version to overwrite their local changes, by using the local version to overwrite the pulled changes, or by
manually merging the pulled changes on the local instance. In this case, you will manually merge changes.

1. Navigate to Marketing Event > Attendees.


2. Right-click the list headers and click Configure > Table.
3. Enter these field values.

Field Value

Can create Selected


Can update Selected

4. Click Update.
5. Navigate to Team Development > Team Dashboard.
6. From Local Changes, filter the list to show changes to the Marketing Events application.
7. Click the checkbox to select all rows.
8. From Actions on selected rows, select Queue for Push.
9. From the Team Dashboard, click Collisions.
The system displays a list of collisions.
Figure 1. Collision of push and pull versions

Note: In this case, there is only one collision.


10. From the Type column, click Table.
The system displays the Push or Pull Version record for the change.
Figure 2. Record for the push or pull version
11. From Related Links, click Compare to Current.
The system displays a list of changes between the two records. In this case, the values for create_access and update_access no longer collide. Only the
system update fields differ.
Figure 3. Compare to Current list
12. To resolve the collision, click Use local version.
13. In the Confirmation dialog box, click OK.
The system changes the state of the Push or Pull Version record to Resolved.
Figure 4. Record of resolved collison
14. Navigate to Team Development > Team Dashboard.
With the collision resolved, the team dashboard displays OK status messages. Notice that there are still local changes ready to push.
Figure 5. Team dashboard with no collisions
15. From the Team Dashboard, click Push.
The system displays the Push Changes form.
16. Enter these field values.

Field Value

Name Attendee table changes


Comments Allow configuration from other scopes.

17. Click Push Changes.


The system pushes the changes to the parent instance.
Figure 6. Pushing changes to the parent instance

18. Click Close.

Team development evaluation


Table 1. Business requirements review for team development
Requirement Met? Evaluation

Multiple developers can work on the Yes There are a number of possible parent-child instance
same applications simultaneously. configurations to choose from.
Team development identifies collisions between instances, not
between individual developers on the same instance.
You must decide how many development instances are best for
your environment.

Developers can retrieve changes from a Yes Developers can pull changes from the parent instance.
central instance. Pulling frequently identifies collisions sooner.
Collisions must be resolved before changes can be pulled from the
parent.

Developers can send changes to a Yes Developers can identify and push local changes to the parent
central instance. instance.
Developers can ignore local changes they do not wish to push to
the parent instance.

There is a mechanism to identify and Yes Developers can see the differences between the local and
resolve change conflicts. incoming changes.
To prevent overwriting incoming changes, developers must
manually merge incoming changes on their local instance.
05 Deploying applications - Module 4 - Considerations and conclusions

Deployment options evaluation


The following table summarizes the deployment options you experienced.

Table 1. Summary of deployment options

Deployment option Good for Future considerations

Update Sets Storing changes to a baseline or installed You can manually create update sets to
application store a particular application version.
Storing and applying a particular version of Use update sets to deploy patches or
an application changes to installed applications.
Producing a file for export Avoid using update sets to install
applications. Instead, use the application
repository or theServiceNow Store to install
applications.

Application Repository Installing and updating applications on all of Consider uploading an application to
your instances the ServiceNow Store to share it with other
Automatically managing application update users.
sets Allows installation of and update to the latest
Restricting access to applications to the application version only. Use update sets to
same company store prior application versions.
Deploying completed applications to end If used in conjunction with team
users development, make applications available
only from a parent instance.

Team Development Providing change management across Works best when each development team
multiple instances has access to a dedicated development
Allowing multiple developers to work on instance.
applications Requires developers to manually merge
Organizations that have access to several colliding changes.
sub-production instances If used in conjunction with the application
repository, make applications available from
a parent instance.
Only works for instances owned by the same
company.

Further challenges
Improve your skills by attempting these tasks on your own.

Create an update set for a custom application.


Install an application from the application repository on a production instance.
Create an application with team development and make it available from the application repository.
06 Content Management System 101 - Module 1 - Portal rebranding

Exercise 1: Log in to your instance and create bookmarks


Log in to your training instance and bookmark frequently used records.

1. Go to your instance URL and log in using admin credentials.


2. Navigate to Content Management > Sites.
Figure 1. Navigating to Sites

3. Drag Employee Self-Service and Portal to the Edge.


Bookmarks are created for Employee Self-Service and Portal. These exercises frequently use Employee Self-Service and Portal as examples.
Bookmarking them allows you to return to them quickly.
Figure 2. Employee Self-Service and Portal bookmarks
Exercise 2: Modify the logo and colors in the banner
Update the company logo that appears in the portal.

1. Click the Employee Self-Service bookmark you created in the previous exercise.
Note: The site record for the Employee Self-Service window is the parent record for all of the content pages within the site. The site record form contains
reference fields to other values, such as site layout, site theme (CSS file), and the Portal page. The Portal page is the first page displayed when a user
navigates to the portal URL. At the bottom of the form is a Related Links list that includes all the pages that exist within that particular site. Because many
or all pages can use a single content section, you only need to modify the content section once.
2. Click the icon next to Portal in the Home page field.
Figure 1. Home page field icon
The Page Portal form displays. This form contains fields such as Layout (if different from Site Layout) and Content Theme. If there is no value in
the Layout orContent Themefields, they inherit those values from the parent site record.
3. Click the Edit Page link.
Figure 2. Edit Page link
The Portal page displays. This page contains a collection of content blocks that you can add, remove, and edit.

4. Click the Edit icon ( ) in the top right corner.


The Header Portal Header form opens. This form contains important information, including the logo, the banner text, the top and bottom menus, and a
choice between a background image or the colored horizontal bars.

There are three colored bars: a light-gray top row, a white row behind the logo and banner text, and a red row behind the main menu. Alternatively, the
Background option lets you choose a background image. For this exercise, leave Background as Colored Bars.

Figure 3. Background
5. Download the CloudDimensionsLogo.png file from http://tinyurl.com/cms101-logo or use the logo of your choice.
6. On the header form link in the Logo field, click Update.
7. Click Browse, navigate to the CloudDimensionsLogo.png file that you downloaded, and click OK.
The header record form appears with the new logo in the place of the ServiceNow logo. The new logo has a solid blue background.
8. Modify the value for middle and bottom color bars, leaving the Top color bar value unchanged.
The current value for the Top color bar is the hexadecimal value for light blue.
Note: For the top, middle, and bottom bar colors, you can use standard color names such as red, blue, and yellow or the hexidecimal values of colors. To
find the hexadecimal value of a specific image, use an image editor or a browser plugin such as ColorZilla.
1. Enter the value #1F5FA0 into the Middle bar color field to match the blue color in the logo image.
2. Replace the Bottom color bar value (currently the current hexidecimal value for red) with the word gray.
9. Enter Self Service Portal in the Text field.
10. Click Update.
11. Navigate to http://<yourinstance>.service-now.com/ess.
The screen should look like the following:
Figure 4. Self Service Portal
06 Content Management System 101 - Module 2 - New content pages
from existing

Exercise 3: Create a new Schedule Relocation page


Create a content page where you can schedule equipment relocation.

The easiest way to create a new page is to use another page as a template, copy it, then make changes to the copy.
1. Click the Employee Self-Service bookmark to open the site record.
2. Scroll to the Pages section and click Portal Order Hardware.
You will use the Portal Order Hardware page as a template for the Schedule Relocation page. The Portal Order Hardware page is designed for a user
to order something.
Figure 1. Portal Order Hardware
3. Click Copy.
Note: Content on pages are related records. Those functions do not copy related records, so you cannot use the Insert or Insert and Stay commands to
copy a page.
Figure 2. Copy

The Copy of Portal Order Hardware page appears. The Name and URL suffix fields contain a copy of the information from the Portal Order
Hardware page.
4. Replace the information in the Name field with Scheduled Relocation and the information in the URL suffix field with scheduled_relocation.
5. Scroll to the Related Links section and click Edit Page.
6. Click the X icon to remove Portal Order Splash Menu from the page.
7. Click the Add Content link.
Figure 3. Add Content link

8. In the Sections box, select Content Blocks and New Detail, click Add Here, and click the X icon to close the Sections box.
Figure 4. Sections box
9. Click the Close icon to remove the Portal Nav Column Common and Portal Content Column Common content blocks.
These content blocks are used for advanced prototyping on the site.

Note: If you want to keep these content blocks, move Portal Content Column Commonbefore the New Detail content block.

10. Click the Edit icon ( ) to edit the New Detail content block.
The Detailed Content page appears. This screen specifies the details of the new record.
Figure 5. Detailed Content page
11. In the Name field, enter Portal - Scheduled Relocation.
12. From the Type drop-down menu, select Show a specific document.
13. Click the magnifying glass next to the Model document field.
The Select the document window appears.
14. From the Table name drop-down menu, select Catalog Item.
15. Click the magnifying glass next to the Document field.
16. Filter the Catalog Items by typing scheduled in the Search box and pressing Enter.
17. Click Schedule Relocation.
The Select the document window looks similar to the following:
Figure 6. Select the document window
18. Click OK.
The Detailed Content page looks similar to the following:
Figure 7. Detailed Content page
19. Click Submit.
The Scheduled Relocation page looks similar to the following:
Figure 8. Scheduled Relocation page
20. Click the preview link to see how the page appears to the end user.
The page looks similar to the following:
Figure 9. End user view
21. Close the preview window.

Exercise 4: Add the page to a portal menu


Add the Schedule Relocation page you created in the previous task as a link in the Get Helpportal menu.

1. Click the Portal bookmark in the Edge.


2. Scroll to the Related Links section and click Edit Page.
Note: You can navigate directly to a menu to change it, but opening the Portal page and clicking Edit Page clearly identifies the menu and items to be
changed. This is the most consistent way of making menu changes until you are familiar with the menu.

3. In the Portal Menu section, click the Edit icon ( ).


The Navigation Menu Portal Block Menu screen appears.
4. Scroll to the Menu Items section and click Get Help.
Figure 1. Menu Items > Get Help

5. Scroll to the Menu Items section and click New.


Figure 2. Menu Items > New
6. Enter these field values.

Field Value

Name Schedule Relocation

Redirect to A content page

Detail page Scheduled Relocation

Order 500

7. Click Submit.
8. Navigate to http://<yourinstance>.service-now.com/ess.
The Get Help portal menu should look like the following:
Figure 3. Get Help portal menu

9. Click Schedule Relocation.


The Schedule Relocation page appears.

Exercise 5: Add the page to a header menu


Add the Schedule Relocation page to the Get Help drop-down in the bottom menu of the header. The bottom menu is the gray bar underneath the logo.

1. Click the Portal bookmark in the Edge.


2. Scroll to the Related Links section and click Edit Page.

3. In the JC Header section, click the Edit icon ( ).


4. Click the icon next to the Bottom menu field.
5. Scroll to the Menu Sections section and click Get Help.
6. Scroll to the Menu Items section and click New.
7. Enter the following information.

Field Enter this

Name Schedule Relocation

Redirect to A content page

Detail page Scheduled Relocation

Order 500

8. Click Submit.
9. Navigate to http://<yourinstance&gt;.service-now.com/ess.
The Get Help drop-down in the bottom menu of the header should look like the following:
Figure 1. Get Help drop-down in the bottom menu of the header
06 Content Management System 101 - Module 3 - New content pages
from scratch

Exercise 6: Create a new Can We Help You? page


Create the Can We Help You? page. This exercise creates a new page instead of copying an existing page.

1. Click the Employee Self-Service bookmark in the Edge.


2. Scroll to the Pages section and click New.
3. Enter the following information.

Field Enter this

Name Can We Help You

URL Suffix can_we_help_you

Title Can We Help You?

4. Scroll to the Related Links section and click Edit Page.


A blank page appears.
5. Click the Add Content link.
Figure 1. Add Content

6. In the Sections box, select Content Blocks and Portal Header.


A preview of the header appears.
7. Click the first Add Here section.
Figure 2. Add Here

The header appears on the page in the background and the Sections box is still available. Use this box to add multiple items to the page.
8. In the Sections box, keep Content Blocks selected and select My Requests.
A preview of the My Requests section appears.
9. Click the second Add Here section.
Figure 3. Add Here
10. Repeat steps 8 and 9, selecting Top Requests in the Sections box instead of My Requests.
11. In the Sections box, keep Content Blocks selected and select *New Detail.
A preview of the *New Detail section appears.
12. Click the third Add Here section.
Figure 4. Add Here
13. Click the X icon ( ) in the top-right of the Sections box.
The portal looks similar to the following.
Figure 5. Portal example

14. In the *New Detail section, click the Edit icon ( ).


15. Enter the following information.

Field Enter this


Name Can We Help You

Type Show a specific document

16. Click the magnifying glass next to the Model document field.
17. From the Table name drop-down menu, select Category.
18. Click the magnifying glass next to the Document field and select Can We Help You.
19. Click OK.
20. Click Submit.
21. Click the preview link to see how the page appears to the end user.
The page looks similar to the following:
Figure 6. End user view
Exercise 7: Add the page to the portal menu
Add the Can We Help You page as a link in the Order Things portal menu.

This is the same process you followed when you made the Schedule Relocation page available in an earlier module.
1. Click the Portal bookmark in the Edge.
2. Scroll to the Related Links section and click Edit Page.

3. In the Portal Menu section, click the Edit icon ( ).


4. Scroll to the Menu Items section and click Order Things.
Figure 1. Menu Items > Order Things

5. Scroll to the Menu Items section and click New.


6. Enter these field values.

Field Value

Name Can We Help You?

Redirect to A content page

Detail page Can We Help You


Order 500

7. Click Submit.
8. Navigate to http://<yourinstance>.service-now.com/ess.
The Order Things portal menu should look like the following:
Figure 2. Order Things portal menu

9. Click Can We Help You?.


The Can We Help You? page appears.
Figure 3. Can We Help You? page
10. Click any item on the page (for example, Item Designer Category Request).
On the page that appears, there is no Search option or Back button. These missing tools can cause navigation issues. You will add these tools in the next
exercise.
Figure 4. Item Designer Category Request page
Exercise 8: Add navigation options
Add a Back button and a Search field.

1. Click the Employee Self-Service bookmark in the Edge.


2. Clear the Simple catalog display check box and click Update.
Figure 1. Clearing the Simple catalog display
3. Navigate to the Can We Help You? page on the end user portal.
The page now has a Back button and a Search field.
Figure 2. Can We Help You? page with navigation features
4. Click any item on the page (for example, Item Designer Category Request).
On the page that appears, note that there is a Back button.
Figure 3. Item Designer Category Request page
06 Content Management System 101 - Module 4 - Plugin activations and
layout changes

Exercise 9: Add chat via plugin


Activate a system plug-in to add chat capability so that end users to chat with the support desk.

1. Navigate to System Definition > Plugins.


2. Enter *chat in the Go to search box and press Enter.
Figure 1. Searching for *chat

3. Click Chat.
Figure 2. Click Chat

4. Scroll to the Related Links section and click Activate/Upgrade.


5. Select Load demo data and click Activate.
Figure 3. Activate Plugin
6. Click Close & Reload Form.
7. Click the Portal bookmark in the Edge.
8. Scroll to the Related Links section and click Edit Page.

9. In the JC Header section, click the Edit icon ( ).


The Header Portal Header screen appears. A new field, Chat Queue, is now visible.
Figure 4. Chat Queue
10. Click the magnifying glass next to the Chat Queue field.
11. Click Service Desk Chat.
12. Click Update.
13. Click the preview link.
A Service Desk Chat button now appears.
Figure 5. Service Desk Chat button
Exercise 10: Modify the layout of an existing page
Move the Top Requests and My Requests lists to the right side of the Can We Help You? page.

1. Click the Employee Self-Service bookmark in the Edge.


2. Scroll to the Pages section and click Can We Help You.
Figure 1. Can We Help You
Note: To sort by Created Date, click the Created column header. Both of your recent pages, Can We Help You and Scheduled Relocation, will display at the
top.
The Page Can We Help You page appears. The Layout field is blank, which means that the layout of the page is inherited.
3. Click the magnifying glass next to the Layout field.
A list of available layouts appears. From this list, you can select a layout that meets your needs. If none of the available layouts meet your needs, you can
add a new layout for this page. The easiest way to do this is to start with a page that is close to what you need. This exercise uses CMS 2 Column Narrow
Left as a starting point.
4. Select CMS 2 Column Narrow Left.
Figure 2. CMS 2 Column Narrow Left
5. Click the details icon ( next to the Layout field.
6. Change the Name and Description to Right instead of Left.
Figure 3. Update Name and Description

7. In the XML section, scroll to the lines that start with <td id dropzone20 and <td id dropzone10.
Figure 4. Locate XML lines
8. Swap these two lines of XML.
Figure 5. Swap XML lines

9. Rightclick the records gray bar and select Insert and Stay.
Figure 6. Select Insert and Stay

10. Click Update.


11. Click the magnifying glass next to the Layout field and select CMS 2 Column Narrow Right (the layout you just created).
12. Rightclick the records gray bar and select Save.
13. Scroll to the Related Links section and click View Page.
The page should look similar to the following.
Figure 7. Can We Help You? page updated layout
06 Content Management System 101 - Module 5 - Considerations and
conclusions

Content Management System review


Consider the developer requirements you met during this introduction to the Content Management System.

Table 1. Basic requirements satisfied by the Content Management System

Requirement Met? Evaluation

Rebrand a portal homepage Yes Browsing for and selecting the logo of your choice is
simple and easy.
A logo approximately 80px high preserves the bulk of the
screen for content.
You can select an image for the banners background, or
use colored bars.
If you use bars, specify the colors with standard names like
red and blue, or with hexidecimal values.

Create new pages Yes The most common way is to use an existing page as a
template, copy it, then make changes to the copy.
You can also create pages from scratch.
Make new pages available Yes Linking the new page directly from the portal homepage is
a simple process.
You can also easily link the new page to an item in one of
the header drop-down menus, if desired.
Use the preview link to see how the page appears to the
end user.

Activate system plugins Yes The platforms chat plugin added sophisticated
functionality to your application in moments.
See List of plugins for names, IDs, and descriptions of over
500 available plugins.

Further challenges
Improve your skills by attempting these tasks on your own.

Add your logo and company colors to the self-service portal banner.
Change some text in the banner.
Rearrange the order of the items in one of the banner pull-down menus.
Activate the password reset plugin for self-service and service desk password resets.