You are on page 1of 120

Event Management Application

ServiceNow enables you to create applications quickly, with little to no coding required. This
tutorial walks you through building an event management application for a fictitious company.
The event coordinators at the fictitious company manage events with spreadsheets, email, phone
calls, and Google Docs. Coordinators struggle with managing equipment, attendee lists, and
attendee notifications.

Application Requirements
To help meet the needs of the company, build an app that will meet the following criteria for each
stakeholder.

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 requirements.

Obtain access to an instance and log in as administrator.

Users who have completed the Developer Platform Introduction training will have already created
this application and associated tables, and can continue to Exercise 4: Adding event records.

1. Navigate to System Applications > Applications.


2. Click New.
The Get started building applications home screen appears.

3. From the Start from global row, click Create.


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

5. Click Create and then OK to confirm that you want to create the application.
Figure 1. Confirm application

The system creates the Marketing Events Application and displays a Application Creation
Success window.

Note: When you create an application, the Application Creator creates a new role that you can
assign to users to grant access to the application.

6. Click View app record.


The system displays the list of applications.
Figure 2. System Applications

7. Click Edit for the Marketing Events Application.


The system displays the Application record for the Marketing Events Application.
Figure 3. Marketing Events Application

You have built your application, but it does not do anything yet. In the next exercise you will build the
foundation necessary to make your app functional.
Required tables
ServiceNow is built on a relational database that contains tables, which contain records, the
records hold fields, and each field is a column.

You can extend an existing table or create brand new tables for your application. This decision is
one of the most important decisions you will make when building applications. For our sample
app, you will create brand new tables. This will allow you to script and configure all of the
behaviors of your application.

Your sample application requires three database tables:

 Marketing Event
 Equipment request
 Attendee

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

Create the Marketing Event table


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

The Name field populates automatically, based on the label and application name.

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. Create the columns for the table, using the following information.

a) Double-click Insert a new row.


b) Enter a column label and click the checkmark.
c) Double-click the space under Type, enter a type, and click the checkmark.
d) 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 system displays the text of this field to
identify records in this table. In this case, whenever you need to select a particular
Marketing Event record, you will see the value from the Name field instead of the system-
generated 32-character long sys ID.

2. Create module “Marketing Events Application”


3. From the Controls section, accept the default values for the Create access controls and
User role fields.
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>.service-


now.com<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.

Create the Equipment Request table


In the Extends table field, select Task.

Select module “Marketing Events Application”

Create the additional columns for the Task table by building them one row at a time, using the
following information.
Column label 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.

Building the user Interface:


List layout for Marketing Event Application:

Form Layout for Marketing Event Application


Choice Values for City:
 Dallas,
 Kansas City,
 London
 San Jose,
 Portland
 Sydney

List layout for Equipment Requests list:


Form layout for Equipment Requests list:
Create the event records
Populate your tables with sample data.

1. Navigate to Marketing Events Application > Marketing Events.


2. Click New.
3. Create the following sample marketing event records:

Name City Budget Sponsor Start Date End Date

London LUG London $6000.00 Platinum Partners 2016-05-02 2016-05-02

Dallas LUG Dallas $2000.00 Dallas Partners 2016-05-16 2016-05-19

a. Click New.
b. Populate the fields.
c. Click Submit.
4. Navigate to Marketing Events Application > Equipment Requests.
5. Click New.
6. Create the following sample equipment request records:

Type Cost Needed From Needed Until Marketing Event

AV $1000.00 2016-05-02 2016-05-02 London LUG

Wireless Mic $300.00 2016-05-02 2016-05-02 London LUG

AV $1000.00 2016-05-16 2016-05-19 Dallas LUG

Wireless Mic $300.00 2016-05-16 2016-05-19 Dallas LUG

a. Click New.
b. Populate the fields.
c. 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 system displays a blank Marketing Event form.
6. Fill in the Marketing event form with sample values.
7. Right-click the form header and click Save.
The Equipments Requests related list appears at the bottom of the form.
You will see equipment requests for existing events and for new events as they are submitted.
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.
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.

1. Open a spreadsheet or text editor.


2. Create a comma-separated values (CSV) file using the following data.
Note: Include the header row.

