GregLusk
Tera Expert

One of the first suggestions to increase performance for a user is to reduce the number of rows per page that the user displays.   However, there are legitimate use cases that require a large number of rows to be displayed at once.   How can we allow as much flexibility for our users while still paying attention to performance issues?   The solution below allows administrators to set a maximum default rows system property that is used to reset the maximum rows count for users when their session has ended, instead of keeping the user's last setting. It can easily be adapted to set other user preferences on logout.   Import set attached.

 

  1. Create 3 new System Properties in the sys_properties table:
    1. lll.max.row.count
      • Name: lll.max.row.count.
      • Description: Sets the maximum number of the value for maxrows on the users preference record before reseting it to lll.reset.count at logout.
      • Type: integer.
      • Value: User configurable integer.
    2. lll.reset.count
      • Name: lll.reset.count.
      • Description: The value to set maxrows on the users preference record after the value is higher than lll.max.row.count.
      • Type: integer.
      • Value: User configurable integer, should be equal or less than lll.max.row.count.
    3. lll.excluded.users
      • Name: lll.excluded.users.
      • Description: Comma separated values of user IDs to exclude from List Limit Limiting.
      • Type: string.
      • Value: User configurable string of login ids to exclude from list limit limiting.
  2. Create a business rule with the following properties:
    • Name: List Limit Limiter
    • Table: User Session [sys_user_session]
    • Priority: 100
    • Active: true
    • Advanced: true
    • When: async
    • Order: 100
    • Update: true
    • Condition: current.invalidated.changes() && current.invalidated.hasValue() && current.name.hasValue()   &&   gs.getProperty('lll.excluded.users').indexOf(current.name) ==-1
    • Script:

(function executeRule(current, previous /*null when async*/) {

//This BR executes when a user session is ended.   It checks if the user is in the exclude

//list (lll.excluded.users) if it is not it compares the number of list rows the user has

//set to display against a maximum number (lll.max.row.count) if the list rows is greater

//than the maximum number the users list row number is set to lll.reset.count

        var LoggedOutUser = new GlideRecord('sys_user');

        if (LoggedOutUser.get('user_name',current.name)){

//setPreference and getPreference do not work for the rowcount preference:

//http://wiki.servicenow.com/index.php?title=User_Preference_Settings

                  var userPref = new GlideRecord('sys_user_preference');

                  userPref.addQuery('user',LoggedOutUser.sys_id);

                  userPref.addQuery('name','rowcount');

                  userPref.query();

                  while (userPref.next()){

                            if (parseInt(userPref.value) > parseInt(gs.getProperty('lll.max.row.count'))){

                                      userPref.value = gs.getProperty('lll.reset.count');

                                      userPref.update();

                            }

                  }

        }

})(current, previous);