- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2024 01:06 PM - edited ‎01-03-2024 01:10 PM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2024 03:09 AM
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:gs.beginningOfOneYearAgo()");
lockAccount("locked_out=false^last_login_timeISEMPTY^sys_created_on<javascript:gs.beginningOfOneYearAgo()^account!=58ba9ccb4fddb640873b69d18110c744")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2024 05:34 AM - edited ‎01-10-2024 05:45 AM
I don't see why it should not work for the second condition... Can you check if you see the 103 + 6 records in the list when visiting this link? Make sure to replace yourinstance with the name of your instance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2024 06:48 AM
Hi Rene,
It won't show me the 103 from yesterday, since I ran the script after and it successfully locked those Accounts. It just didn't lock the 6 Contacts where Last login time was Empty and was created before One year ago.
I ran the query from your most recent link, and it's showing me a total of 32 (which is correct). 24 of those are new Contacts that are showing Last login time is before One year ago (up to today's date/time). And it's showing me a total of 8 (6 from yesterday and 2 more added since) of Contacts where Last login time is Empty and was created before One year ago.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2024 03:09 AM
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:gs.beginningOfOneYearAgo()");
lockAccount("locked_out=false^last_login_timeISEMPTY^sys_created_on<javascript:gs.beginningOfOneYearAgo()^account!=58ba9ccb4fddb640873b69d18110c744")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2024 08:18 AM
>> And it also didn't lock the 8 contacts yesterday?
Correct.
Today, I'm showing 29 Contacts where Last login time is before One year ago (up to today's date/time). And, 19 Contacts where Last login time is Empty and was created before One year ago. A total of 48.
I updated the code and executed the script. It successfully locked all 48 Contacts, and sent the reminder emails. So, looks like everything is working successfully! I really appreciate all the time you spent on this issue. Helped me out tremendously.
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2024 12:08 PM
Hi Mike, glad that I could help!
It would be great if you could mark my reply as correct/helpful so that the question can be marked as solved.
Best regards,
Rene