Name City Start date End date Budget Sponsored by

Sydney LUG Sydney 2016-06-20 2016-06-22 2000 ANZ Partners

Dublin Launch Dallas 2016-05-23 2016-05-23 1000 TX Partners

Dublin London 2016-05-24 2016-05-24 20000 UK Partners


Workshop

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.
The system 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 right-click the form header and
click Save.

Field Value to use

Name Marketing Events CSV Transform

Source This field populates automatically.

Target table Marketing Event [x_snc_marketing_event_marketing_event]

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


The system adds the Field Maps related list.

4. In Related Links, click Mapping Assist.


5. Drag and drop the Sponsored by and Sponsor fields into the center Field Map column so
that Sponsored by is in the left column and Sponsor is in the right column.
6. Click Save.
The system displays the Table Transform Map record.

7. Verify that any incoming dates are in a format the system recognizes.
a. From the Fields Maps list, click u_start_date.
b. 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.
c. Select the yyyy-MM-dd format to match the date format in the CSV file and
click Update.
8. Verify that any end dates are in a format the system recognizes.
a. From the Fields Maps related list, click u_end_date
b. 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.
c. Select the yyyy-MM-dd format to match the date format in the CSV file and
click Update.
9. In the Related Links list, click Transform.
The system displays the import set and transform map to be used in the transform.
10. Click Transform.

The system takes data from the temporary staging table and uses the transformation logic to insert
new records in to the marketing event table.
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.

Users who have completed the Developer platform introduction training will have already created
these fields.

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. From the Tables related list, click the Marketing Event table.
The system displays the Table record for Marketing Event.
3. Create these fields with the following information.

Column label Type Display

Number of attendees expected Integer false

Number of attendees registered Integer false

a. Double-click Insert a new row.


b. Enter a column label and click the green checkmark.
c. Double-click the space under Type, enter a type, and click the green checkmark.
d. Double-click the space under Display, set to either true or false, and click the green checkmark.
4. Click Update.
5. Navigate to Marketing Event > Marketing Events.
6. Click New.
7. Right-click the title bar of the Marketing Events form and select Configure > Form Design.
The system opens the Form Design control in a new browser tab.

8. Click the Add a new section icon.

9. Drag the following fields into the new section.


o Number of attendees expected
o Number of attendees registered
10. Click Save.
11. On the Marketing Event form, right-click the title bar, and select Reload form to view your changes.
12. Close the Form Design browser tab.
13. Return to the browser tab containing the standard user interface.
Create the Attendee table
Create the third database table, the Attendee table, to capture attendee information.

1. Scroll to the Tables related list and click New.


The system displays a blank Table record.

2. In Label enter Attendee.


The system automatically populates the Name field based on the label and application name.

3. From Add module to menu, select Marketing Event.


4. Create the table rows, using the following information.

Column Label Type Reference Display

First name String false

Last name String false

Email String true

Phone String false

Marketing Event Reference Marketing Event false

5. From the Controls section, accept the default values for the Create access controls and User
role fields.
6. Click Submit.
The system creates the new table and displays the Custom Application record for the Marketing
Events Application.

7. From the Application Navigator, click Navigator options > Refresh Navigator.
The system reloads all menus and modules.

8. Navigate to Marketing Events Application > Attendees.


9. Add a few attendees.
a. Click New.
b. Enter attendee information.
c. Click Submit.
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_snc_marketing_ev_attendee]

Subject Thank you for registering for $


{marketing_event.name}

Message Dear ${first_name},

This is to confirm that you are registered for $


{marketing_event.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_snc_marketing_ev_attendee]

Active True (checkmark)

When to send > Inserted True (checkmark)

When to send > Updated True (checkmark)

Who will receive > Users/Groups in fields Add the Email field to Selected column

What it will contain > Email template Marketing Event Registration


4.

5. Click Submit.
Add a few test attendee records to test the email notification functionality. Navigate to System
Mailboxes > Outbound >Outbox to see the email records ServiceNow generates. It may take 15-
30 seconds for messages to show up. You may also want to check the other Outbound queues such
as Sent and Skipped to verify the message was generated.
Note: By default, email is disabled on development instances.
Using the service catalog

