Job Switch Kit: Everything you need to crack your next ServiceNow interview Get Job Switch Kit →
Get the complete ServiceNow interview prep system — 500+ Q&A, mock interviews & more Get Job Switch Kit →

ServiceNow Scripting Scenario Based Interview Questions 2026

Tip : For scripting related scenario based questions, usually interviewer asks you to login and share your PDI where you will have to write script. This way interviewer tries to understand your scripting skills.

Make sure you follow ServiceNow best practices while writing script.
e.g.
Do not use 'gr' variable name.
Give meaningful names to variables you declare.
Do not use multiple addQuery for single gliderecord instead try single 'addEncodedQuery'.

New: practise these scripts right here

Each scenario below has a Practice this in the sandbox button. Write your script, run it against realistic practice data and get it checked the way an interviewer would review it. No PDI needed. Nothing you run touches a real instance, and the data resets on every run.

Write a script to show incident count for each state which are updated today?

We can use GlideAggregate API to achieve this scenario:

Script :

gs.print('State\\tIncident Count');
var grIncident=new GlideAggregate('incident');
grIncident.addEncodedQuery(' sys_updated_onONToday@javascript: gs.beginningOfToday()@javascript: gs.endOfToday()');
grIncident.addAggregate('COUNT','state');
grIncident.query();
while(grIncident.next()){
gs.print(grIncident.state. getDisplayValue()+'\t'+grIncident. getAggregate('COUNT','state'));
}

Output :


Note: This scripting question is common. However, they might ask for different table or different field. The primary learning here is whenever there is question related to finding count of the records, we are supposed to use GlideAggregate API. Do not use GlideRecord API with getRowCount method, it is not considered as best practice. Also make sure you understand how addAggregate, getAggregate and groupBy works in GlideAggregate API.

Write a script to print last 5 incidents created yesterday?

Script :


Output :


Note: Many of you must already be knowing how GlideRecord works but here interviewer checks if you know how setLimit, orderBy or orderByDesc can be used for such scenarios.

Write a script to print number of incidents Category and Sub Category wise?

We need to use GlideAggregate as we need to get count of incidents. Since, we need incidents Category and sub cateory wise, we need to apply grouping on 2 fields as shown below :

Script :


Output :


Note: Take away from this scenario is to understand how grouping on multiple fields can be used. Interviewer might change question to include 3-4 grouping fields so you should understand how grouping on multiple fields can be done via GlideAggregate API. Such multiple grouping logic is also quite useful if you want to do analysis on existing data.

Write a script as per below requirement :

1. You have to create one script inlcude with two function getIncidentDetails and sendDataToBackgroundScript.

2. getIncidentDetails should fetch first incident resolved today, this function should send Incident number, assignee user, resolved date and created date to sendDatToBackgroundScript function which is in the same script include.

3. sendDataToBackgroundScript function should calculate duration between created date and resolved date and return difference and Incident Number, Assignee User.

4. sendDataToBackgroundScript shoudl be called from background script and all data should be printed.

Background Script :


Script Include :


Output :


Note: Here interviewer tries to test your basic scripting knowledge, like calling script include from another script, sending multiple values from one function to another, finding date difference, basic usage of GlideRecord with setLimit and orderBy method. Interviewer might change scenarios to introduce more ServiceNow API's so prepare yourself with these all basic scripting knowledge.

Allow user to generate "Security Incident" via normal Incident record but we have to make sure that logged in user has access to "Security Incident" Table?

There are two methods to verify users access for any glide record.

1. Use GlideRecordSecure API while creating security incident. This API implicitly verifies if user passes ACL access on table.
2. Use canRead or canWrite function. These functions implicitly verifies if logged in user satisfies ACL access.

Write a script to print the number of open (active) incidents for every active assignment group, including groups that have no open incidents.

Counting means GlideAggregate, but there is a catch: GlideAggregate only returns groups that actually have incidents. To also show groups with 0, query the active groups separately and look up each count, defaulting to 0. That keeps it to two queries however many groups exist.

Script :

