code is not working as expected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 02:47 AM - edited 11-30-2023 06:37 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 03:10 AM
Hi,
I don't see any comparison with incident date fields.
Your script is not calculating days. What should be the criteria for no of Days? From Last updated or from Created date?
If last updated then you need t record the date in one field when ticket state changes to Pending and calculate the duration of Days from that date till today.
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 03:37 AM - edited 11-30-2023 06:41 AM
Hi Anil,
here is the code. The days part is working as expected. but comparison in for loop is not iterating for all the records .
I have tried with a single record . it worked.
var curDate = new GlideDateTime();
var DaysArray = [3,5,7];
var pendingDays;
var gr = new GlideRecord('u_incident');
gr.addEncodedQuery('assignment_group=a57e93e38bf34e10de76b710fe4ee3ea^u_status=Pending');
gr.query();
while (gr.next()) {
var pendingStartDate = gr.u_pend_start_date; (This field holds the date when the incident is inserted/updated to Pending status via a BR. Just making use of the existing field)
for (var i = 0; i < DaysArray.length; i++) {
gs.info(" DaysArray before if" + DaysArray[i]);
if (pendingDays == DaysArray[i]) {
gs.eventQueue('event name', gr, '');
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 04:50 AM
Hi,
I couldn't test your script because of some script include calls you have made.
I believe you need to change this line:
dur.push(utils.getBDDuration(pendingStartDate, curDate)); // calculating the Business Days Duration
to below:
Thanks
Anil Lande