Scenario Based Servicenow Developer Interview Questions
Scenario Based Servicenow Developer Interview Questions
in
1. Auto-Populate Fields:
o Scenario: Set "Short Description" to "New Incident
Reported" on new incidents.
o Type: Before Insert
o Table: incident
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.
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.
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
7. Validating Data:
o Scenario: Ensure a valid phone number format before
inserting an incident.
o Type: Before Insert
o Table: incident
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.
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.
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:
1. if (current.priority == 1) {
gs.addErrorMessage("High-priority incidents cannot be
deleted!");
current.setAbortAction(true);
}
2.
14. Creating Related Records:
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
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. function onLoad() {
g_form.setReadOnly('short_description', true);
}
2.
1. function onLoad() {
g_form.setValue('priority', '3');
}
2.
• Dynamic Mandatory 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!
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!
1. function onLoad() {
alert('This is a test alert!');
}
• Preventing Editing After Setting:
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;
}
• 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 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;
}
}
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;
}
}
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;
}
}
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!
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. gs.info(gs.getUser().getDisplayName());
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!