- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2017 10:44 AM
Hi,
So with a little help from the community I am almost in a good position.
What I need is for the schedule job to run daily. It needs to search the u_infra_certificates table and query the u_expiry_date.
If this date is EXACTLY 30 days from today it will trigger an Incident.
The incident part works fine but what I cannot get it to do is only run it if it is exactly 30 days.
So when it runs daily it skips it if the date is 29 days or 31 days.
My script is below.
var rec = new GlideRecord('u_infra_certificates');
rec.query();
if(rec.next()) {
var now = new GlideDateTime();
var gdt = new GlideDateTime(''+rec.u_cert_expiry_date);
var diffSeconds = gs.dateDiff(gdt, now, true);
if (diffSeconds < 2592000) {
//creates incident
var gr = new GlideRecord('incident');
gr.intialize();
gr.short_description = 'Certificate renewal required';
gr.assignment_group = '5e8550e90f6e3900f6e783fc22050ef3';
gr.description = rec.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 = rec.sys_id;
gr.insert();
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2017 01:03 PM
Your dates are in the future. I was under the impression that you wanted to create an incident if it had already expired. Try using positive numbers instead of negative numbers. I also discovered that there is a GlideDate method that was used since I created the original script, so there is no need to strip off the time:
var chkDate = new GlideDate();
chkDate.addDays(30);
var rec = new GlideRecord('u_infra_certificates');
rec.addQuery('u_cert_expiry_date', chkDate);
rec.query();
gs.print(rec.getRowCount());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2017 01:40 PM
Perfect it was a reference field but was referencing my old table to this. Corrected this and allis perfect
Thanks you very very much