- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2019 06:20 AM
Can some one help me with this requirement
I want to monitor sys_user table and check if there is any update or insert happens in every 4 hours
How can i do that , Please help me with the code if possible
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2019 07:10 AM
You'll need to make a couple of modifications to your script. I think caller_id may also be a required field on the incident, but just make sure all required fields are populated in the script.
var users = new GlideRecord('sys_user');
users.addEncodedQuery('sys_created_onRELATIVEGE@hour@ago@4");
users.query();
if (!users.hasNext()){
var gr = new GlideRecord('incident');
gr.initialize();
gr.short_description = 'Certificate renewal required';
gr.assignment_group = '5e8550e90f6e3900f6e783fc22050ef3'; //Sys_id of x workgroup
gr.description = //current will not work for this scheduled job, you'll need to use data from one of the glide records
gr.cmdb_ci = 'Certificate Services (Corporate Internal)'); //I don't know whether setDisplayValue will do the same
gr.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2019 06:44 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2019 06:48 AM
Just make sure to switch "daily" to "periodically". Daily will make it only run once at 04:00 and periodically will have it run every 4 hours. Then you'll need to update the //do something line to whatever you're trying to do or check with the user record. If you're trying to check if nothing has happened in the past 4 hours, change the "While (user.next()){" to
if (!user.hasNext()){
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2019 06:53 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2019 07:10 AM
You'll need to make a couple of modifications to your script. I think caller_id may also be a required field on the incident, but just make sure all required fields are populated in the script.
var users = new GlideRecord('sys_user');
users.addEncodedQuery('sys_created_onRELATIVEGE@hour@ago@4");
users.query();
if (!users.hasNext()){
var gr = new GlideRecord('incident');
gr.initialize();
gr.short_description = 'Certificate renewal required';
gr.assignment_group = '5e8550e90f6e3900f6e783fc22050ef3'; //Sys_id of x workgroup
gr.description = //current will not work for this scheduled job, you'll need to use data from one of the glide records
gr.cmdb_ci = 'Certificate Services (Corporate Internal)'); //I don't know whether setDisplayValue will do the same
gr.insert();
}