Service Catalog
Using the ServiceNow platform’s built-in Service Catalog ensures that users have a single interface
for all of their requests without having to navigate multiple applications.

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.

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 email. The marketing department can then receive, review,
track requests online, and process them more 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


Before you can add your application to the Service Catalog, you must first publish it. To publish an
application, you will need to 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 whenever someone uses the
Service Catalog to request a new marketing 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_snc_marketing_ev_marketing_events]
Field Value to use

Accessibility > Catalogs Service Catalog

Accessibility > Category Can We Help You?

Accessibility > Availability Desktop and Mobile

What it will contain > Short description Request for a Marketing Event

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. Note: Your Marketing Event table name will list your instance's unique application scope prefix
for the Marketing Event Application such as x_0123_marketing_e_.
5.

6. Click Submit.
The system creates the new record and displays it in the list of Record Producers.

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. From the Variables related list, create the following records.
Type
Question > Specifications >
Type Order Question Question > Name Reference

Reference 100 Your name requested_by User [sys_user]

Single Line 200 Event name name


Text

Single Line 300 Event sponsor


Text sponsor

Single Line 400 City city


Text

Date 500 Event start start_date


date

Date 600 Event end end_date


date

Single Line 700 Number of number_of_attendees_expected


Text attendees
expected

Single Line 800 Expected budget


Text budget

3. Note: For each variable, we have intentionally set the value of the Name field to match the
name of a corresponding column in the Marketing Event table. This mapping allows the system
to automatically save data entered into the variable into the matching field in the Marketing
Event table.
4.

a. From the Variables list, click New


b. Enter the record information.
c. Click Submit.
5. Navigate to Self Service > Service Catalog.
The system displays the Service Catalog categories.
6. Click Can We Help You?.
The system displays the items in the Can We Help You category.
7. Scroll down until you see the Request Marketing Event option.

8. Click Request Marketing Event.


The system displays a blank Request Marketing Event record producer form.
9. Enter the following values.
Table 1. Request Marketing Event sample values

Field Value

Your name Beth Anglin

Event name Service Catalog Demo

Event sponsor ServiceNow, Inc.

City San Jose

Event start date 2016-05-02

Event end date 2016-05-02

Number of attendees expected 25

Expected budget 5000

10. Note: Currently there are no restrictions on the data users can enter in this record producer.
This could result in errors such as city names that do not appear in the choice list and currency
values that include string values for the denomination such as $ for USD, £ for GBP, or ¥ for
JPY.

11. Click Submit.


The system displays the Marketing Event record created from the record producer.
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.

5. Click Submit.
An empty workflow appears. On the right is the palette of tasks and other activities that you can add
to the workflow.
6. Click the Core tab and expand the Approvals folder, then drag the Approval-User activity
between Begin and End.
The New Activity: Approval - User form appears.
7. Enter the name Get VIP Approval.
8. 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).

9. Click Submit.
The workflow is updated.

10. Create a point on the workflow for Set Status to Requested.


a. From the Utilities folder, navigate to Set Values.
b. Drag and drop Set Values between Begin and Approval - User.
The New Activity: Set Values window appears.
c. Enter the name Set Status to Requested.
d. From Set these values, select Approval from the --choose field-- choice list and Requested from
the --None--choicelist.
e. Click Submit.
The workflow is updated.
11. Create a point on the workflow for Set Approval to Approved.
a. Drag and drop Set Values between Approved - User and End.
b. Enter the name Set Approval to Approved.
c. From Set these values, select Approval from the --choose field-- choice list and Approved from
the --None--choice list.
d. Click Submit.
The workflow is updated.
12. Create a point on the workflow for Set Approval to Rejected.
a. Drag and drop Set Values between Approval - User Rejected and End.
b. Enter the name Set Approval to Rejected.
c. From Set these values, select Approval from the --choose field-- choice list and Rejected from
the --None--choicelist.
d. 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.
13. Connect the Set Values node for Set Approval to Rejected.
a. Click Rejected in the Approval - User node and draw the line to the Set Values node for Set
Approval to Rejected.
b. Click Always in the Set Values node for Set Approval to Rejected and draw the line to End.

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. Configure the list and form to add the Approval field.
Note: Refer to Lab 3 if you have forgotten how to configure list and form views.

