Script Include is not working

Prithvi Ramesh1
Mega Sage

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 :

 

PrithviRamesh1_0-1748631420729.png

 

Although there are a few records in the table, they are not displayed.

 

3 REPLIES 3

YaswanthKurre
Giga Guru

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.

 

still not working

YaswanthKurre
Giga Guru

Can you please attach the screenshots and put some logs in place.