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

That would be done with a reference field. If you want the incident to reference the original record, you can create a reference field on the incident (e.g. u_cert) that points to your cert table and populate the field in the script before you do the inc.insert().



inc.u_cert = current.sys_id;


PerfectThanks Chuck


You are welcome Riaz,



If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.



If you are viewing this from the community inbox you will not see the correct answer button.   If so, please review How to Mark Answers Correct From Inbox View.



Thank you


Thank you again Chuck -