Introduction: The Power of the Related List
Related lists in ServiceNow are not just list fields—they are windows into the intricacies of data relationships, revealing patterns and connections across different records.
In the platform’s ecosystem, where tables and their records can often weave complex webs, understanding how to efficiently showcase these connections directly on a record’s form view becomes pivotal.
One way to harness this potential is through the creation of a related list using relationships.
For instance, let’s illustrate the context: While browsing through an Incident record, wouldn’t it be beneficial to quickly show all active tasks created by the user who requested this incident?
That’s where related lists shine. Without any laborious search or navigation, you’re presented with the information right there.
Let’s navigate this process step-by-step, diving deeper into server-side scripting and the relationship model akin to the “Incidents by Same Caller” feature.
There are a ton that are created out of box, but you can also create your own.
Creating a Related List Using Server-Side Relationships
- Setting Up the Relationship:
- Go to System Definition > Relationships.
- Click ‘New’ to start defining a new relationship.
- For our demonstration:
- Name: Incidents with Active Tasks by Same Requester
- Applies to: Incident (As we want this related list to appear in Incident records)
- Queries from: Task (From where the data will be fetched)
- Condition: Here is where our server-side script will reside.
- Server-Side Scripting for the Relationship:
current.addQuery('active', true); current.addQuery('requested_for', parent.requested_for);
The above script, when applied in the ‘Condition’ field, filters out tasks that are not only active but are also requested by the same user as the parent Incident record.
Let’s take a look at another Related List, this one is out of box called “Incidents By The Same Caller”.
- Integrating the Related List into the Form:
- Navigate to the Incident table.
- Open any record and move to the related list section at the bottom.
- Using the ‘Personalize Related List’ option (usually represented by a gear icon or similar), you can now add your newly created “Incidents with Active Tasks by Same Requester” related list.
After you’ve created your related list relationship, you can now add it to the form. Keep in mind, you can ONLY add a related list to a form where the “Applies to table” is set as the current table, so related lists are obviously table specific.
Recap and Common Mistakes to Avoid
- Ensuring Correct Relationships: Double-check that you’ve set the right tables in ‘Applies to’ and ‘Queries from’. Mixing these up can yield incorrect data or none at all.
- Server-Side Logic: Ensure that your scripting logic accurately captures the relationship you want to depict. The
parentvariable is pivotal here, representing the record you’re currently viewing.
- Permissioning: Just as before, permissions are pivotal. If users can’t view records from the child table, they won’t see anything in the related list—even if it’s correctly set up.
- Testing is Key: Always, always test your related list on various records to ensure it’s pulling the right data.
You’ll want to make sure that your queries are efficient and when you’re building these on large tables, you add more conditions to reduce the row count that is returned.
Related Lists and Performance in ServiceNow: Best Practices
Related lists in ServiceNow offer an incredible way to display interconnected records directly within a form. However, like all powerful tools, they must be wielded wisely. One primary concern is performance. ServiceNow, being a cloud-based platform, relies on efficient server requests to maintain its snappy user experience, and an improperly configured related list can slow things down.
The Pitfall of Large Queries
At its core, every related list is essentially running a query against the ServiceNow database. If this query is expansive and not optimized, it can consume considerable server resources, leading to longer load times for your form. For instance, a related list that pulls in all incidents from the past ten years will undoubtedly be slower than one that only showcases incidents from the past month.
Moreover, if multiple related lists on a single form run substantial queries, the cumulative load time can render a form sluggish, negatively impacting user experience.
Best Practices for Optimal Performance
- Limit Record Display: Use filters to restrict the number of records displayed in a related list. It’s rarely necessary to show thousands of records at once. Decide on a reasonable limit and stick to it.
- Optimize Conditions: Ensure that the condition or script used to generate the related list is optimized. Avoid nested loops and aim for straightforward conditions. The more specific the criteria, the faster your query will run.
- Use Indices: If a related list queries a specific field frequently, consider adding an index to that field in the table. Indices can significantly speed up database lookups.
- Lazy Loading: If possible, set up related lists to use “lazy loading,” which means they only load records when a user scrolls to that section or clicks on the related list tab, rather than loading immediately when the form opens.
- Evaluate Necessity: Before adding a related list, always ask: Is this information crucial for the user on this form? If the answer is ‘no’, consider alternative methods to provide that information, like a report or dashboard.
- Regular Audits: Periodically review the related lists on frequently-used forms. Over time, business needs change. What was crucial a year ago might not be relevant today. Removing unnecessary related lists can have a noticeable impact on form load times.
- Educate Stakeholders: Ensure that those requesting the creation of related lists understand the performance implications. They might reconsider their requirements if they know it could affect overall system speed.
- Test in Sub-Production: Before deploying a new related list in production, test it in a sub-production instance like Dev or Test. Monitor the performance and refine as necessary.
In the vast and interconnected world of ServiceNow records, related lists are gateways that offer insights directly where they’re needed. However, they should be added judiciously, keeping in mind the larger picture of system performance. An efficient ServiceNow instance strikes a balance between providing necessary insights and ensuring optimal performance. By adhering to the best practices outlined above, you can achieve both.
Your Related List queries can be expensive if you just let them run rampant, and these will negatively impact performance on the client.
To sum up, related lists using server-side relationships in ServiceNow offer a robust way to depict intricate data connections right where they’re most relevant. It’s a blend of art (understanding what users need to see) and science (the technical setup).
But with a careful approach and attention to detail, it becomes an invaluable tool in the ServiceNow developer’s toolkit.