7. Explain your experience with ServiceNow scripting languages such as Glide, Jelly, and AngularJS.

Advanced

7. Explain your experience with ServiceNow scripting languages such as Glide, Jelly, and AngularJS.

Overview

ServiceNow's scripting languages, such as Glide, Jelly, and AngularJS, play a crucial role in extending and customizing the platform to meet specific business requirements. Glide provides server-side scripting capabilities, Jelly is used for creating dynamic content, and AngularJS is utilized for building client-side applications. Mastery of these languages is essential for developing robust, efficient, and user-friendly ServiceNow applications.

Key Concepts

  1. Glide Scripting: Server-side scripting that interacts with the ServiceNow database and API.
  2. Jelly Scripting: Templating engine used for rendering dynamic HTML and creating interactive UI components.
  3. AngularJS: A client-side JavaScript framework used in Service Portal widgets for creating rich and interactive user interfaces.

Common Interview Questions

Basic Level

  1. What is GlideRecord and how is it used?
  2. Provide an example of a basic Jelly script in ServiceNow.

Intermediate Level

  1. How would you optimize a GlideRecord query for better performance?

Advanced Level

  1. Describe how you would design a Service Portal widget using AngularJS that interacts with ServiceNow's backend.

Detailed Answers

1. What is GlideRecord and how is it used?

Answer: GlideRecord is a ServiceNow API used for querying and manipulating data from the platform's database tables. It is a server-side scripting API that provides methods to perform database operations like create, read, update, delete (CRUD), and query records. GlideRecord is essential for developers to interact with the ServiceNow database programmatically.

Key Points:
- GlideRecord is used for server-side scripting.
- It enables CRUD operations on database records.
- Essential for accessing and manipulating ServiceNow data programmatically.

Example:

// Example to query the Incident table and print the incident numbers
GlideRecord gr = new GlideRecord('incident'); // Specifying the table
gr.query(); // Querying the table without condition, retrieves all records
while(gr.next()) {
    Console.WriteLine(gr.getValue('number')); // Printing the incident number
}

2. Provide an example of a basic Jelly script in ServiceNow.

Answer: Jelly is a scripting language used in ServiceNow to generate dynamic HTML content. It's often used in UI pages, UI macros, and email templates to render data dynamically.

Key Points:
- Jelly is XML-based and allows for dynamic content rendering.
- It can access ServiceNow data using Glide and other ServiceNow APIs.
- Often used in UI customization and dynamic email content.

Example:

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null">
    <g:evaluate var="jvar_helloMessage">"Hello, " + gs.getUser().getFirstName() + "!"</g:evaluate>
    <div>${jvar_helloMessage}</div>
</j:jelly>

This Jelly script greets the current user by first name.

3. How would you optimize a GlideRecord query for better performance?

Answer: Optimizing GlideRecord queries is crucial for maintaining high performance in ServiceNow applications. Techniques include limiting the number of records retrieved, specifying query fields, and using pagination for large datasets.

Key Points:
- Use setLimit() to restrict the number of records.
- Specify only necessary fields with setWorkflow(false) and setView('').
- Use pagination for large datasets with getRowCount() and chooseWindow().

Example:

GlideRecord gr = new GlideRecord('incident');
gr.addQuery('active', true); // Adding condition to fetch only active incidents
gr.setLimit(100); // Limiting the result set to 100 records for performance
gr.query();
while(gr.next()) {
    Console.WriteLine(gr.getValue('number'));
}

4. Describe how you would design a Service Portal widget using AngularJS that interacts with ServiceNow's backend.

Answer: Designing a Service Portal widget using AngularJS involves creating a client-side application that communicates with the ServiceNow backend via the ServiceNow API. The widget should encapsulate functionality making it reusable and maintainable.

Key Points:
- Utilize AngularJS's MVC architecture for a clean separation of concerns.
- Use ServiceNow's $http service for backend communication.
- Ensure the widget is modular and reusable across the Service Portal.

Example:

// AngularJS controller for the widget
function MyWidgetController($scope, $http) {
    $scope.loadData = function() {
        var serverURL = '/api/now/table/incident'; // ServiceNow API endpoint
        $http.get(serverURL).then(function(response) {
            $scope.incidents = response.data.result; // Assigning fetched data to scope variable
        });
    };

    $scope.loadData(); // Initial load
}

// HTML template part of the widget
<div ng-controller="MyWidgetController">
    <ul>
        <li ng-repeat="incident in incidents">{{incident.number}} - {{incident.short_description}}</li>
    </ul>
</div>

This example demonstrates a basic Service Portal widget that fetches and displays incidents from ServiceNow using AngularJS.