How to fix it
- Navigate to
System Definition > Tablesand open your target table to verify all field references in your encoded query exist on this specific table. - Copy your encoded query into a text editor and search for
javascript:to identify any dynamic functions that need replacement. - Replace date functions with static values. For example, change
javascript:gs.beginningOfLastMonth()to2024-01-01or calculate the date value in your script first. - For user-relative functions, replace
javascript:gs.getUserID()with the actual user sys_id or calculate it separately in your script usinggs.getUserID(). - Open
System Logs > System Log > Alland add debug logging to your script:gs.log('Query: ' + encodedQuery, 'DEBUG'); - Test your corrected encoded query in a background script first. Go to
System Definition > Scripts - Backgroundand run a simple query to verify results. - For complex OR conditions, wrap them in parentheses manually. Change
field1=value1^ORfield2=value2^field3=value3to(field1=value1^ORfield2=value2)^field3=value3if needed. - Check if your business rule runs as
systemuser by examining theAdvancedtab. If so, user-based queries will behave differently than in the UI. - Use
gs.log(gr.getEncodedQuery(), 'DEBUG')after building your GlideRecord to see the final resolved query and compare it with your original. - For date-sensitive queries, calculate the date values in your script before building the query:
var startDate = gs.beginningOfLastMonth(); gr.addQuery('created', '>=', startDate);
Always test encoded queries in Scripts - Background before using them in business rules. Copy the exact query string and log the record count to verify it matches your expectations.