ServiceNow Developer Training – An Introduction To ServiceNow Scripting

Last updated on Sep 26,2020 12.1K Views

Vishal is a technology enthusiast working as a Research Analyst at Edureka.... Vishal is a technology enthusiast working as a Research Analyst at Edureka. He has expertise in domains like Big data, Machine Learning,Statistical Analysis and...
1 / 2 Blog from ServiceNow Development

ServiceNow is one of the most popular ITSM tools that brings in automation in various business processes. In this blog, I am going to discuss ServiceNow from a developer’s perspective. So let us not waste any time and get started with this ServiceNow Developer Training Blog. 

This blog will walk you through following points:

  1. What Is ServiceNow
  2. Introduction To Scripting
  3. ServiceNow Developer Training Demo

So let us start with the first topic of discussion in this ServiceNow Developer Training blog

What Is ServiceNow?

ServiceNow is a software platform that supports IT service management and automates common business processes. It contains a number of modular applications that can vary by instance and user. ServiceNow is an integrated cloud solution which combines major cloud and business services into a single system of record. 

ServiceNow whose journey began with IT Service Management applications providing Service Catalog Management, today supports both IT Service Management Processes and IT Enterprise such as HR Management, Security Management and PPM, etc.

ServiceNowPlatform - ServiceNow Developer Training - Edureka

Following features make ServiceNow better than its competitors:

  • Instance based implementation
  • Ease of customization
  • Better Support and low maintenance cost
  • Real time analysis and reporting

 This was a short introduction to ServiceNow. Next in this ServiceNow Developer Training blog we would understand what is scripting in ServiceNow:

Introduction To Scripting

script is nothing but a computer programming language with a series of commands that are capable of being executed without being compiled. In simple words scripting is configuring your system to perform certain tasks which are triggered by specific events.

You can classify scripting in two types: Server Side Scripting and Client Side Scripting

Server Side Scripting

It is script that runs on a web server, which produces a response customized for each user’s request to the website. Server side scripts execute on the server or the database

Server-side scripting is often used to provide a customized interface for the user. These scripts may assemble client characteristics for use in customizing the response, based on those characteristics, the user’s requirements, access rights, etc. Server-side scripting also enables the website owner to hide the source code that generates the interface.

Client Side Scripting

Client scripts run on the client (web browser). You can use client scripts to define custom behaviours that run when events occur, such as, when a form is loaded or submitted, or a cell value changes. Proper client-side processing depends on the form loading completely first. Making record updates prior to form load can produce unexpected results that bypass client-side processing. Client-side Glide APIs (Application Programming Interfaces) provide classes and methods that you can use in scripts to perform client-side tasks.

Users with basic knowledge of JavaScript can define scripts to run in the client browser. Several types of client scripts are supported by ServiceNow. Let us take a look at those:

  • onLoad()
  • onChange()
  • onSubmit()
  • onCellEdit()

onLoad() 

An onLoad() script runs when the form loads before the user ever sees it. The values on the form are straight from the database. This type of script lets you control how the form first appears to the user.

onChange()

An onChange script runs when the user changes value in any of the field. This script is handy for setting up a value of a field or displaying value based on the values user enters in the other fields. 

onSubmit()

An onSubmit script runs when the user submits the form. This type of script is useful for validating the values the user entered.

onCellEdit()

An onCellEdit() script is very similar to onChange() script. However there is one major difference between the two. onCellEdit() script runs when the user changes value of the fields in list.

ServiceNow Developer Training: Demo

In this ServiceNow Developer Training demo we start by creating a github account. 

Creating a Github account:

Step 1: Go to the following link to create and a Github account. Following page will appear. SignIn, if you already have an account else follow the steps to SignUp

github - ServiceNow Developer Training- Edureka

 

Step 2: Fill in the above mentioned details and click on Sign Up. Following window will appear, fill in the details required in fields shown below

github - ServiceNow Developer Training - Edureka

 

Step 3: GitHub will request you following details, fill in those as well and click on continue

github - ServiceNow Developer Training - Edureka

 

Step 4: Once you have done this, a formal information page would appear, fill in that information and you are good to go.

