Example - Conference Room Bookings

From ServiceNow Wiki
Home > Build > Applications > Example - Conference Room Bookings (Redirected from Example:Conference Room Bookings)
Jump to: navigation, search
Note
Note: The ServiceNow Wiki is no longer being updated. Visit http://docs.servicenow.com for the latest product documentation.


Applications
Related Topics
Get the Book
Knowledge.gif Applications

1 Overview

This example guides you through creating a simple custom application for managing conference room requests. To learn more about the features demonstrated in this example, see Further Reading.

1.1 Audience

This guide is intended for junior ServiceNow system administrators. You should be familiar with the platform, but you don't need much experience developing or maintaining custom tables. A basic understanding of JavaScript and relational databases would be helpful, but is not necessary.

2 Create an Application Record

These steps allow application developers to quickly create a simple application containing a single table. After completion you will have the following application artifacts:

  • An application record called Book Rooms.
  • An application scope containing the your unique vendor identifier. For example. x_acme_book_rooms.
  • An application menu called Book Rooms.
  • A user role containing the application's unique namespace identifier. For example, x_acme_book_rooms_user.
  • An application version number set to 1.0.
  • A set of access control rules granting access to the Book Rooms menu and modules.
  • A set of application file records

To create your application record:

  1. Navigate to System Applications > Create Application.
  2. From the Create custom application row click Create.
  3. Define the application by completing the following fields on the form. Use the default values for the rest of the fields.
    • Name: Book Rooms
    • Create Table: Slide to enable.
    • Label: Conference Rooms.
    • Extends Table: Configuration Item.
    • Auto-number: Slide to enable.
    • Prefix: ROOM
    Create custom application options

  4. Click Create.
  5. Click OK to confirm the creation of the application.
    Confirm application creation

    The system displays a success message with options to view the custom application record or the table record.
    Application creation success

  6. Click View app record.
    The system automatically selects the new application from application picker and creates a new update set to save changes.
    Book Rooms custom application record

3 Update the Application Record

Application developers can update the custom application record to provide the application additional functionality. After completion you will have the following application artifacts:

  • A short description
  • A logo

To update the application record:

  1. Define the following fields on the form.
    • Short description: Book conference rooms.
    • Logo: pick a suitable image.
    Updates to the Book Rooms custom application record

  2. Click Update.

4 Build the Data Model

These steps will create the tables where you can store application-specific data. After completion, you will have the following application artifacts:

  • A table to store conference rooms
  • A table to store conference room booking requests

4.1 Add Fields to the Conference Rooms Table

The system automatically created this table during the application creation process. However, you must edit this table to add some additional columns.

  1. On the application record, scroll down to the Tables related list.
    Tables related list

  2. Open the Conference Rooms table record.
  3. From the Table Columns embedded list, add new columns as defined in the table (see below).
    New fields

  4. Click Update.
    • The system adds the new columns.
    • The new columns appear as application file records (sys_dictionary).
Column label Type
Capacity Integer
Floor Integer
Phone number Phone Number (E164)
Polycom True/False
Projector True/False
WiFi True/False

4.2 Create the Room Request Table

Create the Room Request table to store requests for room reservations.

  1. Click System Applications > Applications.
  2. From the Tables related list, click New.
  3. In Label, enter Room Requests.
  4. From the Columns section, create the fields from the table below.
    Room Requests table

  5. From the Controls section, select Auto-number.
  6. In Prefix, enter ROOMREQ.
  7. Click Submit.
    The system:
    • Creates the Room Request table.
    • Creates access controls to grant the user role full access to the Room Requests table.
    • Creates a module for the Room Request table under the Book Rooms application menu.
    • Creates and assigns application file records to the Book Rooms application.
Column label Type
Requester Reference to User
Conference Room Reference to Conference Rooms
Attendees Integer
Start Date Date/Time
End Date Date/Time
Duration Duration

5 Design the User Interface

Design the user interface to facilitate data entry and business logic. After completion, you will have the following application artifacts:

  • Conference Rooms table
    • A display value override
    • A list layout
    • A set of autocomplete attributes
    • A form design
    • A set of sample data
  • Room Requests table
    • A list layout
    • A form design
    • An updated module

5.1 Override the Conference Rooms Display Value

Our application data table extends the Configuration Item [cmdb_ci] table, which does not define a display value field. Create a dictionary override to make the Name field the display value.

  1. Open the Conference Rooms table record.
  2. From the Table Columns embedded list, select the Name field.
  3. From the Dictionary Overrides related list, click New.
  4. Select Override display value.
    Override the display value

  5. Click Submit.

5.2 Layout the Conference Rooms List

Use the standard configure options to layout the conference rooms list.

  1. Open the Conference Rooms table record.
  2. From related links, click Layout List.
  3. Add the following fields to the list.
    • Name
    • Location
    • Capacity
  4. Click Save.

5.3 Set Autocomplete Attributes for Conference Rooms Table

We want all references to the Conference Rooms table to display and search for information in the Location and Capacity columns.

  1. Navigate to System Definition > Dictionary.
  2. Open the collection record for the Conference Rooms table.
  3. Click the Advanced view related link.
  4. In the Attributes field, enter the following:
    ref_auto_completer=AJAXTableCompleter,ref_ac_columns=location;capacity,ref_ac_columns_search=true
    Dictionary record for the Conference Rooms table

  5. Click Update.

5.4 Design the Conference Rooms Form

