0% found this document useful (0 votes)
12 views

Scenario Based Servicenow Developer Interview Questions

The document provides a comprehensive list of scenario-based interview questions and solutions for ServiceNow developers, covering various functionalities such as auto-populating fields, restricting updates, and validating data. Each scenario includes specific conditions, types, and code snippets to implement the desired behavior in ServiceNow. Additionally, it offers guidance on user onboarding automation, scheduled automation, and leveraging notifications to enhance incident management processes.

Uploaded by

sachin kambhapu
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)
12 views

Scenario Based Servicenow Developer Interview Questions

The document provides a comprehensive list of scenario-based interview questions and solutions for ServiceNow developers, covering various functionalities such as auto-populating fields, restricting updates, and validating data. Each scenario includes specific conditions, types, and code snippets to implement the desired behavior in ServiceNow. Additionally, it offers guidance on user onboarding automation, scheduled automation, and leveraging notifications to enhance incident management processes.

Uploaded by

sachin kambhapu
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/ 22

©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.

in

SCENARIO BASED SERVICENOW DEVELOPER INTERVIEW


QUESTIONS ALONG WITH SOLUTIONS ATTACHED

1. Auto-Populate Fields:
o Scenario: Set "Short Description" to "New Incident
Reported" on new incidents.
o Type: Before Insert
o Table: incident

1. (function executeRule(current, previous /*null when


async*/) {
if (!current.description) {
current.description = "New Incident Reported";
}
})(current, previous);
2.

2. Restrict Updates:
o Scenario: Prevent manual changes to the "Priority"
field.
o Type: Before Update
o Table: incident

