user group expiry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2023 02:38 AM
Email notification should be sent when group is expiring and prior(15,7,5,4.3,2days) to the expiry date, below code I have used in schedule job any suggestion on this code.
var gr = new GlideRecord("sys_user_group");
gr.addNotNullQuery('u_expiry');
gr.addQuery("active", "true");
gr.query();
while (gr.next()) {
var actdate = gr.getValue('u_expiry');
var act = actdate.toString();
var today = new GlideDateTime().getDate().toString();
if (today == act) {
gs.eventQueue("user_group_expiry", gr);
}
}
var vr = new GlideRecord('sys_user_group');
vr.addQuery("active", "true");
//var today = gs.nowDateTime();
var todays = new GlideDateTime().getDate().toString();
vr.addEncodedQuery( ('u_expiryRELATIVEGT@dayofweek@ahead@14^active=true') || ('u_expiryRELATIVEGT@dayofweek@ahead@6^active=true') || ('u_expiryRELATIVEGT@dayofweek@ahead@5^active=true') || ('u_expiryRELATIVEGT@dayofweek@ahead@4^active=true') || ('u_expiryRELATIVEGT@dayofweek@ahead@3^active=true') || ('u_expiryRELATIVEGT@dayofweek@ahead@2^active=true') || ('u_expiryRELATIVEGT@dayofweek@ahead@1^active=true'));
vr.query();
while (vr.next()) {
var total = gs.dateDiff(today, vr.getElement('u_expiry'), true);
var diff = Math.floor(total / 86400);
gs.log('Diff : ' + diff);
if ((diff == 15) || (diff == 7) || (diff == 6)|| (diff == 5) || (diff == 4)|| (diff == 3)|| (diff == 2) || (diff == 1)) {
// gs.log('diff found: ' + diff);
gs.eventQueue("user_group_expiry", vr);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2023 02:53 AM
In your first code just get the result of today == act in a variable and put it in a log to check whether it is giving correct result or not
Also update method as below
gs.eventQueue("user_group_expiry", gr,"","");
You can combine both of your code in one schedule if your recipients are same
you need to add condition in your encoded query and the if which you are using to check the days
Let me know if you need more help
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful based on the Impact
Thanks,
Manjusha Bangale