Convert time zone from IST to US/Eastern
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi Community,
Here my requirement is for the caller x, if created 25 incidents per day as per US/ eastern time zone then it should trigger the notification. Here i am using this business rule, but it's not triggering the notification , can anyone please help me on this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi,
What's the use case for such a restriction, to limit the number of incidents a user can create?
In my mind this will be a very bad user experience if the use a record producer, or send an email that would generate an Incident.
You would type everything to create an Incident, and then when you submit you'd get an error stating you ran out of records to submit for the day..
Maybe a friendly conversation could change the behaviour of this user instead?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
@OlaN in this case they only create manually incidents
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
I would classify submitting a record producer or sending an email as creating records manually.
On another note, if you are still going forward with this, then you will problably need to restrict it to exclude people with the ITIL role for example.
Otherwise your service desk agents will also not be able to create many records for various users, even if they call in numerous times.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Key Changes:
- Date Handling: Use
getLocalDate()to ensure the date string is correctly formatted for local time. - Logging: Added a log statement to help with debugging the count.
- Condition Update: Changed the condition to
count >= 25to trigger the event if the count is 25 or more, which might be more appropriate depending on your requirement.
You can verify with below script:
(function executeRule(current, previous /*null when async*/) {
// Define Eastern Time Zone
var tz = Packages.java.util.TimeZone.getTimeZone('US/Eastern');
// Get today's date in Eastern Time
var nowEastern = new GlideDateTime();
nowEastern.setTZ(tz);
var easternDate = nowEastern.getLocalDate().toString(); // Use getLocalDate() for local date string
// Start of day in Eastern Time
var startEastern = new GlideDateTime(easternDate + " 00:00:00");
startEastern.setTZ(tz);
// End of day in Eastern Time
var endEastern = new GlideDateTime(easternDate + " 23:59:59");
endEastern.setTZ(tz);
// Convert to UTC for query
var startUTC = startEastern.getValue();
var endUTC = endEastern.getValue();
// Query incidents
var gr = new GlideAggregate('incident');
gr.addEncodedQuery('sys_domain=a028216e47ed51508b6b4537536d4383^sys_created_on>=' + startUTC + '^sys_created_on<=' + endUTC + '^caller_id=748b5c7f97071550d2ec73100153af73');
gr.addAggregate('COUNT');
gr.query();
if (gr.next()) {
var count = parseInt(gr.getAggregate('COUNT'), 10);
// Log the count for debugging
gs.info('Incident Count for caller: ' + count);
// Trigger event if count is 25 or more
if (count >= 25) {
gs.eventQueue('it.checkmate.incident.limit.reached', current);
}
}
})(current, previous);
