Scheduled Script / Notifications

MStritt
Tera Guru

I currently have a scheduled script that looks at the last login time (logging into our Support Portal) of Contacts. If they haven't logged in >1 year (365 days), we are locking their account. We would like to send 3 notifications to these Contacts over a period of time leading up to the actually locking of their account.

 

First notification 30 days (335 days not logged in) in advance of action being taken.
Second notification 2 weeks (351 days not logged in) in advance of action being taken.

Third and final notification 1 day (364 days not logged in) in advance of action being taken.

 

What's the best way of creating these notifications? 

1 ACCEPTED SOLUTION

And it also didn't lock the 8 contacts yesterday?

Last thing we could try is to split the query and call the function twice. Again, make sure to replace the javascript colon. 

function sendReminder(days, event) {

    var query = "locked_out=false^account!=58ba9ccb4fddb640873b69d18110c744^last_login_timeRELATIVELT@dayofweek@ago@" + days + "^last_login_timeRELATIVEGT@dayofweek@ago@" + Number(days + 1);

    var contactGR = new GlideRecord("customer_contact");
    contactGR.addEncodedQuery(query);
    contactGR.query();

    while (contactGR.next()) {
        gs.eventQueue(event, contactGR, contactGR.getUniqueValue());
    }

}


function lockAccount(query) {

    var contactGR = new GlideRecord("customer_contact");
    contactGR.addEncodedQuery(query);
    contactGR.query();

    while (contactGR.next()) {
        contactGR.setValue("locked_out", true);
        contactGR.update();
    }
}

// Send reminders
sendReminder(335, "lock_out_reminder.30days");
sendReminder(351, "lock_out_reminder.14days");
sendReminder(364, "lock_out_reminder.1day");

// Lock accounts
lockAccount("locked_out=false^account!=58ba9ccb4fddb640873b69d18110c744^last_login_time<javascript&colon;gs.beginningOfOneYearAgo()");

lockAccount("locked_out=false^last_login_timeISEMPTY^sys_created_on<javascript&colon;gs.beginningOfOneYearAgo()^account!=58ba9ccb4fddb640873b69d18110c744")

 

View solution in original post

20 REPLIES 20

Harish KM
Kilo Patron
Kilo Patron

Hi @MStritt You can also use Flow designer to run daily for this requirement by reducing scripting. and use wait for duration to tirgger notification by passing the days using relative duration

Here is a example on how to use

https://www.servicenow.com/community/developer-forum/remove-user-group-roles-if-not-logged-in-last-3...

Regards
Harish