- 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-04-2024 11:41 AM
Hi Rene,
I've updated the conditions of the query. So, probably changes the code you sent??
locked_out=false^account!=58ba9ccb4fddb640873b69d18110c744^last_login_timeISEMPTY^ORlast_login_time<javascript:gs.beginningOfOneYearAgo()^sys_created_on<javascript:gs.beginningOfOneYearAgo()
This is what I currently have. I haven't updated the code yet, to reflect your inputs.
// Build the encoded query for customer_contact
var encodedQuery = "locked_out=false^account!=58ba9ccb4fddb640873b69d18110c744^last_login_timeISEMPTY^ORlast_login_time<javascript:gs.beginningOfOneYearAgo()^sys_created_on<javascript:gs.beginningOfOneYearAgo()";
// Query the customer_contact table based on the encoded query
var contactGR = new GlideRecord('customer_contact');
contactGR.addEncodedQuery(encodedQuery);
contactGR.query();
// Loop through the contacts and deactivate them
while (contactGR.next()) {
contactGR.locked_out = true;
contactGR.update();
}
Also, I assume where you have "reminder.30 days" will be the actual name of the Event/s I create?
lock_out_reminder.30days
lock_out_reminder.14days
lock_out_reminder.1day
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2024 12:53 PM
You just need to adjust the query like so. Yes, the event names need to be changed if you didn't name them the same as in my example.
function sendReminder(days, event) {
var query = "locked_out=false^account!=58ba9ccb4fddb640873b69d18110c744^sys_created_on<javascript:gs.beginningOfOneYearAgo()^last_login_timeRELATIVELT@dayofweek@ago@" + days + "^last_login_timeRELATIVEGT@dayofweek@ago@" + Number(days + 1) + "^ORlast_login_timeISEMPTY";
var contactGR = new GlideRecord("customer_contact");
contactGR.addEncodedQuery(query);
contactGR.query();
while (contactGR.next()) {
gs.eventQueue(event, contactGR, contactGR.getUniqueValue());
}
}
function lockAccount() {
var query = "locked_out=false^account!=58ba9ccb4fddb640873b69d18110c744^sys_created_on<javascript:gs.beginningOfOneYearAgo()^last_login_timeRELATIVELT@dayofweek@ago@365^ORlast_login_timeISEMPTY";
var contactGR = new GlideRecord("customer_contact");
contactGR.addEncodedQuery(query);
contactGR.query();
while (contactGR.next()) {
contactGR.setValue("locked_out", true);
contactGR.update();
}
}
// Send reminders
sendReminder(30, "reminder.30days");
sendReminder(14, "reminder.14days");
sendReminder(1, "reminder.1day");
// Lock accounts
lockAccount();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2024 08:04 PM
Scheduled job ran about 2 hours ago, but it didn't send out any notifications. Here is my script, one of the events I created (the other 2 are identical except for the event name), and screenshot of the corresponding notification.
function sendReminder(days, event) {
var query = "locked_out=false^account!=58ba9ccb4fddb640873b69d18110c744^sys_created_on<javascript:gs.beginningOfOneYearAgo()^last_login_timeRELATIVELT@dayofweek@ago@" + days + "^last_login_timeRELATIVEGT@dayofweek@ago@" + Number(days + 1) + "^ORlast_login_timeISEMPTY";
var contactGR = new GlideRecord("customer_contact");
contactGR.addEncodedQuery(query);
contactGR.query();
while (contactGR.next()) {
gs.eventQueue(event, contactGR, contactGR.getUniqueValue());
}
}
function lockAccount() {
var query = "locked_out=false^account!=58ba9ccb4fddb640873b69d18110c744^sys_created_on<javascript:gs.beginningOfOneYearAgo()^last_login_timeRELATIVELT@dayofweek@ago@365^ORlast_login_timeISEMPTY";
var contactGR = new GlideRecord("customer_contact");
contactGR.addEncodedQuery(query);
contactGR.query();
while (contactGR.next()) {
contactGR.setValue("locked_out", true);
contactGR.update();
}
}
// Send reminders
sendReminder(30, "lock_out_reminder.30days");
sendReminder(14, "lock_out_reminder.14days");
sendReminder(1, "lock_out_reminder.1day");
// Lock accounts
lockAccount();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2024 08:47 AM
Also, script doesn't appear to be marking the 29 contacts as locked, that match the condition. I'm showing 1 contact where their last login time is empty (and created more than 1 year ago), 6 where last login time is 01/04/23, and 22 where last login time is 01/05/23 up to the current time today.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2024 11:10 AM - edited ‎01-05-2024 12:20 PM
I just realized that when posting the code here the "javascript(colon)" gets replaced by "javascript:" which you have probably copied over and invalidates the query. Make sure you replace it with a colon. Also, I've mixed something up with the days passed to the function. See corrected code below.
I have tested this on my PDI, but I recommend that you also validate that the encoded queries return the correct records in the list view. Just replace "YOURINSTANCE" with the name of your instance and also replace the ":" here.
Not logged in for 335 days:
function sendReminder(days, event) {
var query = "locked_out=false^account!=58ba9ccb4fddb640873b69d18110c744^sys_created_on<javascript:gs.beginningOfOneYearAgo()^last_login_timeRELATIVELT@dayofweek@ago@" + days + "^last_login_timeRELATIVEGT@dayofweek@ago@" + Number(days + 1) + "^ORlast_login_timeISEMPTY";
var contactGR = new GlideRecord("customer_contact");
contactGR.addEncodedQuery(query);
contactGR.query();
while (contactGR.next()) {
gs.eventQueue(event, contactGR, contactGR.getUniqueValue());
}
}
function lockAccount() {
var query = "locked_out=false^account!=58ba9ccb4fddb640873b69d18110c744^sys_created_on<javascript:gs.beginningOfOneYearAgo()^last_login_timeRELATIVELT@dayofweek@ago@365^ORlast_login_timeISEMPTY";
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();