Skip to main content

Filters, Encoded Queries, and Breadcrumbs: A ServiceNow Fairy Tale

Jonathan Jacob

Once upon a time, in the Brothers Grimm fairy tale "Hansel and Gretel," two children dropped breadcrumbs along their forest path to find their way home. While their breadcrumbs were eaten by birds (spoiler alert!), this simple concept of leaving a trail to navigate back through complex terrain has become a cornerstone of modern web interfaces. Today's digital breadcrumbs help users understand where they are and how they got there, transforming from fairy tale navigation aid to essential UX element.

In the enchanted forest of ServiceNow, filters and breadcrumbs serve a similar magical purpose—they're fundamental building blocks that power everything from lists and reports to templates, flows, and notifications. In this data-driven kingdom, filter conditions enable us to intelligently leverage attributes from across the platform, helping us navigate through complex data relationships just like breadcrumbs guide travelers through dark woods.

The Foundation: Encoded Query Syntax - Our Magic Spell

At the heart of ServiceNow's filtering capabilities lies the encoded query syntax—our magic spell for data manipulation. This powerful incantation can be cast in multiple contexts, from URLs to GlideRecords, making it an essential tool for any ServiceNow wizard.

applyEncodedQuery: The Enchanted Configuration

One of my favorite spells when conjuring ServiceNow functionality is the applyEncodedQuery method:

// Once upon a time, in an enchanted forest...
var forestRecord = new GlideRecord('enchanted_forest');
forestRecord.applyEncodedQuery('creatures=giants^realm.name=Fairyland^magical_protection=true');

// Our brave adventurer seeks the golden castle
var questLog = new GlideRecord('hero_quest');
questLog.applyEncodedQuery('destination=golden_castle^companions=breadcrumb_trail^status=active');

This magical example demonstrates how applyEncodedQuery can set values on records directly, much like casting a spell to transform the very nature of our data. This approach is invaluable for configuration purposes—it allows the wise village elders (application owners) to modify quest parameters without exposing them to the arcane code beneath, creating a cleaner separation between the magic and its manifestation.

GlideFilter: The Wise Oracle's Clean Decisions

GlideFilter often provides a much cleaner alternative to messy if conditions scattered throughout our ServiceNow kingdom, acting like a wise oracle that makes clear decisions. The magical benefits are substantial:

  • Conditions can be written on ancient scrolls (system properties) or carved into stone tablets (table configurations)
  • Our spells become more readable and easier for future wizards to maintain
  • Provides flexible handling of case sensitivity and null values—even works with incomplete incantations
  • Separates the wisdom of business rules from the mechanics of their implementation
// The oracle speaks in clear, encoded wisdom
var ancientWisdom = 'creature_type=helpful_fairy^location.realm=enchanted_forest^trust_level=high';
var oracle = new GlideFilter(magicalCondition, ancientWisdom);

// Ask the oracle: "Should we trust this forest creature?"
if (oracle.match(currentCreatureRecord)) {
    // The path is safe, continue the journey
    followTheTrail();
}

GlideQueryBreadcrumbs: The Hero of Our Digital Fairy Tale

Last but certainly not least is the least documented character in our story: GlideQueryBreadcrumbs—truly the hero of our digital fairy tale! While we can gather magical conditions from ancient scrolls (system properties), stone tablets (table definitions), or other mystical configuration areas, the real challenge lies in presenting these cryptic runes to the common folk through user-friendly interfaces like Service Portal, UI Pages, or message ravens (email notifications).

You could forge a custom parser to decode these magical runes, but such a tool would fail when encountering sys_ids (unique magical identifiers) or time-based enchantments (complex date formats). This is where our hero enters the story, ready to save the day.

// A cryptic message left by a previous traveler
var mysteriousMessage = 'helpful_guide=a8f98bb0eb32010045e1a5115206fe3a^quest_active=true^last_seen>2024-01-01';

// Our hero transforms the cryptic runes into readable wisdom
var heroicTranslator = new GlideQueryBreadcrumbs();
var readableStory = heroicTranslator.getReadableQuery('traveler_log', mysteriousMessage);
gs.info(readableStory);

// Output: "Helpful Guide is Fairy Godmother AND Quest Active is true AND Last Seen is after January 1, 2024"

This heroic utility transforms cryptic encoded queries into human-readable breadcrumb trails, automatically resolving magical references and formatting time-based enchantments appropriately for display. Unlike Hansel and Gretel's breadcrumbs, these digital ones don't get eaten by birds—they persist to guide future travelers through the same data forest.

The Moral of Our Story

These three magical components work together to create a robust, maintainable approach to data navigation in the ServiceNow kingdom, much like the best fairy tales teach us important lessons:

  1. Encoded queries provide the ancient language of data magic
  2. GlideFilter serves as our wise oracle for clean, configurable decision-making
  3. GlideQueryBreadcrumbs acts as our heroic translator, bridging cryptic technical runes with user-friendly breadcrumb trails

By mastering these enchanted tools, you can build more flexible, maintainable, and user-friendly ServiceNow applications that separate the magic from its configuration, while ensuring that no user ever gets lost in the dark forest of complex data relationships.

And unlike the original fairy tale, these breadcrumbs will never be eaten by birds—they'll always be there to guide you home, no matter how deep into the ServiceNow forest you venture.

And they all lived efficiently ever after... at least until the next release.