Create a Custom Related List in ServiceNow

Create a Custom Related List

There are a few ways to create a custom-related list

But first of all, let's clarify what related lists are god damnit!

Related lists in SN are these:


Related list: Defined related lists provide a list of any records you want at the bottom of the form.

For example, a simply defined related list that lists other rooms on the same floor may be placed on the Room form. This helps you quickly navigate between them. 

For more explanation & other examples have a look at this article.

Key takeaway:

This functionality depends on reference fields or many-to-many table relationships. If two tables are related via the system dictionary, one can appear as a related list on the other.

Best practice:

Before creating a related list or relationship, verify that there is not an existing relationship record that already provides the needed information. 

First method

Steps

  • Navigate > System Definition -- Relationships
  • Click New
  • Specify the relationship record fields
  • Click Submit

Applies to table: on which table you want to see the related list

Queries from table: from which table you want to show the data

current: queries from table 

parent: applies to table

Script:

(function refineQuery(current, parent) {

    // Add your code here, such as current.addQuery(field, value);
    current.addActiveQuery();
    current.addQuery('opened_by', requested_by);
    current.orderBy('number');

})(current, parent);

Navigate > Change requests

Add the related list to the change form via the context menu > Configure > Related List:


In the change form of any change request you should now see the Incident by Requester Related List: 


Note

This method assumes that there is already a relationship between the two tables (applies to table & queries from table).

Second method

Now, imagine that you don't have a relationship between the tables that you'd like to have a related list. 

For instance, you want to populate a related list on a custom table (let's call it - Credit Bucket) that queries the task time worked table.

What to do then?

Easy.

Create a reference field on the task time worked table and refer it to the custom table:


Congrats!

You have just created a relationship between those two tables.

On the custom table, you can now populate the related list via the context menu > Configure > Related List:


How cool is that?!

Note:

Via this route, you don't have much control over which data to query specifically like with the first method.

NOTE:

The same principles apply to custom-scoped apps!

Thanks for reading and till next time!


Comments

Popular Posts