github - ServiceNow Developer Training - Edureka

 

Step 5: Once you do this, your account is created. Next verify your account by clicking on the link that GitHub will send to your registered e-mail ID.

Forking needit repository in ServiceNow

Step 1: Next open your browser and Enter this ‘https://github.com/ServiceNow/devtraining-needit-jakarta‘ link. The link will redirect you to the following page. Now let us fork the ‘devtraining – needit – jakarta’ repository with our ServiceNow instance by clicking on fork

Github5 - ServiceNow Developer Training - Edureka

 

Step 2: After you have forked the repository. GitHub will give you an option to clone the repository. Click on the clone tab, Github will generate following link for you, copy the link. You may download the zip file or directly open it on the desktop. 

Github8 - ServiceNow Developer Training - Edureka

We have successfully forked the GitHub repository. Now Let us go ahead and create a client script using our repository.

ServiceNow Developer Training : Creating A Client Scrip

Step 1: Go to Application Navigator in your ServiceNow Instance. Type Studio and open it.

Github9 - ServiceNow Developer Training - Edureka

 

Step 2: Following tab will open. Click on Import Source Control to import the repository. 

Client Script2 - ServiceNow Developer Training - Edureka

 

Step 3: Following window will appear. Enter the link we copied while cloning the repository, also enter the GitHub credentials, we used to create the account. Click on import

Client Script3 - ServiceNow Developer Training - Edureka

 

Step 4: Following page will appear. Click on the NeedIT repository. 

Client Script4 - ServiceNow Developer Training - Edureka

 

Step 5: In Studio, open the Source Control menu and click the Create Branch option

Client script image5 - ServiceNow Developer Training - Edureka

 

Step 6: Configure the Branch with following credentials:

Branch Name: ClientScriptsModule. Create from Tag: LoadForClientScriptsModule. 
Click the Create Branch button. Click the Close Dialog button.
clientscript - ServiceNow Developer Training - Edureka
Step 7: Click the Create Application File button. Choose the new file type, in this case, Client Script. Configure the new file.
ClientScript - ServiceNow Developer Training - Edureka
Step 8: Go to studio, click on client scripts and finally on NeedITonChangeExample. Fill in the details and scroll down.
Clientscript - ServiceNow Developer Training - Edureka
Step 9: Following script will help you implement changes that are made to the form. Click on submit or update.
ClientScript - SServiceNow Developer Training - Edureka
Step10: Similarly update records NeedIT onChange Example and NeedIT onSubmit Example
First lets do it for NeedIT onLoad Example.
Onload - ServiceNow Developer Training - Edureka
OnLoad - ServiceNow Developer Training - Edureka
 Finally we update the NeedIT onSubmit Example client script.
onsubmit - ServiceNow Developer Training - Edureka
onsubmit - ServiceNow Developer Training - Edureka
We have successfully updated our three sample Client scripts. Now is the time to test them.

Testing The Client Scripts

Step 1: In the main ServiceNow browser window (not Studio) use the Application Navigator to open NeedIt > All. Select a record of your choice and open it. If your client script is active. It will display an alert as shown in the image below.Testing - ServiceNow Developer Training - Edureka

Step 2: Press OK. Now make a change to the record. Change the priority to moderate and click on update. The onSubmit alert would pop out.

Testing - ServiceNow Developer Training - Edureka

Step3: Finally Let us test the onChange client script. To do that, make a change to the short description and update it. The alert would pop out as shown in the image below.

 Testing - ServiceNow Developer Training - Edureka

This verifies that all are client scripts are working and thus we have successfully created client scripts and implemented them accordingly. This brings us to the end of this ServiceNow Developer Training Blog.

Want to be an expert in ServiceNow?? Become a ServiceNow Expert starting from Edureka’s ServiceNow Admin Certification Training and ServiceNow Developer Certification Training which helps learners become expert in Administering the SN platform, Develop the Scripts for the Business processes, Workflows, Import Sets using real-time use cases on Banking, Sales, Finance domain.

Got a question for us? Please mention it in the comments section and we will get back to you.

Comments
1 Comment

Join the discussion

Browse Categories

Subscribe to our Newsletter, and get personalized recommendations.