0% found this document useful (0 votes)
4 views12 pages

Scenario Based Servcienow Interview Question - Solution

The document outlines various scenarios and solutions for automating processes in ServiceNow, including incident closure, filtering change requests, preventing modifications on closed incidents, and managing catalog items. It provides detailed steps for implementing scheduled jobs, business rules, client scripts, and workflows, along with sample scripts for each scenario. Additionally, it discusses integrating with external knowledge bases and debugging workflows stuck on approval, emphasizing the importance of automation and user experience in IT service management.

Uploaded by

Altamash Mujawar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views12 pages

Scenario Based Servcienow Interview Question - Solution

The document outlines various scenarios and solutions for automating processes in ServiceNow, including incident closure, filtering change requests, preventing modifications on closed incidents, and managing catalog items. It provides detailed steps for implementing scheduled jobs, business rules, client scripts, and workflows, along with sample scripts for each scenario. Additionally, it discusses integrating with external knowledge bases and debugging workflows stuck on approval, emphasizing the importance of automation and user experience in IT service management.

Uploaded by

Altamash Mujawar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

©️SHAAH ABIIR

1. Automating Incident Closure Scenario

Scenario: The Service Desk team has noticed that many resolved Incident tickets remain in
the "Resolved" state for extended periods. The IT Manager wants to automatically close
Incidents 7 days after they are moved to the "Resolved" state, provided the "Reopen count" is
zero.

Specific Questions:

1. What type of ServiceNow automation would be best suited to handle this


requirement? Explain your reasoning.
2. Describe the steps you would take to configure this automation, including any
conditions you would need to set.
3. Write a sample script (if necessary) that checks the "Resolved date" and "Reopen
count" to determine if an Incident should be automatically closed.

Detailed Solutions:

1. Solution: A Scheduled Job (System Definition > Scheduled Jobs) is the most
appropriate automation for this scenario. Scheduled Jobs run at defined intervals and
can process multiple records based on specific criteria. This is ideal for a recurring
task like checking and updating Incident records.
2. Solution: The steps would involve:
o Creating a new Scheduled Job.
o Setting the Run field to "Daily" or another appropriate frequency.
o Setting the Run this script option and writing the necessary script.
o In the Condition field, you would likely leave it blank or set it to true to
ensure the script runs every time the job is executed. The filtering logic will be
within the script itself.
3. Solution (Sample Script):

(function() {
var gr = new GlideRecord('incident');
// Query for incidents in the 'Resolved' state
gr.addQuery('state', '=', 6); // Assuming '6' is the value for
'Resolved'
gr.addQuery('reopen_count', '=', 0);
// Query for incidents resolved more than 7 days ago
var sevenDaysAgo = new GlideDateTime();
sevenDaysAgo.addDays(-7);
gr.addQuery('resolved_at', '<=',
sevenDaysAgo.getDisplayValue());
gr.query();

while (gr.next()) {
gr.setValue('state', 7); // Assuming '7' is the value for
'Closed'
gr.update();
gs.log('Incident ' + gr.number + ' automatically closed.');

©️This Content Is Solely Prepared by SHAAH ABIIR, If You Want to Meet Me One-On-One, Please Book
an Appointment with Me Here: https://tinyurl.com/2brstwjq
©️SHAAH ABIIR

}
})();

2. Filtering Change Requests by Assignment Group Scenario

Scenario: The Change Management team wants a custom list view that only shows Change
Requests assigned to the logged-in user's assignment group. This view should dynamically
update as the user's assignment group changes.

Specific Questions:

1. How would you create this custom list view with the specified filtering?
2. What ServiceNow feature allows for dynamic filtering based on the logged-in user's
information?
3. Explain how you would ensure this filter applies only to the specific custom list view
and doesn't affect other Change Request views.

Detailed Solutions:

