- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 03:59 AM
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');
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 04:22 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 05:08 AM
Can you try debugging the code by adding logs and see where your getting error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 08:05 AM
Hi @MuhammadAqS
Location is your reference field or Choice field. can you share me the screenshot of you Configure dictionary for Location field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 08:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 04:22 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 04:45 AM
Hi @Satishkumar B ,
I have tried this, but it is not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 05:08 AM
Can you try debugging the code by adding logs and see where your getting error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 06:15 AM
I have debugged that but it is not executing a first if condition for checking the location.