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

Hi Chuck,



Does this seem right o you?



find_real_file.png


That's the general idea.


Sorry what I meant was have i selected the correct information here? Or would you recommend i just recreate the table and extend with the Task table?



It is a new table so no records...


I don't think you need to recreate the table from Task in this case.



If you can create a workflow, you can always use the Run Script activity to generate a record on (almost) any table as well.



Ex:



var inc = new GlideRecord('incident');


inc.newRecord();


inc.assignment_group.setDisplayValue('NAME OF YOUR ASSIGNMENT GROUP');


inc.short_description = 'SOME DESCRIPTION';


inc.insert();


Thanks Chuck that is great but then how do I relate any of the information from that Record back to the Incident?