- 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 07:49 AM
I have made some configurations in this. Below is the updated one:
if (current.location == 'Noida') {
gs.info("Test");
var indiaTime = new GlideDateTime();
indiaTime.setTZ('IST');
gs.info(indiaTime);
var currentHour = indiaTime.getHourOfDayLocalTime();
gs.info(currentHour );
if (currentHour >= 17 && currentHour <= 23) {
gs.info("If Part");
current.assignment_group.setDisplayValue('ANZ Noida After Hours Operations Team');
}
else if (currentHour >= 0 && currentHour <= 16){
gs.info("Else Part");
current.assignment_group.setDisplayValue('ANZ Noida Operations Team');
}
}
It is executing only Else part, and assigned a "'ANZ Noida Operations Team'" group for each ticket now. I guess the below part is not working.
var indiaTime = new GlideDateTime();
indiaTime.setTZ('IST');
var currentHour = indiaTime.getHourOfDayLocalTime();
- 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:19 AM
Hi @Satishkumar B,
Location condition is now working fine. I have just copied my code to the Background Script, and it is giving me the error that :
Javascript compiler exception: Can't find method com.glide.glideobject.GlideDateTime.setTZ(string). (null.null.script; line 2)
Now, I have updated my code to the below, as it is running fine in the Background script, but it is still assigning all tickets to the "ANZ Noida Operations Team" group (Else part).
if (current.location == 'Noida') {
gs.info("Test");
var indiaTime = new GlideDateTime();
gs.info("Server Time: " + indiaTime.getDisplayValue());
// Get the UTC time in milliseconds
var utcMillis = indiaTime.getNumericValue();
// Create a JavaScript Date object using UTC milliseconds
var date = new Date(utcMillis);
// Adjust to India Standard Time (IST), which is UTC+5:30
var istOffsetMillis = 5.5 * 60 * 60 * 1000;
var indiaTimeMillis = utcMillis + istOffsetMillis;
// Create a new Date object in IST
var indiaDate = new Date(indiaTimeMillis);
// Get the current hour in IST
var currentHour = indiaDate.getUTCHours(); // Use getUTCHours() after adjusting milliseconds
gs.info("Current India Time: " + indiaDate.toISOString());
gs.info("Current Hour in IST: " + currentHour);
if (currentHour >= 17 && currentHour <= 23) {
gs.info("If Part");
current.assignment_group.setDisplayValue('ANZ Noida After Hours Operations Team');
} else {
gs.info("Else Part");
current.assignment_group.setDisplayValue('ANZ Noida Operations Team');
}
}
- 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 08:32 AM
Sure, just give me 20 mins.