// 1. Count active incidents per group in ONE aggregate query
var counts = {};
var incAgg = new GlideAggregate('incident');
incAgg.addActiveQuery();
incAgg.addNotNullQuery('assignment_group');
incAgg.addAggregate('COUNT');
incAgg.groupBy('assignment_group');
incAgg.query();
while (incAgg.next()) {
    counts[incAgg.getValue('assignment_group')] = parseInt(incAgg.getAggregate('COUNT'), 10);
}

// 2. Walk every active group and print its count (0 when missing)
var groupGr = new GlideRecord('sys_user_group');
groupGr.addActiveQuery();
groupGr.orderBy('name');
groupGr.query();
while (groupGr.next()) {
    gs.info(groupGr.getValue('name') + ': ' + (counts[groupGr.getUniqueValue()] || 0));
}

Note: Interviewers use the "include zero" twist to see whether you understand what GlideAggregate returns. Looping over groups and calling getRowCount() for each one gives the same output but runs one query per group, which is the answer they are hoping you will not give.

Some employees have left the company, but open incidents are still assigned to them. Write a script to clear Assigned to on those incidents so the team picks them up, and print how many were unassigned.

Dot-walk to the assignee's user record inside the incident query: assigned_to.active=false. One query finds every affected incident; there is no need to loop over users first.

Script :

var count = 0;
var incidentGr = new GlideRecord('incident');
incidentGr.addEncodedQuery('active=true^assigned_to.active=false');
incidentGr.query();
while (incidentGr.next()) {
    incidentGr.setValue('assigned_to', '');
    incidentGr.update();
    count++;
}
gs.info('Unassigned ' + count + ' incident(s)');

Note: This is a common real-world clean-up. Keep the assignment group so the ticket goes back to the team's queue, and say why you let Business Rules run (no setWorkflow(false)) - the reassignment is a genuine change people should see.

Write a script to create a P1 incident for the caller "Anita Desai", assigned to the "Database" group, with short description "Production database is down", and print the new incident number.

Reference fields store sys_ids, so look the caller and the group up by name first, check that both were found, then initialize(), set the values and insert(). On a real instance, priority is calculated from impact and urgency, so set those two.

Script :

var callerGr = new GlideRecord('sys_user');
var groupGr = new GlideRecord('sys_user_group');
if (!callerGr.get('name', 'Anita Desai') || !groupGr.get('name', 'Database')) {
    gs.error('Caller or group not found');
} else {
    var incidentGr = new GlideRecord('incident');
    incidentGr.initialize();
    incidentGr.setValue('caller_id', callerGr.getUniqueValue());
    incidentGr.setValue('assignment_group', groupGr.getUniqueValue());
    incidentGr.setValue('short_description', 'Production database is down');
    incidentGr.setValue('category', 'database');
    incidentGr.setValue('impact', 1);
    incidentGr.setValue('urgency', 1);
    incidentGr.insert();
    gs.info('Created ' + incidentGr.getValue('number'));
}

Note: Never hard-code sys_ids in an interview answer - they are different on every instance. Setting caller_id to the text "Anita Desai" is another classic mistake: it stores a broken reference instead of the user.

Write a script to print all active incidents that are Priority 1 or 2 and assigned to either the Network or the Database group, using a single encoded query.

^OR binds to the condition right before it, so (P1 OR P2) AND (Network OR Database) is written as below. An IN list is a shorter alternative: active=true^priorityIN1,2^assignment_group.nameINNetwork,Database.

Script :

var incidentGr = new GlideRecord('incident');
incidentGr.addEncodedQuery('active=true^priority=1^ORpriority=2^assignment_group.name=Network^ORassignment_group.name=Database');
incidentGr.query();
while (incidentGr.next()) {
    gs.info(incidentGr.getValue('number') + ' | ' + incidentGr.priority.getDisplayValue() + ' | ' + incidentGr.assignment_group.getDisplayValue());
}

Note: The trap is ^NQ: it does not mean "or" between two conditions, it starts a completely separate query. With ^NQ in the middle, every Database incident matches regardless of priority. Build the filter in a list view and use Copy query if you are unsure.

