The CreatorCon Call for Content is officially open! Get started here.

Script to determine age of a ticket

reeset
Kilo Contributor

Hi everyone.   I am happy you. All are here and can   hopefully assist me

i tried this through inactivity monitor but it doesn't work correctly. So I would like to use another method like scripyin and have the scripting trigger an email

The parameters are.   Check ll incidents if the incident is 30 days or more and still open,   trigger an email to go out to the assignee of ticket.   This should be done for all open, ain progress, pending or assigen.   Got all tickets that are found an email is sent to the assignee   and manager

i I don't want to use inactivity monitor.   I would like to use a script which fire off an email

does anyone already have something like this or able ti share how this Cavan be accomplished

THANK YOU,,,

24 REPLIES 24

edwin_munoz
Mega Guru

Hello Terry,



Refer to this page to see how to create a Scheduled script. Creating a Scheduled Job - ServiceNow Wiki



Use this script as the condition to first check if there are any scripts that are older tan 30 days,



var ga = new GlideAggregate('incident');


ga.addAggregate('COUNT');


ga.addQuery('active', 'true');


ga.addQuery('sys_created_on', '<', gs.daysAgo(30));


ga.query();


ga.next();


ga.getAggregate('COUNT') !== '0';



Then use this as the script:



var gr = new GlideRecord('incident');


gr.addQuery('incident_state', '<', 6);


gr.addQuery('sys_created_on', '<', gs.daysAgo(30));


gr.query();




while(gr.next()){


  gs.eventQueue("incident.unresolved", gr);


}



Then go to System Policy -> Events -> Registry and create the event "incident.unresolved", select incident as table



Then create an email notification that runs when the event incident.unresolved is triggered, select incident as table. On who will receive select the assigned to field of the incident.



I think this is all you need to do to fulfill your requirement



Good luck!


Edwin, thank you so much for responding to me.   I greatly appreciate it.   I am a little confused about the two scripts.   I created the first one no problem.   Do I modify the first one with the second one or do I add it to the bottom of the first one or do I create a completely new script.   Sorry I am a little confused and need a little more direction.     Thank you so much!


Hello Terry,


On the Scheduled Job you must select the conditional check box. After you select the check box you are going to see a condition field (text area). there you will have to place the first script. The other script must be in "Run this script"



Thank you.


Hi Edwin, thank you for the response.   I still can't get it to run.   Can you tell me when I create the event do I select Business Rule or Notification.   I have been selecting notification.   I checked the events log and the scheduled job has run, but it is not sending any emails.   Im not sure what I am going wrong.     THANK YOU