- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2020 08:50 AM
I have requirement to to create a round-robin type approach (Auto Assignment) for any incidents/tasks that come into our groups(Many groups).
I have created below BR as per one of the community suggested and its working fine for one group.
(function executeRule(current, previous /*null when async*/ ) {
gs.sleep(3000); // Sleep statement added to prevent ticket flood being assigned to a single technician.
current.assigned_to = resolveTech();
function resolveTech() {
var tech_arr = [];
var group = new GlideRecord('sys_user_grmember');
group.addQuery('group', '0a52d3dcd7011200f2d224837e6103f2');
group.query();
var tech = "";
var lastAssigned = "";
var isAssignable = false;
while (group.next()) {
isAssignable = group.user.u_round_robin_active;
tech = group.user.sys_id;
lastAssigned = group.user.u_last_ticket_assigned + "";
if (isAssignable == true) {
tech_arr.push({
sys_id: tech,
last_assigned: lastAssigned
});
}
}
// Sort on last assigned, return user with.
tech_arr.sort(function(a, b) {
return (a.last_assigned < b.last_assigned ? -1 : (a.last_assigned > b.last_assigned ? 1 : 0));
});
updateDateTime(tech_arr[0].sys_id); // Updating ticket last assigned date
gs.sleep(2000);
return (tech_arr[0].sys_id); // Assigned_to technician (sys_id).
}
function updateDateTime(assignedTo_sysID) {
var nowdt = gs.nowDateTime();
var updateDate = new GlideRecord('sys_user');
updateDate.addQuery('sys_id', assignedTo_sysID);
updateDate.query();
while (updateDate.next()) {
updateDate.u_last_ticket_assigned = nowdt;
updateDate.update();
}
}
})(current, previous);
If I add another group's sys_id in code then its not working for other group(i mean its not assigning to other group members).And i have below requirement.
1.Based on User Time zone field , ticket should assign to user(Lets we have 6 members,three from India and three from US, When its off hours in India then it will assign to US time zone members and it should exclude)
2.Ticket should assign to particular users in case P1/P2(Need to hardcode the users name)
3.Need to check Active(user.u_round_robin_active) and last login time of the user before assigning ticket(Both condition should match to assign ticket)
Please help me to automate this approach.
Thanks In Advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2020 12:13 AM
Hi,
I tried this way, it works fine with Round Robin concept. This might not be the final code, probably you could enhance with other use case.
gs.sleep(3000);
//Default P1, P2 handling Users
var aUser = ['62826bf03710200044e0bfc8bcbe5df1', 'a8f98bb0eb32010045e1a5115206fe3a']; //Abel Tuter, Abraham Lincoln
//The ticket should be assigned to based on Group membership
if(current.priority > 2){
//Fetch list of Users
var grGrpMem = new GlideRecord('sys_user_grmember');
grGrpMem.addQuery('group', current.assignment_group);
grGrpMem.query();
while (grGrpMem.next()) {
aUser.push(grGrpMem.getValue('user'));
}
}
//Fetch right User
var grUser = new GlideRecord('sys_user');
grUser.addQuery('sys_id', 'IN', aUser.join()); //Fetch all the Users in the group
grUser.addQuery('u_round_robin_active', true); //Filter only eligible for Round Robin
//grUser.addEncodedQuery('last_login_timeONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()'); //Who is available in the Shift
grUser.orderBy('u_last_ticket_assigned'); //Order by ASC on Last Ticket Assigned
grUser.setLimit(1); //Fetch only the first user
grUser.query();
if (grUser.next()) {
grUser.setValue('u_last_ticket_assigned', gs.nowDateTime());
grUser.update();
current.setValue('assigned_to', grUser.getValue('sys_id'));
}
Hope this might helpful to you!
Regards,
Bala T
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2020 06:28 AM
Before taking further i just wanted to check with , Is these way to achieve without creating mentioned two tables.
Because already we have time zone field on user table then we can fetch using that field only instead of creating new table.
If possible please provide solution without creating tables.
Appreciate your time and effort on this requirement.
Thank you so much.
Thanks,
Vivek
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2020 03:21 AM
Hi,
We can achieve the same by adding three fields in User [sys_user] table.
1. Is Critical Supporter - true/false
2. Start - DateTime
3. End - DateTime
However there are few problems
1. The User can be part of multiple groups and however the User will not be Critical Supporter for all the groups.
User A is part of Windows, SQL Server, Database groups and Critical Resource in Windows and SQL Server, Not on Database group. In this situation we will not be able to exclude.
2. Start & End, this will be common for multiple User as they are tagged to same timezone. We might need to update multiple records.
Hope this might be helpful to you.
Regars,
Bala T
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2020 11:34 AM
With the help of your help I am able to achieve my requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2020 04:23 AM
As suggested I have implemented by creating two tables and its working fine for Critical and not critical Scenario but When its failing when we check the TimeZone Scenario of the User.
Below is the peace of code which is not working.
var grZone = new GlideRecord('u_timezone_support');
grZone.addQuery('u_end', '>', gs.nowNoTZ());
grZone.addQuery('u_start', '<', gs.nowNoTZ());
grZone.query();
while(grZone.next()){
aTimeZone.push(grZone.getValue('u_timezone'));
}
I am suspecting issue with end and start date.
As you suggested I have given todays current date in UTC.
I have attached screen shot of timezone table which i have created.
Please check and do need to achieve this.
Thanks in Advance.
