How to fix it
- First, verify the user context by adding
gs.log('User: ' + gs.getUserName() + ', Admin: ' + gs.hasRole('admin'))before both your GlideAggregate and comparison queries. - Check System Logs > System Log > All to see if the user context differs between queries. If yes, force the same context using
gs.getSession().impersonate('username')before your aggregate. - Identify null value issues by running a GlideRecord query with
addNullQuery('your_groupby_field')to count records with empty groupBy fields. - If null values are the issue, either remove the groupBy clause or add
addNotNullQuery('your_groupby_field')to both queries for consistency. - For domain issues, check current domain with
gs.getSession().getCurrentDomainID()and set to global domain usinggs.getSession().setDomainID('global')before the aggregate if needed. - Debug query differences by logging both encoded queries: add
gs.log('Aggregate query: ' + ga.getEncodedQuery())andgs.log('Record query: ' + gr.getEncodedQuery()). - Copy the encoded query from your aggregate and paste it into the list view filter to verify the same records are returned visually.
- For table inheritance issues, check the
sys_class_namefield and addaddQuery('sys_class_name', 'table_name')to both queries if you need to restrict to specific table types.
Always test your fix by running both queries with identical encoded queries and user context, then verify the counts match before deploying the business rule.