Schedule based Assignment Rule

MuhammadAqS
Tera Contributor

I have a below requirement:

From 5pm India time to 11.59pm India time, tickets on the Incident table for the Location named ‘Noida’ should be assigned to a group called "ANZ Noida After Hours Operations Team"

From 12am India time to 4.59pm India time, tickets on the Incident table for the Location named ‘Noida’ should be assigned to "ANZ Noida Operations Team".

I have written a below Assignment Rule Script for this, but it is not working. Any idea?


if (current.location == 'Noida') {
var indiaTime = new GlideDateTime();
indiaTime.setTZ('IST');
var currentHour = indiaTime.getHourOfDayLocalTime();

if (currentHour >= 17 && currentHour <= 23) {
current.assignment_group.setDisplayValue('ANZ Noida After Hours Operations Team');
}
else {
current.assignment_group.setDisplayValue('ANZ Noida Operations Team');
}
}



4 ACCEPTED SOLUTIONS

Satishkumar B
Giga Sage
Giga Sage

Hi @MuhammadAqS 
try this:

 

 

 

(function executeRule(current, previous /*null when async*/) {

    // Get the location display value
    var location = current.location.getDisplayValue();
    
    // Check if the location is 'Noida'
    if (location == 'Noida') {
        // Get the current time in IST
        var indiaTime = new GlideDateTime();
        indiaTime.setTZ('Asia/Kolkata'); // Use the correct time zone ID
        var currentHour = indiaTime.getLocalTime().getHourOfDay(); // Correct method to get local hour

        // Check time condition and set the assignment group accordingly
        if (currentHour >= 17 || currentHour < 5) {
            // Assign to After Hours Operations Team
            var afterHoursGroup = new GlideRecord('sys_user_group');
            if (afterHoursGroup.get('name', 'ANZ Noida After Hours Operations Team')) {
                current.assignment_group = afterHoursGroup.sys_id;
            }
        } else {
            // Assign to Operations Team
            var operationsGroup = new GlideRecord('sys_user_group');
            if (operationsGroup.get('name', 'ANZ Noida Operations Team')) {
                current.assignment_group = operationsGroup.sys_id;
            }
        }
    }

})(current, previous);

 

 

 

 

……………………………………………………………………………………………………

Please Mark it helpful 👍and Accept Solution✔️!! If this helps you to understand. 

View solution in original post

Can you try debugging the code by adding logs and see where your getting error.


View solution in original post

Hi @MuhammadAqS 

Location is your reference field or Choice field. can you share me the screenshot of you Configure dictionary for Location field.


View solution in original post

Hi @MuhammadAqS 

can we connect , if thats ok for you?
 

View solution in original post

9 REPLIES 9

Satishkumar B
Giga Sage
Giga Sage

Hi @MuhammadAqS 
try this:

 

 

 

(function executeRule(current, previous /*null when async*/) {

    // Get the location display value
    var location = current.location.getDisplayValue();
    
    // Check if the location is 'Noida'
    if (location == 'Noida') {
        // Get the current time in IST
        var indiaTime = new GlideDateTime();
        indiaTime.setTZ('Asia/Kolkata'); // Use the correct time zone ID
        var currentHour = indiaTime.getLocalTime().getHourOfDay(); // Correct method to get local hour

        // Check time condition and set the assignment group accordingly
        if (currentHour >= 17 || currentHour < 5) {
            // Assign to After Hours Operations Team
            var afterHoursGroup = new GlideRecord('sys_user_group');
            if (afterHoursGroup.get('name', 'ANZ Noida After Hours Operations Team')) {
                current.assignment_group = afterHoursGroup.sys_id;
            }
        } else {
            // Assign to Operations Team
            var operationsGroup = new GlideRecord('sys_user_group');
            if (operationsGroup.get('name', 'ANZ Noida Operations Team')) {
                current.assignment_group = operationsGroup.sys_id;
            }
        }
    }

})(current, previous);

 

 

 

 

……………………………………………………………………………………………………

Please Mark it helpful 👍and Accept Solution✔️!! If this helps you to understand. 

Hi @Satishkumar B ,

I have tried this, but it is not working.

Can you try debugging the code by adding logs and see where your getting error.


I have debugged that but it is not executing a first if condition for checking the location.