Use form design to layout the conference rooms form.

  1. Open the Conference Rooms table record.
  2. From related links, click Design Form.
  3. Add fields and sections to the form.
    Conference Rooms form design

  4. Click Save.
  5. Close the form design tab.

5.5 Add Conference Room Data

Enter data for available conference rooms:

  1. Navigate to Book rooms > Conference Rooms.
  2. Click New.
  3. Enter the room details as listed in the table.
  4. Click Submit.
  5. Repeat steps 1 – 4 for all rooms in the table.
Name Capacity Location Floor Phone number Projector Polycom Wifi Can Print
Aruba 7 San Diego 3 North America

(858) 430-9812

true true false false
Fiji 10 Austin 19 North America

(512) 398-4531

true true true true
Jamaica 30 United Kingdom 10 United Kingdom

+44 (0)844 343 9086

true true true true
Oahu 20 Denver 2 North America

(720) 490-2346

true true true false
Tahiti 5 Tokyo 7 Japan

+81 3-3098-4356

true false true false

5.6 Layout the Room Requests List

Use the standard configure options to layout the room requests list.

  1. Open the Room Requests table record.
  2. From related links, click Layout List.
  3. Add the following fields to the list.
    • Number
    • Requester
    • Conference Room
    • Start Date
    • Duration

5.7 Design the Room Requests Form

Use form design to layout the conference rooms form.

  1. Open the Room Requests table record.
  2. From related links, click Design Form.
  3. Add fields and sections to the form.
  4. Set the Conference Room and Attendees fields to Mandatory.
    Room Requests form design

  5. Click Save.
  6. Close the form design tab.

5.8 Update the Room Requests Module

Change the title for the automatically created Room Requests module:

  1. Navigate to Book rooms.
  2. Right-click the icon beside Room Requests and select Edit Module.
  3. Change the title to Book a conference room.
    Change the title of the Room Requests module

  4. Click Update.

6 Add Business Logic and Automation

Add business logic and automation to improve application usability.

6.1 Populate the Requester Automatically

Automatically populate the Requester field with the current user:

  1. Open the Room Requests table record.
  2. From the Columns section, select the Requester field.
  3. In the Default value field, enter this code:
    javascript:gs.getUserID()
  4. Click Update.

6.2 Validate Room Requests

Create a business rule to validate that a room request's number of attendees does not exceed the conference room's capacity.

  1. Select Book Rooms from the application picker.
  2. Navigate to System Definition > Business Rules.
  3. Click New.
  4. Enter or select the values listed below.
    Validate room requests business rule

  5. Click Submit.
Field Value
Name Validate room request
Table Room Requests
Advanced Selected
When to run
When before
Insert Selected
Update Selected
Advanced
Condition current.attendees > current.conference_room.capacity
Script
function onBefore(current, previous) {
   //This function will be automatically called when this rule is processed.
   gs.addInfoMessage('Request not created. The conference room ' + 
   current.conference_room.name + ' cannot support ' + current.attendees + 
   ' attendees. The max capacity is ' + current.conference_room.capacity + '.');
	current.setAbortAction(true);
}

6.3 Send an Email Confirmation

Email the requester to confirm creation of the request:

  1. Enable email on the instance. See Configuring Email.
  2. Navigate to System Policy > Email > Notifications.
  3. Click New.
  4. Define the email notification by completing the fields on the form (see table). Use the default values for the rest of the fields.
    Room request email notification

  5. Click Submit.
Field Value
Name Room requests
Table Room Requests
When to send
Inserted Select the check box
Updated Select the check box
Who will receive
Users/groups in fields Requester
What it will contain
Subject Created room request #${u_number}
Message You have reserved the ${conference_room} conference room on ${start_date} for ${duration}. See ${URI_REF} to make changes.

7 Test the Application

Confirm that you application logic is working.

  1. Navigate to User Administration > Users and open a test user record.
  2. Ensure the user has a valid email address.
  3. Grant the Book Rooms user role to the user.
  4. Impersonate or log in as the user.
  5. Navigate to Book Rooms > Book a conference room.
  6. Click New.
    Notice that the Requester field is automatically populated with the user name.
  7. In the Conference Room field, begin typing A.
    Notice that the autocomplete shows the name, location, and capacity for matching rooms.
    Autocomplete for the Conference Rooms table

  8. Select Aruba.
  9. In the Attendees field, enter 100.
  10. Complete the rest of the form.
  11. Click Submit.
    The business rule validation fails.
    Business rule validation fails

  12. In the Attendees field, enter 5.
  13. Click Submit.
    The business rule validation succeeds, and the system creates a new room request record.
  14. Log back in as an administrator.
  15. Navigate to System Mailboxes > Outbound > Sent.
  16. Remove the Mailbox = Sent condition from the breadcrumbs.
  17. Open an email record.
  18. Under Related Links, click Preview HTML body.
  19. Validate that the email notifications contain the correct information.

8 Publish the Application

  1. Navigate to System Applications > Applications.
  2. Open the application record.
  3. Under Related Links, click Publish to Update Set.
  4. Click Publish.
  5. On the confirmation screen, click Update Set to view the update set that you can use to transfer the application to another instance.

9 Further Reading

These articles contain details about the features demonstrated in this example.

Section Suggested Wiki Links
Create an Application Record
Build the Data Model
Design the User Interface
Add Business Logic and Automation
Test the Application
Publish the Application
Was this article helpful?
Yes, I found what I needed
No, I need more assistance