1. Solution: You would create a new List View for the Change Request table
(change_request). When configuring the filter for this view, you would apply the
necessary condition.
2. Solution: You would use a dynamic filter option that leverages system variables
related to the logged-in user. Specifically, you would filter where the "Assignment
group" field "is (dynamic)" and then select "Me (Group)". This dynamic filter
automatically evaluates to the assignment groups of the currently logged-in user.
3. Solution: When creating or modifying the list view, ensure that you are doing so
either by personalizing your own list view (which would only affect you) or by
creating a new named view (e.g., "My Group's Changes"). You can do this by going
to the Change Request list, personalizing the list columns and filters, and then using
the list control menu (gear icon) to save the view with a specific name. To make it
available to others in your group, you might need administrative privileges to create a
new view that is shared with a specific group or role.

3. Business Rule for Preventing Short Description Changes on Closed


Incidents

Scenario: The IT Manager wants to prevent users from modifying the "Short description"
field on Incident records once they are in the "Closed" state. This is to maintain the integrity
of historical data.

Specific Questions:

1. What type of Business Rule (when) would you use to implement this restriction?
Explain your reasoning.
2. Write a sample script for this Business Rule that checks the Incident's state and
prevents changes to the "Short description" field if the state is "Closed".
3. How would you inform the user that they are not allowed to modify the field?

©️This Content Is Solely Prepared by SHAAH ABIIR, If You Want to Meet Me One-On-One, Please Book
an Appointment with Me Here: https://tinyurl.com/2brstwjq
©️SHAAH ABIIR

Detailed Solutions:

1. Solution: A "before update" Business Rule on the Incident table (incident) is the
most appropriate. We need to check the state before any updates are committed to the
database.
2. Solution (Sample Script):

