Need to send notification to requestor manager's manager if request manager is inactive
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2024 11:39 AM
Hi,
I have a requirement, created a scheduled jobs to trigger an event and that's sends a notification to the manger it is working fine but now i need to add a logic that the notification need to send to requestor's manager if requestor manager is active if not then notification need to be send to requestor manager's manager.
If Requestor's manager is active send to requestor manager (working)
If Requestor manager is inactive then send to requestor' manager's manager.
how we can achieve this
This is my script:
- Labels:
-
Request Management
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2024 06:23 AM - edited 04-25-2024 06:30 AM
Hi @suuriya ,
Steps to achieve this.
1. Create a function to check if the user is active or not. Let us say that the function name is "IsManagerActive(sysID)". In this method return true or false.
2.Create another function to get the Manager of Manager. Let us say the function name is "getManagersManager(sysID)". In this method return the Manager's Manager sysID.
3. You need to make a decision about the manager's active status inside the loop "if(dateDiff == '7')"
Example:
Replace the below 2 lines
if(dateDiff == '7')
gs.eventQueue("notify.manager.idm.second",ci,ci.variables.common_vars_requested_for.manager);
with
if(dateDiff == '7')
{
if(IsManagerActive(ci.variables.common_vars_requested_for.manager))
{
gs.eventQueue("notify.manager.idm.second",ci,ci.variables.common_vars_requested_for.manager);
}
else
{
var managersManager = getManagersManager(ci.variables.common_vars_requested_for.manager);
gs.eventQueue("notify.manager.idm.second",ci, managersManager );
}
}
Hope this helps. Please let me know, if you need any support for creating the functions.
Simply providing the script for everything will not teach any good lesson. that is why.
Please note that here we are not checking active status for the Manager's manager. If you want to check that, you need to create one method which works for all and loop it until you get an active record. Please let me know.
Regards,
Karunakaran.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2024 03:29 AM
HI @Karunakaran ,
Thanks for the reply
But i have tried like this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2024 04:28 AM - edited 04-26-2024 04:30 AM
Hi @suuriya
Normally in server side this dot walking will work.
But, it also depends on the variable type. If it is a table object, it will work. please give a try.
But, it is not a generic solution in some cases where 1st two level of manager's status is inactive.
Please let me know, if you want to design this solution like that.
Otherwise you are good to proceed. Thank you.
Regards,
Karunakaran.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2024 04:41 AM
The best practice is using script include
var UserManager = Class.create();
UserManager.prototype = {
initialize: function() {},
getActiveManager: function(userId) {
var user = new GlideRecord('sys_user');
if (user.get(userId)) {
// Get the user's manager
var managerId = user.getValue('manager');
if (managerId) {
var manager = new GlideRecord('sys_user');
if (manager.get(managerId)) {
// Check if the manager is active
if (manager.active) {
return manager;
} else {
// If the manager is inactive, recursively find the next active manager
return this.getActiveManager(manager.getUniqueValue());
}
}
}
}
// No active manager found
return null;
},
type: 'UserManager'
};
Calling the script include from your script:
// Create an instance of the UserManager class
var userManager = new UserManager();
// Call the getActiveManager method to retrieve the active manager of a user
var userId = 'user_sys_id'; // Replace 'user_sys_id' with the sys_id of the user
var activeManager = userManager.getActiveManager(userId);
if (activeManager) {
gs.info("Active Manager: " + activeManager.getValue('name') + ' | ' + activeManager);
gs.eventQueue("notify.manager.idm.second",ci,activeManager);
} else {
gs.info("No active manager found for the user.");
}