PLs advise the correction in the script

BanuMahalakshmi
Tera Contributor

Hi,

My requirement is - The scheduled job should run the check computer login date(check_in), if the checkin date exceeded 30 days from the current date, the system will trigger event for email notification.

if the checkin date exceeded 35 days, the system will create incident. if the check in  date exceeded 50days, the system Check for active incident that matches this criteria:

  • Incident CI = sys ID of Ci being checked in scheduled script
  • Incident short description starts with "PC has not login"
  • If active incident exists:
    • Update incident work note to add:   PC has been login for 50 days
var currentTime;
var days;
var checkin;
var gr = new GlideRecord('cmdb_ci_computer');
gr.addQuery('sys_updated_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^sys_updated_by=admin^sys_class_name=cmdb_ci_computer^attested=false');
gr.query();
if (gr.next()) {
    currentTime = gs.nowDateTime();
    checkin = gr.checked_in.getDisplayValue();
    diff = gs.dateDiff(checkin, currentTime, true) / 86400;
    days = Math.floor(diff);
    if (days == '30') {
        gs.eventQueue("PC Email Notification", gr.short_description, gr.checked_in);
    } else if (days == '35') {
        var incGr = new GlideRecord("incident");
        incGr.initialize();
        incGr.state = 1;
        incGr.urgency = 2;
        incGr.contact_type = 'self-service';
        incGr.caller_id = " System Administrator";
        incGr.short_description = " PC has not login";
        incGr.insert();


    }
 }
6 REPLIES 6

Using a single greater-than sign in the if loop will enable daily updates or record creation. This will particularly impact the same PC, resulting in 15 new INCs being generated from days 36 to 50.

Yeah, I caught that and updated it right after I posted.  They didn't specify when / how often the job will be run, but safer to assume it will be daily.