how to check if the records in a table is updated or not

RudhraKAM
Tera Guru

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 

1 ACCEPTED SOLUTION

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();
}

View solution in original post

13 REPLIES 13

Elijah Aromola
Mega Sage

You want to check every 4 hours or you want to check if there has been an insert/update in the last 4 hours? 

Sorry for the confusion its every 4 hours, the requirement is  we have ldap listener on and we need a monitor process where if it accidentally stops  we  need a solution so that it can create a incident for our group

How often should users be created/updated? You can write a query for any timeframe but you must know how far to look back. Last 8 hours, last 4 hours, last 30 minutes, etc. 

we are thinking about 4 hrs as of now