- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2017 04:07 AM
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2017 04:35 AM
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
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2017 04:35 AM
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
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2017 04:38 AM
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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2017 04:45 AM
Hi Riaz,
Yes - The server side code can be run from any server side component (UI action, workflow script, etc.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2017 04:47 AM
Thanks Chuck - I didnt extend with the task table when I created so the workflow does not let me create an Incident