Create incident from scheduled job

riaz_mansuri
Kilo Guru

Hi

yesterday Chuck started me ok with this script:

var rec = new GlideRecord('u_infrastructure_certificates');

rec.query();

while (rec.next()) {

  var now = new GlideDateTime();

  var gdt = new GlideDateTime();

      gdt.setValue(rec.getValue('u_cert_expiry_date'));

      gdt.addWeeksLocalTime(-6);

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

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

  }

}

Not being a scripter please help:

a: how do I change this so it only applies it to the record if the date is exactly 30 days

b: How do I get it to add the below so it creates the incident

var gr = new GlideRecord('incident');

gr.intialize();

gr.short_description = 'Certificate renewal required';

gr.assignment_group = '5e8550e90f6e3900f6e783fc22050ef3';

gr.description = current.u_subject_name;

//gr.cmdb_ci = 'Certificate Services (Corporate Internal)';

gr.setDisplayValue('cmdb_ci','Certificate Services (Corporate Internal)');

//gr.u_inf_certificate = current.number;

gr.u_inf_certificate = current.sys_id;

gr.insert();

Help much appreciated

Thanks,

Riaz

12 REPLIES 12

Thank Chuck I will play around this a lot its a great start



riaz


riaz_mansuri
Kilo Guru

Just to update on this. Christoper Jhonson from the community supplied the correct script from another post



  1.       var chkDate = new GlideDate();  
  2.       chkDate.addDays(30);  
  3.       var rec = new GlideRecord('u_infra_certificates');  
  4.       rec.addQuery('u_cert_expiry_date', chkDate);    
  5.       rec.query();  
  6.       gs.print(rec.getRowCount());  


Thanks,


Riaz



Hi riaz.mansuri,
 
I am looking for a way to create an incident to recertify accounts every 6 months
and this script of yours I think would be the solution, would you be so kind to paste the full version that today is working with 30 days so based on the same I see to modify them for our need.
 
Thanks a lot.