pending caller ticket close

c_neytergen
Mega Contributor

I have added new incident state named "Pending Customer. Could oyu please help how can i add following rule in to IM Module?

Incident State = Pending Customer

if there is no response from customer than ticket should be closed after 5 days automaticlly?

thank you.

1 ACCEPTED SOLUTION

You can still validate the script via running it into a scheduled script execution.



Go to System Definition -> Scheduled Jobs -> Automatically run a script of your choosing -> add your script there



This will run it a scheduled job and should be visible under stats.do on workers.



Regards,


Sergiu


View solution in original post

13 REPLIES 13

manita_anand
Giga Expert

Hi,



you can have a hidden field created "Pending customer time"   which would capture the time the incident was put to state "Pending customer".


The same hidden field can be used to write a business rule which would calculate the "Pending customer time + 5days" and current.state =="Pending Customer" and also you can add additional consition to check "Last updated time" is 5 days ago {which means no update was done on that incident from past 5 days}



and if condiions are true, then it should set the current.state ="Closed"



Hope this helped you, if yes please makr my answer as "helpful/correct".



Thanks!


Happy to help you


sergiu_panaite
ServiceNow Employee
ServiceNow Employee

There is an out of box scheduled job that calls a business rule for that on incident table.



The out of box scheduled job: Autoclose Incidents


The business rule: incident autoclose



You can create a similar BR/scheduled job.



The BR has the conditions to close the incident based on state:



// This script automatically closes incidents that are resolved


// and haven't been updated in the specified number of days.


// This number is a property in System Properties.


// To place a comment in the incident, uncomment the "gr.comments" line.




autoCloseIncidents();




function autoCloseIncidents() {


  var ps = gs.getProperty('glide.ui.autoclose.time');


  var pn = parseInt(ps);


  var queryTime = new GlideDateTime();


  queryTime.addDaysUTC(-pn);




  if (pn > 0) {


  var gr = new GlideRecord('incident');


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


  gr.addQuery('sys_updated_on', '<', queryTime);


  gr.query();


  while(gr.next()) {


  gr.incident_state = '7';


  //   gr.comments = 'Incident automatically closed after ' + pn + ' days in the Resolved state.';


  gr.active = false;


  gr.update();


  }


  }


}



Regards,


Sergiu


Hello,



i have created Scheduled Jobs with follow script., need your feedback for this



thank you



var ps = 1;


var pn = parseInt(ps);



if (pn > 0) {


var gr = new GlideRecord('incident');


gr.addQuery('incident_state', '4');


gr.addQuery('sys_updated_on', '<', gs.daysAgoStart(pn));


gr.query();


while(gr.next()) {


gr.incident_state = '8';


gr.comments = 'í‡aÄŸrınıza istenilen süre içerisinde cevap vermediÄŸiniz için çaÄŸrınızın kapatılmıştır.';


// gr.active = false;


gr.update();


}


}


I modified your script to just print the incidents it find and it works on my own instance:



var ps = 1;


var pn = parseInt(ps);



if (pn > 0) {


var gr = new GlideRecord('incident');


gr.addQuery('incident_state', '4');


gr.addQuery('sys_updated_on', '<', gs.daysAgoStart(pn));


gr.query();


while(gr.next()) {


gs.print('Found a record ' + gr.number);


}


}



And I get when running via Background Script:



[0:00:00.011] Script completed in scope global: script



*** Script: Found a record INC0000017
*** Script: Found a record INC0000007
*** Script: Found a record INC0000054


In your case, if you close those incidents, you should set the "active" to "false" as well. I see you commented it out.


But, before running this on a production instance, I strongly recommend that you do some tests on a subproduction instance just to make sure you get the desired results.



Regards,


Sergiu