Advanced Topics
Last updated
Last updated
Customizing OneSearch isn’t hard, but it helps to understand what’s going on. Basically, OneSearch is the middleman between your end user and the Searcher/Sections that you define. When the user begins to type in the search field, OneSearch delivers the search term & context (and any additional fields you configure) back to the server. Once received, your searcher Section processes that data, building an array of object results. Then, the array of objects is sent back to the user’s interface where it appears as a list of helpful results, formatted according to the specified template. This all happens very quickly, several times before the user is even finished typing! Check out this diagram:
In short, OneSearch delivers your user’s search term and any other fields/variables you need, crunches that data according to your specifications, and then displays exactly the data you specify back to your user – in the exact format you specify. Instantaneously.
You can do a lot in OneSearch with point-and-click configuration. However, if you have JavaScript chops, you can do even more - leveraging any capability of the ServiceNow platform, from simple queries to advanced calculations to web service calls leveraging external sources. Here are a few thoughts about what is possible:
In server-side script, you have access to the gs.user object, so you can provide results based upon the logged-in user’s roles, groups, etc.
Even with simple queries, you can add specifications to target the data. Think about your users and the context of the search. Maybe you should only return KB results of ‘category=hr’ on an HR Case, but only ‘category=facilities’ on a Facilities Request?
OneSearch allows you to pull back other fields from the form/item/page to best calculate search results, even before the record is saved – stuff like category, location, CI, etc - you can get very contextual with your results.
Want to interleave results from multiple sources? You can query multiple tables/sources within a single section and interleave them within your script.
You can use log statements like gs.info – very useful for troubleshooting your newest search creation!