1. if (current.priority != previous.priority) {
gs.addErrorMessage("Priority cannot be changed
manually.");
current.priority = previous.priority;
}
2.

©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in


©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in

3. Auto-Assign Tasks:
o Scenario: Assign new incidents to the "Application
Development" group if no group is set.
o Type: Before Insert
o Table: Incident

1. if (!current.assignment_group) {
var grp = new GlideRecord('sys_user_group');
grp.addQuery('name', 'Application Development');
grp.query();
if (grp.next()) {
current.assignment_group = grp.sys_id;
}
}
2.

4. Querying Other Tables:


o Scenario: Validate if an assigned user belongs to the
"Application Development" group.
o Type: Before Update
o Table: incident

1. var userGR = new GlideRecord('sys_user_grmember');


userGR.addQuery('user', current.assigned_to);
userGR.addQuery('group.name', 'Application Development');
userGR.query();
if (!userGR.next()) {
gs.addErrorMessage("User must be part of the IT Support
group!");
current.setAbortAction(true);
}
2.

©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in


©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in

5. Preventing Recursion:
o Scenario: Avoid infinite loops when a Business Rule
updates the same record (for non-admins).
o Type: Before Update
o Table: incident

1. if (!gs.hasRole('admin')) {
current.short_description = "Updated by Business Rule";
}
2.

6. Copying Attachments:
o Scenario: Copy attachments from an incident to a
newly created problem.
o Type: After Insert
o Table: problem

1. var sa = new GlideSysAttachment();


sa.copy("incident", current.sys_id, "problem",
newProblemSysId);
2.

7. Validating Data:
o Scenario: Ensure a valid phone number format before
inserting an incident.
o Type: Before Insert
o Table: incident

©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in


©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in

1. var phoneRegex = /^\+?\d{10,15}$/; // Matches


+1234567890 format
if (!phoneRegex.test(current.u_phone_number)) {
gs.addErrorMessage("Invalid phone number format. Use
+1234567890 format.");
current.setAbortAction(true);
}
2.
Book a One-on-One Call: Facing challenges with ServiceNow administration, scripting,
integrations, or real-world use cases? Book a one-on-one call for expert guidance on streamlining
administration, mastering scripting, seamless integrations, and solving scenario-based challenges.
Click here to schedule!

8. User Restrictions:
o Scenario: Prevent users from assigning incidents to
themselves.
o Type: Before Update
o Table: incident

1. if (current.assigned_to == gs.getUserID()) {
gs.addErrorMessage("You cannot assign incidents to
yourself.");
current.setAbortAction(true);
}
2.

o Scenario: Prevent users from updating their own roles.


o Type: Before Update
o Table: sys_user

©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in


©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in

1. if (current.sys_id == gs.getUserID()) {
gs.addErrorMessage("You cannot modify your own roles.");
current.setAbortAction(true);
}
2.
o Scenario: Prevent self-approval of change requests.

o Type: Before Update


o Table: change_request

1. if (current.approver == gs.getUserID()) {
gs.addErrorMessage("You cannot approve your own change
request.");
current.setAbortAction(true);
}
2.
o Scenario: Prevent ticket reassignment to the same
agent.
o Type: Before Update
o Table: incident

1. if (current.assigned_to == previous.assigned_to) {
gs.addErrorMessage("You cannot reassign the incident to
the same agent.");
current.setAbortAction(true);
}
2.
9. Relating Records:

o Scenario: Automatically populate the "Parent Incident"


field based on similar open incidents.
o Type: Before Insert
o Table: incident

©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in


©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in

1. var parentGR = new GlideRecord('incident');


parentGR.addQuery('short_description', 'CONTAINS',
current.short_description);
parentGR.addQuery('state', '!=', 7); // 7 = Closed
parentGR.orderByDesc('sys_created_on');
parentGR.query();
if (parentGR.next()) {
current.parent = parentGR.sys_id;
}
2.
10. Service Catalog Restrictions:

o Scenario: Restrict executable attachment types in


Service Catalog requests.
o Type: Before Insert
o Table: sc_request

1. var sa = new GlideSysAttachment();


var attachments = sa.getAttachments(current);
while (attachments.next()) {
var fileName = attachments.file_name.toLowerCase();
if (fileName.endsWith('.exe') || fileName.endsWith('.bat') ||
fileName.endsWith('.cmd')) {
gs.addErrorMessage("Executable files are not allowed.");
current.setAbortAction(true);
}
}
2.
11. Enforcing Data Integrity:

o Scenario: Enforce work notes on high-priority (P1/P2)


incidents before updating.
o Type: Before Update
o Table: incident

©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in


©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in

1. if ((current.priority == 1 || current.priority == 2) &&


!current.work_notes) {
gs.addErrorMessage("You must provide work notes for
high-priority incidents.");
current.setAbortAction(true);
}
o Scenario: Prevent closing an incident without a
resolution code.
o Type: Before Update
o Table: incident

1. if (current.state == 6 && !current.close_code) { // 6 =


Resolved
gs.addErrorMessage("You must provide a resolution code
before closing this incident.");
current.setAbortAction(true);
}
2.
12. Dynamic Priority Assignment:

o Scenario: Automatically update incident priority based


on impact and urgency.
o Type: Before Insert
o Table: incident

1. if (current.impact == 1 && current.urgency == 1) {


current.priority = 1; // Critical
} else if (current.impact <= 2 && current.urgency <= 2) {
current.priority = 2; // High
} else if (current.impact == 2 && current.urgency == 2) {
current.priority = 3; // Moderate
} else if (current.impact <= 3 && current.urgency == 3) {
current.priority = 4; // Low
} else {
current.priority = 5; // Planning
}
13. Preventing Deletion:
©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in
©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in

o Scenario: Prevent users from deleting high-priority


incidents.
o Type: Before Delete
o Table: incident

1. if (current.priority == 1) {
gs.addErrorMessage("High-priority incidents cannot be
deleted!");
current.setAbortAction(true);
}
2.
14. Creating Related Records:

o Scenario: Create a related problem record when an


incident is resolved.
o Type: After Update
o Table: incident

1. if (current.state == 6 && previous.state != 6) { // 6 =


Resolved
var problemGR = new GlideRecord('problem');
problemGR.initialize();
problemGR.short_description = "Problem related to
incident " + current.number;
problemGR.correlation_id = current.sys_id;
problemGR.insert();
}
2.
15. Knowledge Management Integration:

o Scenario: Automatically generate a Knowledge Article


from a resolved incident with a known solution.
o Type: After Update
o Table: incident

©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in


©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in

1. if (current.state == 6 && previous.state != 6) { // 6 =


Resolved
var kbGR = new GlideRecord('kb_knowledge');
kbGR.initialize();
kbGR.short_description = "Solution for Incident " +
current.number;
kbGR.text = current.close_notes;
kbGR.kb_category = "Incident Resolutions"; // Adjust as
needed
kbGR.workflow_state = "draft"; // Set to draft for review
kbGR.insert();
}

16. User Onboarding Automation:


o Scenario: Automatically add new employees to the
"New Hires" group.
o Type: After Insert
o Table: sys_user

1. var groupGR = new GlideRecord('sys_user_group');


groupGR.addQuery('name', 'New Hires');
groupGR.query();
if (groupGR.next()) {
var groupMember = new
GlideRecord('sys_user_grmember');
groupMember.initialize();
groupMember.user = current.sys_id;
groupMember.group = groupGR.sys_id;
groupMember.insert();
}
2.

Book a One-on-One Call: Facing challenges with ServiceNow administration, scripting,


integrations, or real-world use cases? Book a one-on-one call for expert guidance on streamlining
administration, mastering scripting, seamless integrations, and solving scenario-based challenges.
Click here to schedule!

©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in


©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in

17. Scheduled Automation:


o Scenario: Automatically close resolved incidents after 7
days.
o Type: Scheduled Script (Daily job)

1. var gr = new GlideRecord('incident');


gr.addQuery('state', 6); // 6 = Resolved
gr.addQuery('resolved_at', '<=', gs.daysAgo(7));
gr.query();
while (gr.next()) {
gr.state = 7; // 7 = Closed
gr.work_notes = "Incident automatically closed after 7 days
in resolved state.";
gr.update();
}
2.
o Scenario: Auto-close incidents with no updates for 14
days.
o Type: Scheduled Script (Daily)
Need Help? Join Our WhatsApp Community: Struggling with ServiceNow administration, scripting,
integrations, or real-world use cases? Don’t worry! Join our WhatsApp community for real-time
support, tips, and advice from experts and peers on the same journey. You’re not alone—we’re here
to help you succeed. Click here to join the community!

1. var gr = new GlideRecord('incident');


gr.addQuery('state', '!=', 7); // Not Closed
gr.addQuery('sys_updated_on', '<=', gs.daysAgo(14));
gr.query();
while (gr.next()) {
gr.state = 7; // Closed
gr.work_notes = "Incident auto-closed due to inactivity.";
gr.update();
}

©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in


©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in

o Scenario: Escalate incidents unassigned for 4 hours.


o Type: Scheduled Script (Every Hour)

1. var gr = new GlideRecord('incident');


gr.addQuery('state', '!=', 7); // Not Closed
gr.addQuery('assigned_to', 'NULL'); // Unassigned
gr.addQuery('sys_created_on', '<=', gs.hoursAgo(4));
gr.query();
while (gr.next()) {
gr.u_escalated = true;
gr.work_notes = "Incident escalated due to lack of
assignment.";
gr.update();
}
2.

2. Leveraging ServiceNow Notifications:


Keep stakeholders informed with automated email notifications:
• High-Priority Incident Alert:
o Scenario: Send an email to the support team when a P1
or P2 incident is created.
o Type: After Insert Business Rule
o Table: incident
o Notification Name: incident.high_priority

1. if (current.priority == 1 || current.priority == 2) {
var emailBody = "A high-priority incident (" +
current.number + ") has been created. \n\n" +
"Short Description: " + current.short_description;
gs.eventQueue("incident.high_priority", current,
"[email protected]", emailBody);
}
2.
©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in
©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in

• P1 Incident Assignment Notification:


o Scenario: Notify the manager when a P1 incident is
assigned.
o Type: After Update Business Rule
o Table: incident

1. if (current.priority == 1 && current.assigned_to &&


previous.assigned_to != current.assigned_to) {
var userGR = new GlideRecord('sys_user');
userGR.get(current.assigned_to);
if (userGR.manager) {
gs.eventQueue("incident.p1_assignment", current,
userGR.manager, current.assigned_to);
}
}
2.

Need Help? Join Our WhatsApp Community: Struggling with ServiceNow administration, scripting,
integrations, or real-world use cases? Don’t worry! Join our WhatsApp community for real-time
support, tips, and advice from experts and peers on the same journey. You’re not alone—we’re here
to help you succeed. Click here to join the community!

3. Mastering ServiceNow Client Scripts:


Enhance user experience and data validation directly on the form:

• Making Fields Read-Only:

1. function onLoad() {
g_form.setReadOnly('short_description', true);
}
2.

©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in


©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in

• Setting Default Values:

1. function onLoad() {
g_form.setValue('priority', '3');
}
2.
• Dynamic Mandatory Fields:

1. function onChange(control, oldValue, newValue, isLoading)


{
if (newValue === '1') {
g_form.setMandatory('impact', true);
} else {
g_form.setMandatory('impact', false);
}
}
2.
• Hiding Fields:

1. function onLoad() {
g_form.setDisplay('description', false);
}
2.

Need Help? Join Our WhatsApp Community: Struggling with ServiceNow administration, scripting,
integrations, or real-world use cases? Don’t worry! Join our WhatsApp community for real-time
support, tips, and advice from experts and peers on the same journey. You’re not alone—we’re here
to help you succeed. Click here to join the community!

©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in


©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in

• Preventing Form Submission:

1. function onSubmit() {
if (g_form.getValue('priority') == '1' &&
!g_form.getValue('description')) {
alert('Description is required for high priority incidents.');
return false;
}
return true;
}
2.
• Conditional Read-Only Fields:

1. function onLoad() {
if (g_form.getValue('priority') == '1') {
g_form.setReadOnly('description', true);
}
}
2.
Book a One-on-One Call: Facing challenges with ServiceNow administration, scripting,
integrations, or real-world use cases? Book a one-on-one call for expert guidance on streamlining
administration, mastering scripting, seamless integrations, and solving scenario-based challenges.
Click here to schedule!

• Displaying Alert Messages:

1. function onLoad() {
alert('This is a test alert!');
}
• Preventing Editing After Setting:

o Scenario: Once a value is entered in "Category," it


cannot be changed.

©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in


©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in

1. function onChange(control, oldValue, newValue, isLoading)


{
if (!isLoading && oldValue && oldValue !== newValue) {
g_form.setValue('category', oldValue);
g_form.addInfoMessage('Category cannot be changed
once set.');
}
}

• Auto-Populating Reference Fields:


o Scenario: When "Category" is "Hardware," auto-set
"Assignment Group" to "Hardware Support."

1. function onChange(control, oldValue, newValue, isLoading)


{
if (newValue == 'hardware') {
g_form.setValue('assignment_group',
'287ebd7da9fe198100f92cc8d1d2154e'); // Replace with actual
sys_id
}
}

• Custom Form Validation:


o Scenario: Prevent submission if "Short Description"
contains "test."

1. function onSubmit() {
var shortDesc = g_form.getValue('short_description');
if (shortDesc.toLowerCase().includes('test')) {
g_form.addErrorMessage('Short Description cannot
contain "test".');
return false;
}
return true;
}

©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in


©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in

• Date Manipulation:
o Scenario: Set "Due Date" to 5 days after the "Opened"
date.
o Type: onChange
o Field: opened
o Table: incident

1. function onChange(control, oldValue, newValue, isLoading,


isTemplate) {
if (isLoading || newValue === '') {
return;
}
var daysadded = "5" var opened = new
Date(g_form.getValue('opened_at'));//gets the value of opened
datetime
var duedate = "";
var openedate = opened.getDate();//get the day
var totaldays = parseInt(openedate) + parseInt(daysadded);
//(example:-today date = 13th, adding 5 days to it = 18th)
opened.setDate(totaldays);
duedate = formatDate(opened, g_user_date_time_format);
g_form.setValue('due_date', duedate);
}
2.
o Scenario: Prevent selecting past dates for the "Opened"
field.
o Type: onSubmit
o Table: incident

©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in


©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in

1. function onSubmit() {
var presentdate = new Date();
var startdate = new Date(g_form.getValue('opened_at'));
startdate.getDate();
if (presentdate.valueOf() > startdate.valueOf()) {
g_form.clearValue('opened_at');
alert('you cannot choose past date');
return false;
}
}

o Scenario: Ensure "End Date" is after "Start Date."


o Type: onSubmit
o Table: incident

1. function onSubmit() {
var duedate = new Date(g_form.getValue('due_date'));
var startdate = new Date(g_form.getValue('opened_at'));
startdate.getDate();
if (duedate.valueOf() > startdate.valueOf()) {
g_form.addInfoMessage("true");
} else {
alert("End Date should be after Start Date.");
g_form.clearValue('due_date');
return false;
}
}

o Scenario: Restrict "End Date" selection to within the


next 10 days.
o Type: onSubmit
o Table: incident

©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in


©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in

1. function onSubmit() {
var enddate = new Date(g_form.getValue('due_date'));
var todayJSdate = new Date();
var day = new Date(enddate);
var timediff = day.getTime() - todayJSdate.getTime();
var datediff = timediff / (24 * 60 * 60 * 1000);
if (datediff > 10) {
alert("please select 10 days from today");
g_form.setValue('due_date', '');
return false;
}
}

o Scenario: Restrict "Opened" date selection to the


current date.
o Type: onSubmit
o Table: incident

1. function onSubmit() {
var sdate=new Date(g_form.getValue('opened_at'));
var edate=new Date(sdate);
var odate=new Date();
if(odate<edate||odate>edate){
g_form.addErrorMessage('please select current date');
g_form.clearValue('opened_at');
}else{
g_form.setValue('opened_at',odate.valueOf());
}
}

Need Help? Join Our WhatsApp Community: Struggling with ServiceNow administration, scripting,
integrations, or real-world use cases? Don’t worry! Join our WhatsApp community for real-time
support, tips, and advice from experts and peers on the same journey. You’re not alone—we’re here
to help you succeed. Click here to join the community!

©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in


©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in

4. Unleashing the Power of GlideRecord Queries:


Retrieve and manipulate data efficiently with these examples:
• Getting Current User's Roles:

1. var gr=new GlideRecord('sys_user_has_role');


gr.addQuery('user',gs.getUserID());//depends on current
loggedIn user
gr.query();
while(gr.next()){
gs.info(gr.role.name);
}gs.info("No.of roles that user is having:-
"+gr.getRowCount());
// (or)
var gr=new GlideRecord('sys_user_has_role');
gs.info(gs.getUser().getRoles());
2.

Book a One-on-One Call: Facing challenges with ServiceNow administration, scripting,


integrations, or real-world use cases? Book a one-on-one call for expert guidance on streamlining
administration, mastering scripting, seamless integrations, and solving scenario-based challenges.
Click here to schedule!

• Getting Users with a Specific Role (e.g., 'admin'):

1. var gr=new GlideRecord('sys_user_role');


gr.addQuery('name=admin');
gr.query();
if(gr.next()){
var user =new GlideRecord('sys_user_has_role');
user.addQuery('role.name',gr.name);
user.query();
while(user.next()){
gs.info(user.user.name);
}gs.info("No.of users with a particular role:-
"+user.getRowCount());
}
2.

©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in


©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in

• Getting Current User's Groups:

1. var user=new GlideRecord('sys_user_grmember');


user.addQuery('user',gs.getUserID());//depends on current
loggedIn user
user.query();
while(user.next()){
gs.info(user.group.name);
}gs.info("No.of groups that user is having:-
"+user.getRowCount());
2.

Book a One-on-One Call: Facing challenges with ServiceNow administration, scripting,


integrations, or real-world use cases? Book a one-on-one call for expert guidance on streamlining
administration, mastering scripting, seamless integrations, and solving scenario-based challenges.
Click here to schedule!

• Getting Users in a Specific Group (e.g., 'application


development'):

1. var grp=new GlideRecord('sys_user_group');


grp.addQuery('name=application development');
grp.query();
if(grp.next()){
var grpmem=new GlideRecord('sys_user_grmember');
grpmem.addQuery('group.name',grp.name);
grpmem.query();
while(grpmem.next()){
gs.info(grpmem.user.name);
}gs.info("No.of users with a particular group:-
"+grpmem.getRowCount());
}
2.

Need Help? Join Our WhatsApp Community: Struggling with ServiceNow administration, scripting,
integrations, or real-world use cases? Don’t worry! Join our WhatsApp community for real-time
support, tips, and advice from experts and peers on the same journey. You’re not alone—we’re here
to help you succeed. Click here to join the community!

©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in


©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in

• Getting Directly Assigned Roles of Current User:

1. gs.info(gs.getUser().getUserRoles());// these roles directly


assigned to the user,excluding inherited or group-based roles.
2.
• Getting Current User's Display Name:

1. gs.info(gs.getUser().getDisplayName());

• Getting Last 10 Resolved Incidents:

1. var inc=new GlideRecord('incident');


inc.addQuery('state=6');
inc.orderByDesc('sys_updated_on');
inc.setLimit(10);
inc.query();
while(inc.next()){
gs.info(inc.number+":- "+inc.caller_id.getDisplayValue());
}
• Getting P1/P2 Active Incidents with Category
'inquiry':

1. var inc=new GlideRecord('incident');


inc.addQuery('priorityIN1,2^category=inquiry');
inc.addActiveQuery();
inc.query();
while(inc.next()){
gs.info(inc.number+":- "+inc.priority.getDisplayValue()+":-
"+inc.category);
}gs.info(inc.getRowCount());

©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in


©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in

• Getting Current Logged-In User's Incidents:

var inc=new GlideRecord('incident');


inc.addQuery('caller_idDYNAMIC90d1921e5f510100a9ad2572f
2b477fe');//current LoggedIn user
inc.addActiveQuery();
inc.query();
while(inc.next()){
gs.info(inc.number+":-"+inc.short_description);
}gs.info(inc.getRowCount());

Need Help? Join Our WhatsApp Community: Struggling with ServiceNow administration, scripting,
integrations, or real-world use cases? Don’t worry! Join our WhatsApp community for real-time
support, tips, and advice from experts and peers on the same journey. You’re not alone—we’re here
to help you succeed. Click here to join the community!

• Getting All Active Incidents (Excluding Closed &


Cancelled):

1. var inc=new GlideRecord('incident');


inc.addQuery('stateNOT IN7,8');
inc.addActiveQuery();
inc.query();
while(inc.next()){
gs.info(inc.number+":-"+inc.state.getDisplayValue());
}gs.info(inc.getRowCount());
2.

©️HackNow Call/WhatsApp: +91 8984988593 Visit Us: https://hacknow.co.in

You might also like