An audit found deactivated groups that still have members. Write a script to print every user who is a member of an inactive group.

Query the membership table sys_user_grmember and dot-walk to the group's active flag. One query answers the question.

Script :

var memberGr = new GlideRecord('sys_user_grmember');
memberGr.addQuery('group.active', false);
memberGr.query();
while (memberGr.next()) {
    gs.info(memberGr.user.getDisplayValue() + ' -> ' + memberGr.group.getDisplayValue());
}

Note: Knowing that sys_user_grmember is the many-to-many table between users and groups is the real test here. In an actual clean-up you would also remove these memberships, because users keep the roles inherited from the group.

Interviewers forget your perfect answer in 5 minutes. They remember how confidently you delivered it.

Confidence comes from repetition, not luck. The Job Switch Kit is where you build it.

500+ Q&A — Technical + Behavioral, structured by module
15-Day Structured Roadmap — Day-by-day plan that peaks on interview day
Unlimited Interview Bot — Practice live, every session recorded and reviewable
Salary Negotiation Playbook — Counter-offers, CTC decoding, in-hand strategy
Job Switch Strategy Guide — Notice period, BGV, resignation, offer comparison
Progress Tracker + Notes — Always know exactly what to tackle next
LinkedIn Profile Optimisation — Get found by recruiters before you even apply
Build That Confidence →

🔒 Secure payment via Razorpay · Instant access after payment

10 days free — for your honest review

Your story could be the reason someone else lands their next ServiceNow role

If this content made a real difference in your prep, sharing that experience with your network helps other professionals discover it — and we'd love to say thank you with 10 days of premium access, completely on us.

Real Interview Questions & Answers

Questions shared by ServiceNow professionals and reviewed for clarity, relevance, and interview usefulness.

