ServiceNow Interview Questions and Answers – User Shared Q&A (Set 6)
Akash 2023-07-11 23:05:10
How to add catalog item fields in workflow
Sushmitha 2023-07-27 20:56:33
current.variables.variable_name
0 Helpfuls
0 Helpfuls
Swetha 2023-07-12 16:28:56
I got a question like how to show different different portals for different user roles.
Sureshmayan 2023-10-30 21:53:12
using Page route map
1 Helpfuls
Pradeep 2024-04-25 01:19:28
By modifying SPEtryPage script include
1 Helpfuls
1 Helpfuls
Satyapriya Biswal 2023-07-15 07:56:31
What are Private functions and what are the uses of it?
Can we call a private function from one script include to another script include?
Can You share a scenario where we can use private functions?
Ritesh 2023-08-28 06:16:50
Private functions are the functions which can be accessed/called from same script include or child script include, which means it cannot be called in background script or Fix script directly.
Private function in SN can be defined by using underscore in the beginning of function name
e.g. _getUserData:function(){}
0 Helpfuls
0 Helpfuls
Swetha 2023-07-16 11:33:42
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 2023-09-20 23:58:17
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 Helpfuls
0 Helpfuls
Vinay 2023-07-18 08:12:18
What are the different types of risks in change management
0 Helpfuls
Priyanka 2023-07-26 22:58:38
Difference between workflow and flow
Pranav 2023-09-05 06:51:24
1. Flow can be scheduled, workflow cannot.
2. Flow have multiple triggers e.g. Inbound email triggers, Application triggers and Rest Triggers, workflow can be triggered based on record creation or update.
2 Helpfuls
5 Helpfuls
Sammy 2023-07-27 09:42:42
How to update change state from "Scheduled" to "Implement" automatically when Planned start date is reached?
Suresh Thorati 2023-09-26 07:14:18
1. Create a BR on Change Table.
a. State = Scheduled
Advanced: use glide time
0 Helpfuls
Trupti 2023-10-09 11:15:32
- You can either use Flow Designer or Scheduled Job.
- Schedule it to execute daily.
- Glide into 'Change' table and check if planned start date = todays date and state=scheduled then update change state to 'implement'
0 Helpfuls
snowexpertaastik 2024-11-02 04:36:14
Basically you can write one Scheduled job that runs daily and check those whose Planned Start date is today and if records matches conditions then update the state of those records to implement . Below is the sample code
var changeReqs = new GlideRecord('change_request');
changeReqs.addEncodedQuery('start_dateONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()');
changeReqs.query();
while(changeReqs.next()){
changeReqs.setValue('state',-1);
changeReqs.update();
}
0 Helpfuls
0 Helpfuls
Satyapriya Biswal 2023-08-05 04:58:56
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 2023-08-06 13:11:44
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 Helpfuls
ps 2023-08-07 08:56:19
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 Helpfuls
Ria 2023-08-23 11:15:54
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 Helpfuls
Satyapriya Biswal 2023-08-25 02:11:26
Thanks
0 Helpfuls
Praveen K 2023-09-20 23:43:56
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 Helpfuls
Bharath 2024-07-12 13:27:33
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 Helpfuls
0 Helpfuls
Ranjit 2023-08-07 20:05:22
Whether the g_scarthpad can be used on all the types of client script?
Naveen 2023-08-19 01:03:09
g_scratchpad is used only in Onload Client scripts to get the data from Display business rule.
1 Helpfuls
Roshan 2023-08-24 08:05:47
In most of the use cases, we access it in onLoad client script. However g_scratchpad object can be accessed in all type of client scripts. In fact it can be accessed in UI policy script also.
Here is very important use case where it can be used in on submit client script, if we want to validate something on submit of the form but data is not available on client side.
Normally we use GlideAjax to get server side data but GlideAjax fails in onSubmit client script (GlideAjax is asynchronous call therefore form gets submitted before GlideAjax returns result). Therefore we can store result in g_scratchpad object in onChange client script and based on value we can restrict form submission in on submit client script.
0 Helpfuls
0 Helpfuls
Mujahid 2023-08-10 19:21:28
4. If you used GlideAjax method to get server side data then why used GlideAjax, why not getReference or Display BR?
Saritha 2023-08-29 12:48:11
g_scratchpad is sent once when a form is loaded (information is pushed from the server to the client), whereas GlideAjax is dynamically triggered when the client requests information from the server.
If you're using getReference you will get ALL data for each record you "get" whether you need it or not.
0 Helpfuls
0 Helpfuls
Fuel My Passion
Loving the content? Well, of course you are. Here’s your chance to indirectly fuel the chaos that keeps this website running. Your contribution helps keep the wheels turning and allows me to continue pretending to be a responsible adult—while cranking out more content for you. Thanks for supporting my delusional dreams and helping me keep this website alive!
Buy Me a Coffee
Support with UPI
If you prefer making a UPI payment to support the website maintenance cost, scan the QR code below: