Condition Script not working (Scheduled Reports)
This content was last updated in 2023. It may still be useful, but could contain outdated information. Please confirm its accuracy before relying on it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 06:26 AM
Hi based on the incident table i would like to schedule a report if a new specific record entry was made like: Application Service = X AND Priority = P1 OR P2 etc.
I use this condition scrip but it is not terminating with true
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 06:56 AM - edited 11-24-2023 07:25 AM
var incidentGr = new GlideRecord('incident');
incidentGr.addEncodedQuery("priorityIN1,2^state=1^opened_atRELATIVEGT@minute@ago@20");
incidentGr.query();
answer = incidentGr.hasNext();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 08:26 AM
Hi Kevin,
thank you for your support! My goal is to Create a Report based on the incident table with a specific query which shall include a specific application service, priority. Whenever an incident is created based on the query a report auf the incident should be send. I know it is easy to implement with Business rules, but my company restricts access.
for the Code i posted first, a table view was working i saw two records an expected the scheduled Report to be triggered. But somehow it did not trigger the report.
Thanks
Artur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 09:12 PM
HI @Artur Schulz ,
I trust you are doing great.
Here's an updated version of your script with explanations:
// Initialize the GlideAggregate for the 'incident' table
var count = new GlideAggregate('incident');
// Add your query here. Ensure that the encoded query is correct and represents your conditions accurately.
// For example, 'application_service=YOUR_SERVICE_ID' should be replaced with the actual service ID.
// 'priorityIN1,2' selects incidents with priority 1 or 2.
// 'state=1' selects incidents in a specific state, adjust as needed.
// 'opened_atRELATIVEGT@minute@ago@20' selects incidents opened in the last 20 minutes.
count.addEncodedQuery("application_service=YOUR_SERVICE_ID^priorityIN1,2^state=1^opened_atRELATIVEGT@minute@ago@20");
// Count the number of incidents matching the query
count.addAggregate('COUNT');
count.query();
// Initialize a variable to hold the count of incidents
var incidents = 0;
// Retrieve the aggregate count if available
if (count.next()) {
incidents = count.getAggregate('COUNT');
}
// Set 'answer' to true if there is at least one incident, otherwise false
var answer = (incidents >= 1);