- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 09:11 PM
Hi Experts
I want to print the incidents caller's managers manages names in the background script.
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 09:44 PM - edited 06-13-2024 09:46 PM
Hi @dhineshkumar,
Please find the below code for the manager'manager :
var inc = new GlideRecord('incident');
inc.get('57384e19c332021003c8deec05013184');//pass the incident record's SYSID
inc.query();
var incusr = inc.caller_id;
gs.info('user Name ' +incusr.name);
gs.info('Manager Name ' +inc.caller_id.manager.manager);//here you will get manager's manager SYSID
Please avoid multiple glideRecord. It will downgrade your performance
Please accept my solution if it works for you and thumps up.
Thanks
Jitendra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
Hi @eepinaveen,
Please put one dot walk
gs.print(inc.caller_id.manager.name)
Please accept my solution if it resolves your query.
Thanks and Regards
Jitendra Diwakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 09:49 PM
Hi @dhineshkumar
use this script in your Background Script editor to print the name of Incident Caller`s Manager`s Manager
Script:
var incidentGR = new GlideRecord('incident');
incidentGR.addEncodedQuery('numberININC0009009,INC0009005');
incidentGR.query();
while (incidentGR.next()) {
// Get the Incident number and Caller Sys ID
var incidentNumber = incidentGR.getValue('number');
var callerSysId = incidentGR.getValue('caller_id');
// Retrieve the Caller (User) details
var callerGR = new GlideRecord('sys_user');
if (callerGR.get(callerSysId)) {
// Get the Caller’s Manager Sys ID
var managerSysId = callerGR.getValue('manager');
// Retrieve the Manager details
var managerGR = new GlideRecord('sys_user');
if (managerGR.get(managerSysId)) {
// Get the Manager’s Manager Sys ID
var managersManagerSysId = managerGR.getValue('manager');
var managersManagerGR = new GlideRecord('sys_user');
if (managersManagerGR.get(managersManagerSysId)) {
// Print the Incident number, Caller’s name, Manager’s name, and Manager’s Manager’s name
gs.print('For Incident ' + incidentNumber + ':');
gs.print('Caller: ' + callerGR.getValue('name'));
gs.print('Manager: ' + managerGR.getValue('name'));
gs.print('Managers Manager: ' + managersManagerGR.getValue('name'));
} else {
gs.print('Manager’s Manager not found for Manager ' + managerGR.getValue('name') + ', associated with Incident ' + incidentNumber);
}
} else {
gs.print('Manager not found for Caller ' + callerGR.getValue('name') + ', associated with Incident ' + incidentNumber);
}
} else {
gs.print('Caller not found for Incident ' + incidentNumber);
}
}
Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 09:53 PM - edited 06-13-2024 09:54 PM
Hi @dhineshkumar
Please Use the addExtraField method to avoid multiple GlideRecord which cause more query time find the code snippet below
var incidentgr = new GlideRecord('incident');
incidentgr.addQuery('sys_id','57af7aec73d423002728660c4cf6a71c'); //<replace your incident sys_id>
incidentgr.addExtraField('caller_id.manager.manager.name');
incidentgr.query();
if(incidentgr.next()){
gs.print("Caller's Manager Name: "+incidentgr.caller_id.manager.name);
gs.print("Caller's Manager's Manager Name: "+incidentgr.caller_id.manager.manager.name);
}
Mark this as Helpful / Accept the Solution if this clears your issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 10:06 PM
please find Below code
Please accept my solution if it work for you.
var incidentGR = new GlideRecord('incident');
incidentGR.query();
while (incidentGR.next()) {
var callerId = incidentGR.caller_id;
if (callerId) {
var userGR = new GlideRecord('sys_user');
userGR.addQuery('sys_id', callerId);
userGR.query();
if (userGR.next()) {
var managerId = userGR.manager;
if (managerId) {
var managerGR = new GlideRecord('sys_user');
managerGR.addQuery('sys_id', managerId);
managerGR.query();
if (managerGR.next()) {
// Print the manager's name
gs.print('Manager Name: ' + managerGR.name);
}
}
}
}
}