4. Test the workflow approval process by creating a new Equipment Request record.
a. Navigate to Marketing Events > New Equipment Requests.
The system opens a blank Equipment Request from.

b. Create an equipment request with a Cost greater than $500.


c. Enter appropriate values for any other required fields.
d. Right-click the form header and click Save.
The Approval value changes to Requested.

e. Navigate to Service Desk > My Approvals.


f. From the filter click All to clear current filter and see all approvals.
The new request should be awaiting approval.

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.
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
company’s 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 applications.

The platform security capabilities should not be looked at in isolation, but should be used together to
secure the application. 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 planning, design, development and implementation.

Roles and Access Control Lists


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

A role is a collection of permissions used to grant access to applications and other parts of the
system and to assign security controls. When you used the application creator in exercise 1, it
created a new role (x_scopeID_marketing_ev_user) that you can assign to users who need access
to the application.
An Access control list restricts access at a fine level of granularity by uniquely identifying an object
and providing a list of conditions that must be met to access the object.

Note: The system also uses a unique five-digit number to prefix all of your application components.
This number distinguishes your application from other applications developed by other users.

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 doesn’t have the x_snc_marketing_ev_marketing_event_user


role and verify that the Marketing Event Application isn't visible.
a. Click the Impersonate icon.

b. Search for Beth Anglin and click OK.

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


2. From Impersonate User, switch back to the System Administrator role and create a new group that
has the user role x_snc_marketing_ev_marketing_event_user.
Any user who is a member of this new group automatically inherits the group's user roles. Assigning
user roles to groups and users to groups is the preferred method of granting user roles as it ties a
job function to a user role and also removes the need to individually manage user access rights.
a. Navigate to User Administration > Groups.
b. Click New.
c. Enter the following field values.
Table 1. Group field values

Field Value

Name Marketing Events

Description Users of the Marketing Events applications

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


The system displays the Roles and Group Members related lists.
e. From the Roles related list, click Edit.
f. In the form, add the role generated when you created your application. It will start with the x_ prefix.

g. Click Save.
The system displays the group record.
3. Add Beth as a member of the Marketing Events group.
a. From the Group Members related list, click Edit.
The system displays the Edit Group Members form.
b. From the list of available users, double-click Beth Anglin to add her to group members list.

c. Click Save.
The system displays the group record.
4. Impersonate Beth again. Verify that the application is visible.
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
AdvancedSelected
Insert Selected
When After
Script function onAfter(current, previous) {
//This function will be automatically called when this rule is
processed.
//Replace the table name with your instance's table name
var gr = new
GlideRecord('x_snc_marketing_ev_marketing_event');
gr.get(current.marketing_event);
gr.number_of_attendees_registered += 1;
gr.update();
}
4. Note: In this and all other code samples you will need to update the table name to use the
actual application scope of your instance. This requires replacing the sample table
name x_snc_marketing_ev_marketing_event with your instance's actual table name
such as x_0123_marketing_e_marketing_event.

5. Click Submit.
6. Test by adding a few attendees.
The current registration count should reflect the addition.
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.
Note: All exercises assume you have already created the basic version of the Marketing Events
application during theDeveloper platform introduction training. If you are missing this application,
consider completing the prerequisite training first.

1. From the Banner frame, click the gear icon and scroll down to the Application picker. Verify
the Marketing Events Application you created in prior training is selected.

2. Navigate to System UI > UI Actions.


3. Click New.
4. 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 Selected
menu
Hint Calculate an event’s total equipment cost
Script (function executeUIAction(current, previous) {
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);
}(current, typeof previous != 'undefined' ? previous : null));

5. Note: In this and all other code samples you will need to update the table name to use the
actual application scope of your instance. This requires
replacing x_snc_marketing_ev_ with the actual application scope.

6. Note: Wherever possible, script samples use the Immediately Invoked Function Expression
(IIFE) format to conform to coding best practices.

7. Click Submit.
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.


Steps 2-4 create several sample marketing event and equipment request records. Users who have
completed the Building a sample ServiceNow application training will have already created these
sample records.
2. Create the following sample marketing event records:

Name City Budget Sponsor Start Date End Date

London LUG London $6000.00 Platinum 2016-05-02 2016-05-02


Partners

Dallas LUG Dallas $2000.00 Dallas 2016-05-16 2016-05-19


Partners

a. Click New.
b. Populate the fields.
c. Click Submit.
3. Navigate to Marketing Events Application > New Equipment Requests.
4. Create the following sample equipment request records:

Type Cost Needed From Needed Until Marketing Event

AV $1000.00 2016-05-02 2016-05-02 London LUG

Wireless Mic $300.00 2016-05-02 2016-05-02 London LUG

AV $1000.00 2016-05-16 2016-05-19 Dallas LUG

Wireless Mic $300.00 2016-05-16 2016-05-19 Dallas LUG

a. Click New.
b. Populate the fields.
c. Click Submit.
5. Navigate to Marketing Event > Marketing Events.
6. Click Dallas LUG.
7. Click Show event cost.
The system displays the total cost of the event.
8. From the Equipment Requests related list, select AV.
The system opens the related Equipment Request record
9. Change the Cost from $1,000.00 to $2,000.00.
10. Click Update.
The system displays the parent Marketing Event record.
11. 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 Yes Requires user to manually select action.
event exceeds its budget. Users can still create events that exceed their budget.

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

Requirement Met? Evaluation

Display the available No Could update UI action to compute remaining budget


remaining budget for a from the budget and cost variables and display it.
marketing event. This information might be better stored in a separate
field or determined by a list calculation.

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
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 offers 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.

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 2016-07-09
End Date 2016-07-11
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.
Client scripts

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_marketing_event]
UI Type Both
Type onSubmit
MessagegetMessage('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. Note: The getMessage() API call allows you to display a translated version of an onscreen
message, error, or warning on systems that support multiple languages. For more information
about translating an instance, see the product documentation.
5. Click Submit.
Business rules

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 an equipment 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. Enter the following field values.
Field Value
Name Validate marketing event
Table Marketing Event [x_snc_marketing_ev_marketing_event]
AdvancedSelected
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.

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_marketing_event]
AdvancedSelected
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.');
}
})(current, previous);

4. Click Submit.
Script includes

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
ApplicationMarketing 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 event cost.
4. Update this field value.
Field Value
Script (function executeUIAction(current, previous) {
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);
})(current, typeof previous != 'undefined' ? previous : null);

5. Click Update.

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.');
}
})(current, previous);

5. Click Update

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 event cost.
4. Update this field value.
Field Value
Script (function executeUIAction(current, previous) {
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 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);
})(current, typeof previous != 'undefined' ? previous : null);

5. Click Update.

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: Create a new Service Catalog
In order to meet the needs of our Marketing Events department, you will create a new service
catalog for the Marketing Events team and populate the catalog using the record producer you
created in the Building a Sample ServiceNow application.

You will need to have completed Exercise 9 of the Building a Sample ServiceNow application.

This catalog will contain the Events Requests form that you created with the record producer. By
creating a new catalog your customer's will have a quick and easy way to submit their request.

1. Navigate to Service Catalog > Maintain Catalogs.

2. Click New.

3. Complete the form with the following information:

Field Description

Title Marketing Events Catalog

Description Catalog for requesting goods and services from the Marketing Event Team.
Field Description

Active checked

4. Click Submit.
5. Open the Marketing Events catalog you just created.
6. Click or scroll to Categories.
7. Click New to create a new category.

8. Complete the form with the following information:


Field Description
Title Events Requests
Catalog Marketing Events Catalog
Active checked
9.

10. Click Submit.

Exercise: Use the record producer to populate the


catalog
Use your existing record producer to populate your new catalog.

1. Navigate to Service Catalog > Record Producers.


2. Select Request Marketing Event from the list of available record producers.

3. Click the lock icon next to Catalogs.

4. Click the Add/Remove multiple icon to access the slush bucket.

5. Use the slush bucket to add the Marketing Events Catalog, then click Save.
6. Next select the Categories tab, then click New.

