Auto generate Incident based on Date

riaz_mansuri
Kilo Guru

Hello,

I have create a new table to capture Infra Certificates and one of the fields is Expiry Date.

I would an Incident to be created and assigned to a specific group 6 weeks before the Expiry Date is reached.

Can some help me and explain what needs to be done?

If any scripting needs to be done it would be useful to have a few lines of code as I am not experienced in this.

Thanks

Riaz

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi Riaz,



You're going to need to create a scheduled job that runs   a small script. Here's a starting point for you.



http://wiki.servicenow.com/index.php?title=Creating_a_Scheduled_Job



var rec = new GlideRecord('YOURTABLE');


rec.query();




while (rec.next()) {


  var now = new GlideDateTime();


  var gdt = new GlideDateTime();


      gdt.setValue(rec.getValue('YOUR EXPIRY FIELD NAME'));


      gdt.addWeeksLocalTime(-6);


  if (gdt.getNumericValue() < now.getNumericValue()) {


            // Expires in 6 weeks or less - do something here


  }


}


View solution in original post

13 REPLIES 13

Chuck Tomasi
Tera Patron

Hi Riaz,



You're going to need to create a scheduled job that runs   a small script. Here's a starting point for you.



http://wiki.servicenow.com/index.php?title=Creating_a_Scheduled_Job



var rec = new GlideRecord('YOURTABLE');


rec.query();




while (rec.next()) {


  var now = new GlideDateTime();


  var gdt = new GlideDateTime();


      gdt.setValue(rec.getValue('YOUR EXPIRY FIELD NAME'));


      gdt.addWeeksLocalTime(-6);


  if (gdt.getNumericValue() < now.getNumericValue()) {


            // Expires in 6 weeks or less - do something here


  }


}


Thanks Chuck - Can this be also done via a workflow and create task - Incident?



Thinking it might be easier then to put a condition to wait 30 days?


Hi Riaz,



Yes - The server side code can be run from any server side component (UI action, workflow script, etc.)


Thanks Chuck - I didnt extend with the task table when I created so the workflow does not let me create an Incident