SHARE
TWEET

Untitled

a guest Jun 19th, 2017 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var payCount = 0;
  2. var propertyUser = gs.getProperty('non_payment_users');
  3. for(var i = 0; i < propertyUser.length; i++) {
  4.     propertyUser[i] = propertyUser[i];
  5. }
  6. //getting all users that are active and not locked out
  7. var userRec = new GlideRecord('sys_user');
  8. userRec.addQuery('active', 'true');
  9. userRec.addQuery('locked_out', 'false');
  10. userRec.query();
  11.  
  12. //going through each user
  13. while(userRec.next()) {
  14.     var userRole = new GlideAggregate('sys_user_has_role');
  15.     //counting the roles of the user
  16.     userRole.addAggregate('COUNT');
  17.     userRole.addQuery('user', userRec.sys_id);
  18.     userRole.query();
  19.    
  20.     if(userRole.next()) {
  21.         countRole = userRole.getAggregate('COUNT');
  22.         //if he/she has at least one role, check if it has only not paying roles
  23.         if(countRole > 0) {
  24.             if(propertyUser.length < 1) {
  25.                 payCount++;
  26.                 continue;
  27.             }
  28.             var allRoles = new GlideAggregate('sys_user_has_role');
  29.             allRoles.addAggregate('COUNT');
  30.             allRoles.addQuery('user', userRec.sys_id);
  31.             allRoles.groupBy('user');
  32.             var notPayQuery = allRoles.addQuery('role.name', 'NOT IN', propertyUser[0]);
  33.             for(i = 0; i < propertyUser.length; i++) {
  34.                 notPayQuery.addOrCondition('role.name', 'NOT IN', propertyUser[i]);
  35.             }
  36.             allRoles.query();
  37.            
  38.             var role = 0;
  39.             if(allRoles.next()) role = allRoles.getAggregate('COUNT');
  40.             if(role == 0) continue;
  41.            
  42.             payCount++;
  43.         }
  44.        
  45.     }
  46.    
  47. }
  48.                    
  49. var resultRec = new GlideRecord('u_license');
  50.         resultRec.initiliaze();
  51.         resultRec.u_number = payCount;
  52.         resultRec.u_datetime = gs.nowDateTime();
  53.         resultRec.insert();
RAW Paste Data
Want to get better at JavaScript?
Learn to code JavaScript in 2017
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top