Meetup Lab: Service Portal Killer UX — Build a Notes App

servicenow service-portal

Enable AI Animation

Build a full CRUD notes application in Service Portal. This lab covers list widgets, body widgets, event broadcasting, inline editing, filters, create, and delete.
This lab originally from the sndevs meetups repo and hosted on GitHub Pages.

Prep: Install the Update Set

  1. Get your PDI at developer.servicenow.com
  2. Download and install the CreateNotes XML update set
  3. Set default value on x_snc_createnotes_note.user: javascript:gs.getUserID();

Lab 0: Explore the Notes App

Take a look at the custom Notes application and create some demo data. Make sure notes have all fields set.

Lab 1: Create Notes List Widget

Create a custom widget that displays the list of notes. Broadcast the sys_id of the selected note when clicked.

  1. Launch the CreateNotes portal
  2. CTRL+Right Click on the Notes List widget box → Widget in Editor
  3. Enable HTML Template, Client Script, and Server Script sections

Server Script

Add code to query the notes table and return data to the client.

Server script

View $scope.data

Reload the portal. CTRL+Right click on the widget and inspect $scope.data to verify the server data is reaching the client.

HTML Template

Populate the notes onto the page:

HTML template

Add ng-click

ng-click

Broadcast Selected Note

Add the client script to broadcast the selected note’s ID:

Broadcast

Broadcast cont

Verify

Click on notes. You should see “Note ID: SYS_ID” in the console.

Verify

Lab 2.1: Configure Note Body Widget

Configure the widget that shows the content of the selected note.

  1. Change the current widget to the Note Body widget
  2. Add event listener for the broadcast:

Event listener

Get Content from Server

Add client script to call c.server.get():

Client get

Server Script

Use the input object to get GlideRecord data:

Server script

HTML Template

Show the data in a panel:

HTML template

Make it Pretty

Pretty

Verify

Click a note — it should load on the right:

Verify

Lab 2.2: Auto-Save on Typing

Configure the body widget to auto-update notes as you type.

HTML Attributes

Add trigger attributes to input and textarea fields:

HTML input

Client Script

Add function to run when fields change:

Client script

Server Script

Write changes back to the server:

Server script

Verify

Change a title, wait a few seconds, refresh. The title should persist.

Lab 3.1: Real-Time Title Updates

Edit both widgets so changing the title in the body updates the list widget without a refresh.

Body Widget Server Script

Return the updated title back to the client:

Server return

Body Widget Client Script

Broadcast the updated title:

Broadcast title

List Widget Client Script

Listen for the broadcast and update the title:

Listen

Fix the note ID reference:

Fix note ID

Lab 3.2: Add Filter

Add an input box to filter the notes list.

List Widget HTML Template

Filter HTML

Verify

Typing in the filter field should filter the notes list.

Lab 4.1: Add New Note Button

Add a button that creates a new note.

List Widget HTML

New button HTML

CSS

CSS

Client Script

Call server side to create:

Client create

Server Script

Create the new note record:

Server create

Verify

Click the New button. A new note should appear in the list and be available for editing.

Lab 4.2: Delete Note

Add a delete button to the note editor.

Body Widget HTML

Delete HTML

Body Widget Client Script

Delete client

Body Widget Server Script

Delete server

List Widget Client Script

Remove the note from the list:

Remove from list

Verify

Click a note, click delete. It should disappear from the screen and the list.


View this page on GitHub.