7. Complete the form to add the Events Requests category.

Field Description

Title Event Requests

Catalog Marketing Events Catalog

Active checked

8. Click Submit.
9. You will now need to update the record producer using the table below:
For each variable select Map to Field.
Map each variable to the field specified in the table.

Field Value

Your Name Created by

Event Name Name

Event Sponsor Sponsor

City City

Event Start Date Start Date

Event End Date End Date

Number of Attendees Expected Number of Attendees Expected

Expected Budget Budget

10. Click Update, your variables table should look like this.
Exercise: Add your new catalog to the Catalog
homepage
Add your new catalog to the homepage to allow users easy access to it.

1. Navigate to Service Catalog > Catalogs.


2. Click the plus sign.

A window opens that will allow you to position your new Marketing Events Catalog widget and
decide what that widget should show.

3. Click the left most Add here button, then click the ⊗ in the uper right corner.
4. Your screen should look like this.

Exercise: Create a new group


Create a new group for the next exercise.

In many business process definitions, approvals are requested before work can be performed.
However, approvals can also be requested as work is progressing. In the event that subsequent
approvals are rejected or tests or tasks fail, the Workflow Editor offers the Rollback To activity. This
activity allows the process designer to return to an earlier place in the workflow and restart it. The
Rollback To activity will adjust the state of User Approvals and Tasks that are part of a rolled back
set of activities. Before you can begin, you will need to have completed Exercise 11 of Building a
Sampl ServiceNow Application.
1. Navigate to System Security > Groups.
2. Search for the Catalog Request Approvers > $1000 group.
3. Modify the form with the following information.
Option Action
Name Equipment Request Approvers > $500
DescriptionThis is a group of users that need to approve an equipment request that is greater
than $500.
4. Click the Group Members tab.
5. Click Edit.
6. Use the slush bucket to add Fred Luddy to the group.
7. Click Save.
8. Next click Update.

The Equipment Request Approvers group is now viewable in the Group list.

Exercise: Access Workflow Editor


Use the Workflow Editor to modify your Equipment Request Workflow.

1. Navigate to Workflow > Workflow Editor.


2. In the Workflows tab at the right, click Equipment Request Workflow.
3. Click the list menu icon on the Equipment Request Workflow tab at the left and click Checkout to
edit the workflow.
In the next exercise you will modify your workflow to assign approvals to a group.

Exercise: Assign approval to a group


Modify the existing work flow to assign the approval to a group.

1. In the Core Activities list on the Core tab, expand the Approvals folder and locate the Approval-
Group activity.
2. Drag Approval-Group onto the transition line between the Set Status to Requested set values
activity and the Get VIP Approval activity.
3. Fill in the fields on the form, as appropriate.

Field Description

Name Equipment Request Approvers

4. Select the Group lock icon.

5. Select the Search looking glass icon.


6. Select the Equipment Request Approvers > $500 as the group.
7. Click Submit.
8. Remove the Get VIP Approval by clicking the x in the right hand corder of the activity.

9. Create a new transition line from Equipment Request Approvers Rejected to Set Approval to
Rejected.
10. Your workflow should look similar to this example.
Exercise: Add Rollback To activity
Use the Rollback To activity to change the state of the request back to Requested.

Our workflow is now set to automatically approve all equipment requests less than $500 dollars.
Anything over that amount will be assigned to the Equipment Requests Approvers group for
approval. In the event that a member of the group rejects the request, we are going to add a
Rollback To activity to change the state of the request back to Requested.

1. Expand the Approvals category in the Activities tree.


2. Double-click the Rollback To activity in the Approvals folder.
3. Fill out the form as shown:

Field Description

Name Approvals Rolled Back

4. Click Submit.
5. Drag the transition line from Equipment Request Approvers Rejectedto Approvals Rolled Back.
6. Drag the transition line from Approvals Rolled Back Always to Set Approval to Rejected.
7. Drag another transition line from Approvals Rolled Back Always to Set Status to Requested.
8. Your workflow should look like this.
9. Select the Workflow Actions menu then click Publish.

Exercise: Using the Rollback To activity