(function executeRule(current, previous /*null when async*/) {

if (current.state.changesTo(7) || current.state.getValue() == 7)
{ // Assuming '7' is the value for 'Closed'
if (current.short_description.changes()) {

current.short_description.setValue(previous.short_description); //
Revert to the previous value
gs.addErrorMessage('You are not allowed to modify the
Short description of a closed Incident.');
current.setAbortAction(true); // Prevent the update
}
}

})(current, previous);

3. Solution: The gs.addErrorMessage() function is used to display a message to the


user at the top of the form, informing them that the modification is not allowed. The
current.setAbortAction(true) prevents the update to the record, ensuring the
"Short description" remains unchanged.

4. Client-Side Script for Mandatory Field on Catalog Item

Scenario: You have a catalog item for requesting a new mobile device. The business requires
that if the user selects "Yes" for the "Need Data Plan?" variable, a new variable called "Data
Plan Details" should become mandatory.

Specific Questions:

1. What type of client-side script would you use to implement this dynamic mandatory
behavior?
2. Describe the client script type and the event that would trigger this logic.
3. Write a sample client script that achieves this functionality, assuming the "Need Data
Plan?" variable name is need_data_plan (a true/false field) and the "Data Plan
Details" variable name is data_plan_details (a string field).

Detailed Solutions:

1. Solution: An onChange client script is the most suitable for this scenario. We need to
react immediately when the user changes their answer to the "Need Data Plan?"
question.

©️This Content Is Solely Prepared by SHAAH ABIIR, If You Want to Meet Me One-On-One, Please Book
an Appointment with Me Here: https://tinyurl.com/2brstwjq
©️SHAAH ABIIR

2. Solution:
o Client Script Type: onChange
o Triggering Event: When the value of the need_data_plan variable changes.
o Applied To: The specific catalog item.
o Field Name: need_data_plan
3. Solution (Sample Client Script):

function onChange(control, oldValue, newValue, isLoading,


isTemplate) {
if (isLoading || newValue === oldValue) {
return;
}

if (newValue == 'true') { // Or newValue == true, depending on


the variable type
g_form.setMandatory('data_plan_details', true);
} else {
g_form.setMandatory('data_plan_details', false);
// Optionally clear the value if it's no longer mandatory
g_form.setValue('data_plan_details', '');
}
}

5. Catalog Item Workflow for Manager Approval

Scenario: You have a catalog item for "Software Installation Request". This request needs to
be approved by the requesting user's manager before the software is provisioned.

Specific Questions:

1. Which ServiceNow feature would you use to implement this approval process for the
catalog item?
2. Describe the key activity you would use in the workflow to handle the manager's
approval.
3. How would you ensure the approval is routed to the correct manager of the person
who submitted the catalog item request?

Detailed Solutions:

1. Solution: A Workflow is the appropriate ServiceNow feature to manage this


approval process for a catalog item.
2. Solution: The key activity would be an "Approval - User" activity. This activity
allows you to specify one or more users who need to approve the workflow to
proceed.
3. Solution: Within the "Approval - User" activity, in the "Approvers" field, you would
use a script. This script would retrieve the manager of the user specified in the
"Requested For" field of the catalog item (which is typically linked to the sys_user
table). You can access the "Requested For" user's sys_id using

©️This Content Is Solely Prepared by SHAAH ABIIR, If You Want to Meet Me One-On-One, Please Book
an Appointment with Me Here: https://tinyurl.com/2brstwjq
©️SHAAH ABIIR

current.requested_for. Then, you would query the sys_user table to get this
user's record and return the manager field's value (which is the manager's sys_id).

// In the 'Approvers' field of the Approval - User activity (Script


tab)
(function() {
var requestedFor = current.getValue('requested_for'); // Get the
sys_id of the requested for user
var userRecord = new GlideRecord('sys_user');
if (userRecord.get(requestedFor)) {
return userRecord.getValue('manager'); // Return the sys_id
of the manager
}
return ''; // Return empty if no manager is found
})();

6. Catalog Item Workflow for Creating Multiple Tasks

Scenario: When a "New Employee Onboarding" catalog item is submitted and approved,
you need to automatically create two tasks: one for the IT department to create the user's
account and another for HR to handle the onboarding paperwork.

Specific Questions:

1. Within the catalog item workflow, what type of activity would you use to create these
tasks?
2. How would you ensure that these tasks are linked to the specific Request Item
(RITM) generated by the catalog item?
3. Describe how you would set different assignment groups and short descriptions for
each of these tasks within the workflow.

Detailed Solutions:

1. Solution: You would use the "Create Task" workflow activity twice, once for each
task you need to create.
2. Solution: When a catalog item is submitted, a Requested Item (RITM) record is
automatically created. The "Create Task" activity, by default, creates tasks that are
linked to this RITM through the request_item field on the task record (sc_task).
The workflow context inherently maintains this relationship.
3. Solution: Within each "Create Task" activity, you would configure the following
properties:
o Task Table: Set this to sc_task (Service Catalog Task).
o Short Description: Provide a specific description for each task (e.g., "Create
New User Account", "Process Onboarding Paperwork").
o Assignment Group: Select the appropriate group for each task (e.g., "IT -
User Administration", "Human Resources").
o You can also set other relevant fields like Priority, Description, Due Date, etc.,
within each "Create Task" activity as needed.

©️This Content Is Solely Prepared by SHAAH ABIIR, If You Want to Meet Me One-On-One, Please Book
an Appointment with Me Here: https://tinyurl.com/2brstwjq
©️SHAAH ABIIR

7. Integrating with an External Knowledge Base via REST API

Scenario: Your company wants to display relevant knowledge articles from an external
knowledge base within ServiceNow Incident forms. The external knowledge base has a
REST API that allows you to search articles based on keywords.

Specific Questions:

1. What ServiceNow feature would you use to interact with this external REST API?
2. Describe the steps involved in setting up this integration in ServiceNow to query the
external knowledge base.
3. Assuming the external API endpoint for searching articles is
https://api.external-kb.com/articles?query=<keyword> and it returns a
JSON response containing an array of article titles and links, how would you
construct the REST message and process the response in ServiceNow to display the
titles?

Detailed Solutions:

1. Solution: REST Message (under System Web Services > Outbound) is the primary
ServiceNow feature for making outbound REST API calls.
2. Solution: The steps involved would be:
o Create a REST Message: Navigate to System Web Services > Outbound >
REST Message and create a new record. Provide a name (e.g., "External KB
Integration") and the base URL (https://api.external-kb.com).
o Create a REST API Method: Within the REST Message, create a new HTTP
Method.
▪ Set the HTTP Method to "GET".
▪ Set the Endpoint to /articles.
▪ Define a Variable (e.g., keyword) in the HTTP Method's "Variables"
section to dynamically insert the search term. The endpoint would then
look like /articles?query=${keyword}.
▪ Configure any necessary HTTP Headers (e.g., Authorization if
required).
o Write a Script to Trigger the API Call and Process the Response: You
would likely use a Business Rule (e.g., when an Incident is opened or
updated) or a Client Script (to trigger on demand) to make the API call. This
script would:
▪ Create an instance of the REST Message API (using new
sn_ws.RESTMessageV2()).
▪ Set the HTTP method and endpoint (using the variable).
▪ Set the value for the keyword variable based on the Incident's short
description or other relevant fields.
▪ Send the request and handle the JSON response.

©️This Content Is Solely Prepared by SHAAH ABIIR, If You Want to Meet Me One-On-One, Please Book
an Appointment with Me Here: https://tinyurl.com/2brstwjq
©️SHAAH ABIIR

3. Solution (Sample Script within a Business Rule or Client Script):

// Example within a Business Rule (runs when an Incident is


displayed)
(function executeRule(current, previous /*null when async*/) {

var keyword = current.short_description.toString();


var restMessage = new sn_ws.RESTMessageV2('External KB
Integration', 'get_articles'); // Name of the REST Message and HTTP
Method
restMessage.setStringParameterNoEscape('keyword', keyword); //
Set the 'keyword' variable

var response = restMessage.execute();


var httpStatus = response.getStatusCode();
var responseBody = response.getBody();

if (httpStatus == 200) {
try {
var parsedResponse = JSON.parse(responseBody);
var articles = parsedResponse.articles; // Assuming the
JSON has an 'articles' array

if (articles && articles.length > 0) {


var articleTitles = 'Relevant External KB
Articles:\n';
for (var i = 0; i < articles.length; i++) {
articleTitles += '- ' + articles[i].title + ' ('
+ articles[i].link + ')\n';
}
gs.addInfoMessage(articleTitles); // Display the
titles as an info message
// In a real scenario, you might display this in a
more structured way on the form.
} else {
gs.addInfoMessage('No relevant external KB articles
found.');
}
} catch (e) {
gs.error('Error parsing external KB response: ' + e);
}
} else {
gs.error('Error retrieving external KB articles. Status
Code: ' + httpStatus + ', Response: ' + responseBody);
}

})(current, previous);

©️This Content Is Solely Prepared by SHAAH ABIIR, If You Want to Meet Me One-On-One, Please Book
an Appointment with Me Here: https://tinyurl.com/2brstwjq
©️SHAAH ABIIR

8. Debugging a Workflow Stuck on Approval

Scenario: A Change Request workflow is stuck at an "Approval - Group" activity. The


approvers in the group claim they haven't received any approval requests, and the workflow
context shows the activity is still "Waiting for Approval".

Specific Questions:

1. What are the first steps you would take in ServiceNow to begin troubleshooting why
the approval is not progressing?
2. What specific information would you look for in the Workflow Context and the
"Approval - Group" activity's details?
3. What are some common reasons why an "Approval - Group" activity might get stuck,
and how would you identify which one is the cause?

Detailed Solutions:

1. Solution: The first steps would be:


o Check the Workflow Context: Navigate to Workflow > Live Workflows >
All and find the specific workflow execution for the stuck Change Request.
Examine the current state of the workflow and the "Approval - Group"
activity.
o Verify Approval Records: Go to Approval > Approvals and search for
approvals related to the specific Change Request. Check the state of these
approval records (e.g., Requested, Approved, Rejected). Filter by the
assignment group involved in the workflow activity.
o Review Workflow Logs: Open the Workflow Editor for the Change Request
workflow and go to Tools > Workflow Log. Filter by the specific workflow
context to see the execution path and any relevant messages.
2. Solution: In the Workflow Context, you would look for:
o The current Activity the workflow is on (it should be the "Approval - Group"
activity).
o The State of the workflow (it should be "Running" or "Waiting").
o Any Error Messages or Warnings in the context details.
o The values of any Workflow Scratchpad variables that might be relevant to
the approval process.

In the "Approval - Group" activity's details (in the Workflow Editor), you would
examine:

o The Group specified for approval.


o Any Conditions set on the activity that might prevent it from triggering
approvals.
o The Approval Rule being used (if any).
o The Wait for condition (e.g., "Any one approves", "All approve").

3. Solution: Common reasons why an "Approval - Group" activity might get stuck and
how to identify them:

©️This Content Is Solely Prepared by SHAAH ABIIR, If You Want to Meet Me One-On-One, Please Book
an Appointment with Me Here: https://tinyurl.com/2brstwjq
©️SHAAH ABIIR

o No Approvers in the Group: Verify that the specified assignment group in


the "Approval - Group" activity actually has active members. Check the
sys_user_group_member table.
o No Users Meet Approval Conditions (if any): If the approval activity has
conditions on which users in the group should receive the approval, ensure
that at least one user in the group meets those conditions. Review the activity's
configuration.
o Email Notification Issues: Approvers might not be aware of the request if
email notifications are not working. Check the system logs for email errors
and verify the email configuration.
o Approval Rules Not Triggering: If an Approval Rule is being used, ensure
the rule is active and its conditions are being met for the Change Request.
Review the active Approval Rules related to the change_request table.
o Workflow Engine Issues: Although rare, there could be a temporary issue
with the ServiceNow workflow engine. Check the system status page for any
reported incidents.
o Scripting Errors in Approval Rule or Workflow: If there's custom scripting
involved in the approval process (either in the Approval Rule or within the
workflow), review the scripts for any errors that might be preventing the
creation or processing of approvals. Check system logs for script errors.
o "Wait for" Condition Not Met: Ensure you understand the "Wait for"
condition (e.g., "Any one approves" vs. "All approve"). If it's set to "All
approve" and only some members have approved, the workflow will remain
stuck. Check the related approval records to see who has approved and who
hasn't.

9. Optimizing a Business Rule with Multiple GlideRecord Queries

Scenario: You have a "before insert" Business Rule on the Incident table that retrieves
information from three different related tables based on the caller and sets some custom fields
on the new Incident record. Users report that creating new Incidents is slow.

Specific Questions:

1. What are some potential performance bottlenecks in this type of Business Rule?
2. Describe at least two strategies you could use to optimize the performance of this
Business Rule.
3. Provide a conceptual example of how you might reduce the number of GlideRecord
queries in this scenario.

Detailed Solutions:

1. Solution: Potential performance bottlenecks include:


o Multiple Synchronous GlideRecord Queries: Each GlideRecord() and
query() operation adds database overhead. Executing several of these
synchronously within a "before insert" rule directly impacts the time it takes to
save the Incident record.
o Unnecessary Data Retrieval: Selecting more fields than needed in the
GlideRecord queries can increase processing time.

©️This Content Is Solely Prepared by SHAAH ABIIR, If You Want to Meet Me One-On-One, Please Book
an Appointment with Me Here: https://tinyurl.com/2brstwjq
©️SHAAH ABIIR

o Inefficient Query Conditions: Queries that don't use indexed fields


effectively or use broad search criteria can lead to slow database lookups.
2. Solution (Optimization Strategies):
o Reduce the Number of GlideRecord Queries: Try to consolidate the data
retrieval into fewer queries. Explore if related information can be accessed
through dot-walking or by restructuring the logic.
o Optimize Query Conditions: Ensure you are using precise query conditions
on indexed fields. Avoid wildcard characters at the beginning of search terms.
o Use setDisplayValue() or getValue() Appropriately: If you only need to
display a value, use getDisplayValue(). If you need the actual stored value
for further processing, use getValue(). Avoid fetching entire records if only a
few fields are needed.
o Consider Asynchronous Processing (with caution): If the custom fields
don't need to be immediately available on the form upon saving, you might
consider moving some of the logic to an "after insert" Business Rule or an
asynchronous Business Rule. However, this needs careful consideration of
data consistency and user experience.
3. Solution (Conceptual Example):

Inefficient Approach (Hypothetical):

// Business Rule on Incident (before insert)


(function executeRule(current, previous /*null when async*/) {
// Get caller's department name
var caller = new GlideRecord('sys_user');
if (caller.get(current.caller_id)) {
var department = new GlideRecord('cmn_department');
if (department.get(caller.department)) {
current.u_caller_department = department.name;
}
}

// Get caller's location city


var location = new GlideRecord('cmn_location');
if (location.get(caller.location)) {
current.u_caller_city = location.city;
}

// Get caller's manager's email


var manager = new GlideRecord('sys_user');
if (manager.get(caller.manager)) {
current.u_manager_email = manager.email;
}
})(current, previous);

©️This Content Is Solely Prepared by SHAAH ABIIR, If You Want to Meet Me One-On-One, Please Book
an Appointment with Me Here: https://tinyurl.com/2brstwjq
©️SHAAH ABIIR

More Efficient Approach (Conceptual):

// Business Rule on Incident (before insert)


(function executeRule(current, previous /*null when async*/) {
// Get caller information in one query using dot-walking in the
getDisplayValue()
current.u_caller_department =
current.caller_id.department.getDisplayValue();
current.u_caller_city =
current.caller_id.location.city.getDisplayValue();
current.u_manager_email =
current.caller_id.manager.email.getDisplayValue();

// Alternatively, query the sys_user table once and access


related fields
var caller = new GlideRecord('sys_user');
if (caller.get(current.caller_id)) {
current.u_caller_department =
caller.department.getDisplayValue();
current.u_caller_city = caller.location.city; // Access
directly
current.u_manager_email = caller.manager.email; // Access
directly
}
})(current, previous);

Explanation: The more efficient approach reduces the number of GlideRecord


instantiations and query() calls by leveraging dot-walking to access related data
directly. In the second optimized example, we fetch the caller's record once and then
access the related department, location, and manager information directly from that
object, minimizing database interactions.

10. Understanding GlideRecord Query Conditions

Scenario: You need to write a script to find all active Problem records that were created in
the last 30 days and are assigned to the "Problem Management" group.

Specific Questions:

1. Write a GlideRecord query that retrieves these Problem records. Specify the table and
the conditions you would use.
2. Explain the purpose of the addQuery() and addEncodedQuery() methods in
GlideRecord. When might you use each?
3. How would you iterate through the results of this GlideRecord query and access the
"Number" and "Short description" fields of each Problem record?

Detailed Solutions:

©️This Content Is Solely Prepared by SHAAH ABIIR, If You Want to Meet Me One-On-One, Please Book
an Appointment with Me Here: https://tinyurl.com/2brstwjq
©️SHAAH ABIIR

1. Solution (GlideRecord Query):

var problemRecords = new GlideRecord('problem');


problemRecords.addQuery('active', true);
var thirtyDaysAgo = new GlideDateTime();
thirtyDaysAgo.addDays(-30);
problemRecords.addQuery('sys_created_on', '>=',
thirtyDaysAgo.getDisplayValue());
problemRecords.addQuery('assignment_group.name', 'Problem
Management');
problemRecords.query();

while (problemRecords.next()) {
// Process each Problem record
gs.log('Problem Number: ' + problemRecords.number + ', Short
Description: ' + problemRecords.short_description);
}

2. Solution:
o addQuery(field, operator, value): This method adds a simple condition
to the GlideRecord query. You specify the field name, the operator (e.g., '=',
'!=', '>', '<', 'IN', 'LIKE'), and the value to compare against. It's useful for
building queries step-by-step with individual conditions.
o addEncodedQuery(encodedQuery): This method allows you to add a
complex query string that is already formatted in the ServiceNow encoded
query syntax. You might get this encoded query from filtering a list view and
then right-clicking in the filter breadcrumbs to "Copy query". This is useful
for applying multiple complex conditions at once or reusing existing filter
logic.
3. Solution: You would use a while (problemRecords.next()) loop to iterate
through each Problem record that matches the query. Inside the loop,
problemRecords represents the current Problem record. You can access the fields
using dot notation (e.g., problemRecords.number to get the "Number" field and
problemRecords.short_description to get the "Short description" field).

©️This Content Is Solely Prepared by SHAAH ABIIR, If You Want to Meet Me One-On-One, Please Book
an Appointment with Me Here: https://tinyurl.com/2brstwjq

You might also like