Note: jvar_apply_paging is always true. It is set in the kb_find UI page directly, and kb_find_query is never included anywhere else.
This issue has been present since at least Aspen. It appears to have been introduced in 76ce5d6ddbedc1a1fe4830a539dee833fbb5ca35 from 2011-01-11, which added pagination to Knowledge search results.
Steps to Reproduce
- Log in to a ServiceNow instance.
- Enable Debug Text Search.
- Go to Knowledge.
- Conduct a general search.
There will be two query debug outputs, each from START Strategy Analysis to Total Time for Text Query.
This issue is caused by the fact that the com.glideapp.knowledge_section record tag executes the query, and the explicit kb.query(); below it as well, resulting in the query being run twice. The fix (and the workaround) is to edit the kb_find_query UI Macro and update the (last section of the) XML to look like this:
<j2:if test="$[jvar_apply_paging == 'true']">
<g2:com.glideapp.knowledge_section record="$[kb]" startRecord="$[sysparm_current_row - 1]"
endRecord="$[sysparm_current_row + sys_nav_count - 1]"/>
<j2:if test="$[jvar_apply_paging == 'false']">
// When pagination is enabled, the query will be executed in
// the knowledge_section above. When disabled, we need to run
// it here instead:
Related Problem: PRB587149