Send notification to a particular group about the output of schedule job
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-25-2022 11:05 AM
Hi Team,
I am executing the script through schedule job to remove the user from groups and roles.
I am getting a count of users through log statement (like how many users have been removed),so the same details that is the count,I want to send to a particular group as an email.How can I achieve that.
var count=0;
var inclist=[];
var us1=new GlideRecord('sys_user');
us1.addEncodedQuery('last_login_time<javascript:gs.beginningOfLast3Months()^last_login_timeISNOTEMPTY^active=true');
us1.query();
while (us1.next()) {
var memberRec = new GlideRecord('sys_user_grmember');
memberRec.addEncodedQuery('group!=62e0f859db4bc410b2537a76f396194b^ORgroup!=491c1e2fdb7e4010b2537a76f3961992');
memberRec.addQuery('user',us1.sys_id);
while (memberRec.next()) {
count++; // count number of users who is having role and didn't log-in from last 60 days
memberRec.deleteMultiple(); // remove roles from the role table
gs.log("Hello! User "+count+ " is removed from group" );
}
Thanks,
Karan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-25-2022 11:11 AM
Once you've finished looping through your query, you can generate an event, and initiate a notification based on that event.
1. Create an event in the Event Registry
2. In your script, after the while loop ends, add gs.eventQueue([event name],current,count) , or something along those lines.
3. Create a new notification triggered off of an event, and select the name of the event you just created. Set the recipient to the group that needs to receive the email. If you use the formatting I provide in step 2, I believe you should just need to use $ {event.parm1} to call that count value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-25-2022 11:40 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-26-2022 04:47 AM
If it's triggering multiple times, it's likely because it's still within one of your while loops. Can you share your code again, with the new line?