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

Thank you so much for the code Wilson , am i doing it correct ?

 

find_real_file.png

 

 

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()){

}

so i am trying to create and incident and assign it to my group if no insert or update is made with in last 4 hrs on sys_user table , please let me know if  i need to change any thing in the script

find_real_file.png

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