autopopulate string field with manager's reportees
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 12:27 AM
Hi experts,
we have a requirement to display logged in manager's reportees in a string field on a record producer and send email to all of them when a HR case is created. how can we achieve this?
TIA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 09:24 AM
Hi @si21 ,
Do the following.
1. Create one "reportee" variable of type list collector referencing to user table.
2. Write onload client script and call script include to get the repartee's sys id.
use below code to get the reportee list.
// Step 1: Get the logged-in user
var user = gs.getUser();
var managerSysId;
// Step 2: Find the manager of the logged-in user
var userGR = new GlideRecord('sys_user');
if (userGR.get(user.getID())) {
managerSysId = userGR.manager; // Get the manager's Sys ID
}
// Step 3: Query for reportees
var reportees = [];
if (managerSysId) {
var reporteeGR = new GlideRecord('sys_user');
reporteeGR.addQuery('manager', managerSysId);
reporteeGR.query();
while (reporteeGR.next()) {
reportees.push({
sys_id: reporteeGR.sys_id,
});
}
}
3. Set those sys ids to "reportee" and submit the record.
4. On case form create filed to hold the reportee value, create list type field.
5. Create Notification and choose that field to send email.
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
LinkedIn: https://www.linkedin.com/in/runjay
YouTube: https://www.youtube.com/@RunjayP
-------------------------------------------------------------------------