Email body issue it contains duplicate details
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2024 05:00 AM
Hi, I am trying to delete the itil role from users who are no logged in system last 60 days. I am able to delete the itil role but I am having issue while sending email with itil users removal list in email body. The email boday contains duplicate users list.
Code:
It should be like below.
What is the issue in my code? kindly help on it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2024 10:35 AM
Hi @Sarah Bouil ,
for your 4th use case I have shared the updated code -
Kindly replace these five lines in your code.
//Replace These 5 lines from you code -
var emailBody = "The ITIL role has been removed from the following users due to inactivity:\n\n";
for (var i = 0; i < removedUsers.length; i++) {
var user = removedUsers[i];
emailBody += "Name: " + user.name + ", User ID: " + user.userId + ", Email: " + user.email + "\n";
}
//Replace the above with the below code
var daysAgo = gs.daysAgoStart(60); // Get date for 60 days ago
var emailBody = "The following users had their 'itil' role removed because they have not logged in for 60 days:\n\n";
// Query sys_user for users who haven't logged in for 60 days and have the 'itil' role
var userGr = new GlideRecord('sys_user');
userGr.addEncodedQuery('last_login_time<=' + daysAgo + '^roles=itil'); // Users who haven't logged in for 60 days and have 'itil' role
userGr.addActiveQuery(); // Only active users
userGr.query();
while (userGr.next()) {
emailBody += "Name: " + userGr.name.toString() + ", User ID: " + userGr.userId.toString() + ", Email: " + userGr.email.toString() + "\n";
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2024 03:01 PM
Hi Moin,
I have updated the code as you mentioned but the email body doesn't contains any data, it is showing as empty body with user details.
Code:
Could you please help me to fix the issue?