Script Include is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2025 11:58 AM
Below is the client callable script include:
(function getEmail(emailDomain) {
// Step 1: Get users who updated more than one ACL
var acl = new GlideAggregate('sys_security_acl');
acl.addAggregate('COUNT');
acl.groupBy('sys_updated_by');
acl.query();
var users = [];
while (acl.next()) {
var count = acl.getAggregate('COUNT');
if (count > 1 || count == 1) {
users.push(acl.sys_updated_by.toString());
}
}
//gs.print(users);
// Step 2: Filter users with email ending in '@avatu.in'
var user = new GlideRecord('sys_user');
user.addQuery('user_name', 'IN', users.join(','));
user.addQuery('email', 'ENDSWITH', emailDomain);
user.query();
var filteredUsers = [];
while (user.next()) {
filteredUsers.push(user.user_name.toString());
}
return filteredUsers;
});
In the Report below is the screenshot as I had called :
Although there are a few records in the table, they are not displayed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2025 12:13 PM
Hi Prithvi,
Please refer Script include documentation in developer portal:
Here is your correct function in script include :
function getEmail(emailDomain) {
// Step 1: Get users who updated MORE THAN ONE ACL (fixed condition)
var acl = new GlideAggregate('sys_security_acl');
acl.addAggregate('COUNT');
acl.groupBy('sys_updated_by');
acl.query();
var users = [];
while (acl.next()) {
var count = acl.getAggregate('COUNT');
// Only add users who updated >1 ACLs (removed redundant condition)
if (count > 1) {
users.push(acl.sys_updated_by.toString());
}
}
// Step 2: Filter users with email ending in specified domain
var user = new GlideRecord('sys_user');
user.addQuery('user_name', 'IN', users.join(','));
user.addQuery('email', 'ENDSWITH', emailDomain);
user.query();
var filteredUsers = [];
while (user.next()) {
filteredUsers.push(user.user_name.toString());
}
return filteredUsers;
}
call from report:
javascript: new getUser().getEmail("@avatu.in"); //getUser is the name of script include, if it is in different scopes - use api name instead of script include name.
Please mark this correct, if this resolves your issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2025 12:16 PM
still not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2025 12:18 PM
Can you please attach the screenshots and put some logs in place.