The CreatorCon Call for Content is officially open! Get started here.

Kristy Merriam
Administrator
Administrator

 

As a ServiceNow developer, you’ve probably used related lists to connect data between tables. But what happens when the tables you want to link don’t have a direct relationship?

 

That’s where scripted relationships come in — and they’re one of the most flexible (yet underutilized) tools in your ServiceNow toolbox.

 

In a recent episode of Did You Know?, ServiceNow MVP Mohit Kaushik gives us a step-by-step walkthrough on how to use scripted relationships to bridge the gap between tables like Incidents and Requests — using a common reference field like caller_id.

 

Why Use a Scripted Relationship?

Let’s say you're on an Incident record, and you want to see all requests made by the same user. There’s no direct link between Incidents and Requests, but both reference the User table — which means you can build a custom relationship using a script.

 

How to Set It Up

In System Definition → Relationships:

  • Choose your parent table (e.g. incident)

  • Choose your related table (e.g. sc_request)

  • Use the Query with script field to link them:

    current.addQuery("requested_for", parent.caller_id);

Tips for Going Further

Kristy explains how you can filter even further:

  • Only show high-priority requests

  • Limit to matching assignment groups

  • Show only open records

This makes scripted relationships super dynamic and relevant to the user viewing the form.

 

⚠️ Performance Considerations

A powerful query can also be expensive. Each related list fires off its own database query, which can slow down performance — especially on high-traffic tables like incident.

 

Best Practices:

  • Use indexed fields in your query (like state, caller, etc.)

  • Always test your queries in a background script before going live

  • Keep your logic as lean as possible

Final Thoughts

Scripted relationships give you the flexibility to surface exactly the data you want, right where your users need it — without redesigning your data model. Just remember to use them wisely!

 

Big thanks to Mohit Kaushik for sharing his knowledge. If you’ve got a smart tip like this, we’d love to hear from you for a future episode.