Apurva 15 Oct 2025
Given an array, find the duplicates of in the array and return an object with duplicate number and its index input = [1,2,3,1] output = { 1 : [1,4]}
Keerthi Kiran M 13 Nov 2025
var arr= [1,2,3,1]; var duplicate = {}; for(var i=0; i< arr.length; i ){ if(duplicate[arr[i]]){ duplicate[arr[i]].push(i); }else{ duplicate[arr[i]]=[i]; } } var result = {}; for(var key in duplicate){ if(duplicate[key].length > 1){ result[key] = duplicate[key]; }} console.log(result); //output: { '1': [ 0, 3 ] }
0 helpful
0 helpful
*Please enter a reply
Apurva 15 Oct 2025
Using a ServiceNow code, find your age.
Sowmya 08 Feb 2026
(function () { var dob = '1996-09-20'; var dobGDT = new GlideDateTime(dob); var today = new GlideDateTime(); var age = GlideDateTime.subtract(today,dobGDT).getYears(); gs.info("your age is:" age); })();
0 helpful
0 helpful
*Please enter a reply
Apurva 15 Oct 2025
Create a table with 2 fields - Employee Name and Salary. Add 3-5 entries. Employee Name Salary Raj 2000 Keshav 3000 Seema 5000 Jason 6000 Using a ServiceNow code, Display the name of the employee with second highest salary
Durga Prasad 24 Mar 2026
var employeeList = [ { name: 'Raj', salary: 2000 }, { name: 'Keshav', salary: 3000 }, { name: 'Seema', salary: 5000 }, { name: 'Jason', salary: 6000 } ]; // Sort descending by salary employeeList.sort(function(empA, empB) { return empB.salary - empA.salary; }); // Get second highest var secondHighestEmployee = employeeList[1]; gs.print('Second highest salary employee: ' secondHighestEmployee.name);
0 helpful
0 helpful
*Please enter a reply
Ani 23 Aug 2025
I want to create change task a b c d e and short description a1 b1 c1 d1 e1 When ever change moves to implement state How cam we achieve this scenario
0 helpful
*Please enter a reply
Akshay 10 Jul 2025
If Assigned To user is not active, then assign the incident to the Assigned To's manager" in ServiceNow ITSM
Surya 06 Apr 2026
what is manager is not part of the assignment group
0 helpful
0 helpful
*Please enter a reply
Jasprit 24 Dec 2024
What is the difference between the newRecord and initialize method of GlideRecord?
Swappy 07 Feb 2025
What is servicenow gliderecord initialize ? Creates an empty record within the current GlideRecord that is suitable for population before an insert. What is servicenow gliderecord newRecord? Creates a GlideRecord, sets the default values for the fields, and assigns a unique ID to the record.
0 helpful
0 helpful
*Please enter a reply
Zorro 29 Sep 2024
Suppose there are multiple duplicates for multiple records in a incident table now I want to know all the records which have duplicates, how can I be able to achieve it?
Manoj D 02 Nov 2024
var incidentGr = new GlideAggregate('incident'); incidentGr.addAggregate('COUNT', 'number'); incidentGr.groupBy('number'); incidentGr.query(); while (incidentGr.next()) { var count = incidentGr.getAggregate('COUNT', 'number'); if (count > 1) { gs.info('Duplicate Record: ' incidentGr.number ' Count: ' count); } }
0 helpful
Srinidhi 28 Aug 2025
gs.print(getDuplicates('incident','number')); // Assuming you have duplicate Incident Numbers function getDuplicates(tablename,val) { var dupRecords = []; var gaDupCheck = new GlideAggregate(tablename); gaDupCheck.addQuery('active','true'); gaDupCheck.addAggregate('COUNT',val); gaDupCheck.addNotNullQuery(val); gaDupCheck.groupBy(val); gaDupCheck.addHaving('COUNT', '>', 1); gaDupCheck.query(); while (gaDupCheck.next()) { dupRecords.push(gaDupCheck[val].toString()); } return dupRecords; }
0 helpful
0 helpful
*Please enter a reply
Pragya 15 Jun 2024
Print user's manager's manager name and email address using client script and script include.
0 helpful
*Please enter a reply
Chandu 22 May 2024
How to pass values between two functions in Script Include
Abhinandan 09 Jun 2024
You can use function arguments to send in data from one function to other.
2 helpful
Sharique 07 Sep 2026
I guess you mean, in a script include there are two functions and you want to access variables defined in one function into another. You can make use of the 'this' leywpord for accessing the value.
0 helpful
0 helpful
*Please enter a reply
Ghouse Sharief 30 Mar 2024
Populate an alert or info message on incident form when assignment group changes on the incident . on the alert display the assignment group members
Sumit 04 Oct 2024
we have to use onchange client script for displaying alert , and for fetching assignment group members we hvae to write script include which will return the list of all members in that group
0 helpful
N Cinthala 07 Aug 2025
script include: var namearr=[]; var y=this.getParameter('sysparm_value'); var x=new GlideRecord('sys_user_grmember'); x.addQuery('group',y); x.query(); while(x._next()){ namearr.push(x.user.name ''); } return namearr ''; client script: var z=new GlideAjax('test123'); z.addParam('sysparm_name','demo'); z.addParam('sysparm_value',newValue); z.getXMLAnswer(hello); function hello(response){ alert(response ''); }
1 helpful
0 helpful
*Please enter a reply
Sk 30 Mar 2024
Hi, I was asked this scenario : If Assignment group and state is changed to particular choice Short description should become Mandatory and Description should become read only
Dhruv 27 Apr 2024
You can use UI Policy UI Policy condition - Assignment Group is [Service Desk] AND state is [New] UI Policy Action: Make short description field Mandatory Description filed Read Only
1 helpful
0 helpful
*Please enter a reply
Chandu 19 Mar 2024
Difference between addQuery and addEncodedQuery methods
Nikhil Kamlekar 01 Apr 2024
addQuery or addEncodedQuery methods we usually use in querying the records. Ex: If you have one query needs to be run, you can use addQuery('category','software); If you have multiple queries then for each time you have to use addQuery instead of multiple queries you can use addEncodedQuery addEncodedQuery('paste the query here')
0 helpful
0 helpful
*Please enter a reply
Sneha 08 Mar 2024
If I create ITIL user it will automatically added in manager group how can I do this?
Ajay 08 Oct 2024
There is a table called "sys_user_has_role" , write a Before BR on this table on insert, with the condition as role is ITIL and in the code you can include as below var user_sys_id=current.user; // this will fetch the user with that got assigned the itil role var gr=new gliderecord('sys_user_gr_member'); gr.initialize(); gr.group="Manager group sysid"; gr.user=user_sysid; gr.insert();
0 helpful
0 helpful
*Please enter a reply
Cookie 06 Mar 2024
If an incident is in resolved state for 5 days, Close it
Anjali Singh 25 Mar 2024
1. Navigate to System Properties > System. 2. Locate the property Number of days (integer) after which Resolved incidents are automatically closed. 3. Set the Value to be the number of days to wait before closing a resolved incident.
0 helpful
Sharique 07 Sep 2026
Anjali answer is right. You can also create a scheduled job which will run daily and updates the records. Below is the code for the same var gr = new GlideRecord("incident"); gr.addQuery('state','6'); gr.addQuery('sys_updated_on','>',gs.daysAgo(5)); gr.query(); var total = gr.getRowCount(); gs.log('total row : ' +total); while(gr.next()){ gr.state = 7; gs.log("Incident has closed"); gr.update(); }
0 helpful
0 helpful
*Please enter a reply
Cookie 06 Mar 2024
Print system date and date a year ago
Pradeep 15 Apr 2024
var gdt = new GlideDateTime(); gdt.addYears(-1); gs.print(gdt.getDate());
0 helpful
0 helpful
*Please enter a reply
Cookie 06 Mar 2024
Insert 10 incidents from Incident table in an array
Heisenberg 24 Dec 2024
var incident_list=[]; var incidentGr=new GlideRecord('incident'); incidentGr.addEncodedQuery('active=true'); //Replace query based on the input incidenGr.setLimit(10); incidentGr.query(); while(incidentGr.nect()){ var obj={}; //Empty object //Push attributes according to your choice. For now I am pushing only number and short description obj.number=incidentGr.getValue('number'); obj.short_description=incidentGr.getValue('short_description'); incident_list.push(obj); } //Print List for(var i=0;i
0 helpful
Divesh Jalandriya 22 May 2025
var arrayList = []; var grIncident = new GlideRecord('incident'); grIncident.setLimit(10); grIncident.query(); while (grIncident.next()) { var obj = {}; obj.number = grIncident.number.getDisplayValue(); obj.short_description = grIncident.short_description; arrayList.push(obj.number '->' obj.short_description); } for(var i=0;i
0 helpful
0 helpful
*Please enter a reply
Cookie 06 Mar 2024
Read Caller's name from the Caller field in incident table, and check for 1st letter, if it is a, print "apple", if it is b, print "bat"
Pradeep 21 Apr 2024
var caller = current.caller_id.getDisplayValue(); var text = caller.toUpperCase(); if (text.startsWith('A')) gs.print('Apple'); else gs.print('Bat');
0 helpful
0 helpful
*Please enter a reply
Naveen 01 Mar 2024
2.When the Caller field is changed, retrieve the caller's location and update the Location field accordingly.
Ajay 08 Oct 2024
you can achieve this with a on change client script and script include
0 helpful
0 helpful
*Please enter a reply
Sujatha 28 Feb 2024
when ever the problem work note updated,update the comment in attached incident work notes also
Nithin 03 Jul 2025
script in problem table >> var inc = new GlideRecord('incident'); inc.addQuery('problem_id', current.sys_id); inc.query(); while (inc.next()) { inc.work_notes = current.work_notes; inc.update(); }
0 helpful
0 helpful
*Please enter a reply
Ann 25 Oct 2023
when I submit a new request on behalf of "xyz" when xyz opens that form should be editable for "xyz" and other forms should be read only to xyz how can I achieve this.
Abdul 16 Nov 2023
created_by field will store your name and requested_by field will store 'XYZ'. NOw you can USE ACL or combination of Display BR and Client script
1 helpful
Pratiksha 24 Nov 2023
suppose you create incident on behalf of xyz the you can achieve above requirement in two ways. 1.create write ACL (in script check if logged in user is caller) 2. create display BR and onLoad client script
0 helpful
Isha 28 Nov 2023
ACL
0 helpful
Astik Thombare 04 Dec 2023
Hi @Ann, You can create a new ACL on the incident table with the operation "write" and name it "Incident." Set the conditions to "None" and give the condition that the caller is dynamic. This way, you can achieve the above requirement. Thanks! Astik
2 helpful
Satyam Jain 02 Mar 2024
Create write ACL on the table.none and write the script in advance answer=false; var gr=gs.getUserID(); if(current.caller_id==gr){ answer=true; }
0 helpful
0 helpful
*Please enter a reply
Ann 25 Oct 2023
when user clicks on new form incident form will open, when user opens a new option that time in the state "cancel" option should be hidden. Once he submits a form "cancel" option should be visible. how to achieve this
Snowexpertaastik 05 Sep 2025
if(g_form.isNewRecord()){ g_form.removeOption('state','8'); }
0 helpful
0 helpful
*Please enter a reply
Ann 25 Oct 2023
on the catalog form below the submit button i want to add reset button which will reset all the values. How to achieve this
0 helpful
*Please enter a reply
Harish Gadi 07 Sep 2023
How to create a problem record for 5 th incident in incident list Example: there are 10 incidents we need to create a problem ticket for incident for 5 th incident only ?
Surendra 24 Oct 2023
var gr = new GlideRecord('incident'); gr.orderByDesc('sys_created_on'); //gr.setLimit(10); gr.chooseWindow(4,5);// 4-first row and 5- last row gr.query(); while(gr.next()){ gs.print(gr.number); // create problem record here }
0 helpful
0 helpful
*Please enter a reply
Satyapriya Biswal 05 Aug 2023
I was asked that write a background script that will show how many roles the current logged in user have. Can anyone help me to answer this question.
Aastha 06 Aug 2023
var gr = new GlideRecord('sys_user_has_role'); gr.addQuery('user','6816f79cc0a8016401c5a33be04be441') gr.query(); gs.print(gr.getRowCount()); while(gr.next()) { //one way to do it }
0 helpful
Ps 07 Aug 2023
var userid = gs.getUserID(); var gr = new GlideRecord('sys_user_has_role'); gr.addQuery('user.sys_id', userid); gr.query(); while(gr.next()){ gs.print(gr.role.getDisplayValue()); gs.print(gr.getRowCount()); }
0 helpful
Ria 23 Aug 2023
Whenever we have to find out count of something then it is recommended to use GlideAggregate API, using GlideRecord API with getRowCount method is not efficient and it is not considered as best practice. Therefore you can rather use below code. var userid = gs.getUserID(); var gaRoleCount=new GlideAggregate("sys_user_has_role"); gaRoleCount.addQuery("user",userid); gaRoleCount.addAggregate("COUNT","role"); gaRoleCount.query(); if(gaRoleCount.next()){ gs.print("Role Count for logged in user:" gaRoleCount.getAggregate("COUNT","role"); }
1 helpful
Satyapriya Biswal 25 Aug 2023
Thanks
0 helpful
Praveen K 20 Sep 2023
Hi Ria, In 4th line you are grouping the count by role which is incorrect it should be only gaRoleCount.addAggregate("COUNT"); Check below code for more info var userid = gs.getUserID(); var gaRoleCount=new GlideAggregate("sys_user_has_role"); gaRoleCount.addQuery("user",userid); gaRoleCount.addAggregate("COUNT"); gaRoleCount.query(); if(gaRoleCount.next()){ //gs.print(gs.getUserName()) //gs.print(userid) gs.print("Role Count for logged in user:" gaRoleCount.getAggregate("COUNT")); }
1 helpful
Bharath 12 Jul 2024
gs.print("Role Count for logged in user:" gaRoleCount.getAggregate("COUNT")) in this line was error in background script, Please once check it Tank You..
0 helpful
Anonymous 23 Feb 2026
var a=gs.getUser().getRoles(); gs.log(a); gs.log(a.size());
0 helpful
0 helpful
*Please enter a reply
Swetha 16 Jul 2023
During my interview, I was asked to write a script where I need to return a user's Manager's Manager(Seniormanager). If the field is empty, in that case i have to return his above level manager (Director). Can you help me with the solution code.
Praveen K 20 Sep 2023
Try using Dot walking and if statement for example - var gr = new GlideRecord('sys_user') gr.addQuery('sys_id','02826bf03710200044e0bfc8bcbe5d88'); gr.query(); if (gr.next()){ gs.print('User Name - ' gr.name) gs.print('Manager Name - ' gr.manager.name) if(gr.manager.manager.name){ gs.print('Managers Manager Name - ' gr.manager.manager.name) //Make sure that managers field is populated in users and managers record } else{ gs.print('Director Details (I dont have director so not displaying)') } }
0 helpful
0 helpful
*Please enter a reply
Mohit Singhal 01 Apr 2023
Write Background script code to Make all the incidents active as false whose caller starts with 's'.
Kushal 03 Apr 2023
There is small trick in this scenario. Many developer don't know that we can dot walk caller name in encoded query itself (2nd line in below script). Instead developers glide into all incidents and then they add if condition to check if caller name startswith s, which is valid solution but not efficient one. Script :var grIncident=new GlideRecord("incident"); grIncident.addEncodedQuery("caller_id.nameSTARTSWITHs"); //Here dot walk is very important, very useful in many scenarios grIncident.query(); while(grIncident.next()){ grIncident.setValue("active",false); grIncident.update(); }
1 helpful
Prerna 03 Apr 2023
Thanks Kushal. I never knew dot walk work this way as well.
1 helpful
Rakesh 06 Apr 2023
Hey Kushal, Your script works but it is not efficient. In this case we can rather use updateMultiple method as we are going to update same value for all filtered records ( that is making it false ). Interviewer normally expects efficient script from candidates. We can use below script : var grIncident=new GlideRecord("incident"); grIncident.addEncodedQuery("caller_id.nameSTARTSWITHs"); grIncident.query(); grIncident.setValue("active",false); grIncident.updateMultiple();
1 helpful
Mohit Singhal 01 May 2023
As I have read , Incident's Active is set to false when Incident state is Closed or Cancelled.
1 helpful
Astik 04 Dec 2023
var gr = new GlideRecord('incident'); gr.addEncodedQuery('caller_idSTARTSWITHs^ORcaller_idSTARTSWITHWITHS'); gr.query(); while(gr.next()){ gr.setValue('active',false); gr.update(); }
0 helpful
Ashutosh Kumar 20 Oct 2024
you need to change state of new cases to canceled/closed/resolve than only you can set Active false. var gr = new GlideRecord('incident'); gr.addEncodedQuery('caller_idSTARTSWITHs^active=true'); gr.query(); while(gr.next()){ gr.state=8; gr.active=false; gr.update(); }
0 helpful
0 helpful
*Please enter a reply
Share a Question
?
Questions are reviewed before publishing to maintain quality. Include the role, scenario, or context if possible — specific questions are more useful to others.

🚀 Power Up Your ServiceNow Career

Join a growing community of smart ServiceNow professionals to stay ahead in interviews, sharpen your development skills, and accelerate your career.

📱

ServiceNow Buddy App

Get the free Android app for a smoother experience.

Install
Comments 2
S
Sonali 31 Jan 2025
This is a brilliant set of questions and answers! I’ve been asked many of these questions repeatedly. I must also admit, I’m finding the user-shared questions incredibly interesting and valuable for my interview preparation. I am just loving the fact that everyone is contributing their questions and answers here.
P
Prerna 03 Apr 2023
I can't express how much your content is useful for me. Around 70% questions were asked to me are from your set of question and answers. Now I am able to crack L1 interviews easily.
* Please enter a comment before submitting.
📝 My Topic Notes 🔒 Only visible to you
Previous Scenario Based Questions Next ACL Questions

Found these questions helpful?

Share your experience — it helps other ServiceNow professionals know what to prepare.

Share Your Story →