We added the Rollback To activity in this scenario to reset the status of the original request back
to Requested. Let's verify that our workflow is working properly.
1. Navigate to Marketing Event > Equipment Request > and click New.
2. Complete the form with the following:
Field Description
Cost 750
Field Description
Needed From 2015-12-02
Needed Until 2015-12-02
Approval Not Yet Requested
Marketing Event Dallas Lug
3. Click Submit.
4. Navigate to Service Desk > My Approvals.
5. There are two new approvals for the members of the Equipment Request Approvers group.

6. Select one of the approvals and change the state to Rejected.

7. You should see the state go from Rejected to Not Yet Requested due to the Rollback To activity.
Notice that the state for the 2nd approver did not change.

Exercise: Configure Related Lists


Configure the Related Lists for the Equipment Requests form.
1. Navigate to Marketing Events > Equipment Requests.
2. Click New.
3. Before you complete the form, right-click and select Configure > Related Lists > .

The Related lists will be used to verify your Create Task activity later on in the lab.
4. From the Available lists select Approvers and Task > Parent, use the arrows to add them to the
Selected list.
5. Click Save.
6. Complete the form to create a new Equipment Request, then click Submit.

Set the cost to greater than 500 dollars in order to trigger your workflow.

7. Locate your new equipment request from the list and open it. You will see the related lists now
appear at the bottom of the form.
Exercise: Add the Create Task activity
Create a task that will be assigned to the System Administrator.

1. In the Application Navigator select Workflow Editor.


2. In the Workflow Editor select Equipment Request Workflow from the Workflows tab section from
within the canvas.
3. The workflow should look similar to this.
4. Select Workflow Actions Menu > Checkout.
5. Click the Core tab.
6. Under Task, select the Create Task activity.
7. Drag and drop the Create Task activity between Equipment Request Approvers and Set
Approval to Approved.
8. Complete the form as shown.
Option Description
Name Order equipment task
Task Type Task [task]
Wait for Completion is checked
Assigned to System Administrator
Short Description Order equipment associated with the request.
9. Click Submit.
10. Publish your workflow.
Your workflow should look similar to the example below.
Exercise: Create a new equipment request
Create a new request to verify that your create task activity is generated by your workflow.

1. Create a new equipment request.


2. Select your request, then click the Approvers tab.
3. Change the state to Approved for the first approval.

4. Right click the header bar and select Refresh List.


The 2nd approval state has now changed to No Longer Required.
5. Click the Tasks tab, right click the header bar and select Refresh List.
6. You will have a new task associated with the equipment request assigned to the System
Administrator and you should see the group approval has a state of Closed Complete.

Exercise: Create a new report


Create a bar report to show the Marketing Events budget by city.

1. Navigate to Reports > Create New.


2. Fill out the form with the following information:
Field Description
Report Title Marketing Events Budget by City
Data Table Marketing Event
Type Bar
Group by City
Stacked by None
Aggregation Sum > Budget
3. Click Run.
4. Next click Save.

A gauge is a graphic image on a homepage that when clicked will link to the list of the records
specific to that piece of the graph. After you have saved your report you can make it a gauge and
add it to your homepage.

5. Select the dropdown arrow next to the Save button and click on Make gauge..
6. Select the dropdown arrow again and click on Add to Homepage. Select the drop zone you wish to
add it to by clicking Add here.
7. Next navigate to Self Service > Homepage and you will see your new report.
Exercise: Create a scheduled job
Scheduled jobs are automated pieces of work that can be performed at a particular time or on a
recurring schedule.

Schedule the Marketing Events Budget by City report to run weekly and be sent to theEquipment
Request Approversgroup.

1. Navigate to Reports > View/Run.


2. Search for Marketing in the search field.
3. Select the Marketing Events Budget by City report.
4. Click the dropdown arrow next to the Save button.
5. Select Schedule.
6. Fill out the form with the following information:
Field Description
Groups Equipment Request Approvers
Subject Weekly Marketing Events Budget by City Report
Run Weekly
Day Tuesday
7. Click Submit.
8. Navigate to System Definition > Scheduled Jobs.
9. Click on Updated to sort by recently updated. You should see your scheduled job listed.

You might also like