
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 07-26-2022 05:08 PM
This article is the result of the following question I posted a few weeks ago: https://community.servicenow.com/community?id=community_question&sys_id=a17ef59edbf09910ca6fdb85ca96...
Scenario
Imagine you have your custom table My Table which includes the following attributes among of others:
- Table referencing sys_db_object
- Field referencing sys_dictionary
Maybe you are wondering why someone needed that. Well, on my case, it was creating a configuration table for a custom API engine... there are some situations whether it would make sense.
Going back to the use case. The idea is to apply a reference qualifier to the field Field so it filters by the fields belonging to the selected table in the Table field.
The first idea would be just apply something like:
javascript:"active=true^name="+current.u_table.name.getValue()
It would work as long as the table does not extend any other table, in such scenario, the above filter does not gather the fields belonging to the parent table.
Solution
Depending whether your custom table is created in the global scope or in a scoped application, the filter may differ a little bit.
- Global scope
javascript: "active=true^nameIN" + Array(new TableUtils(current.u_table.name.getValue()).getHierarchy()).toString().replace("[", "").replace("]", "");
Obviously, you need to replace u_table by the name of your custom Table field.
The following script is equivalent:
javascript: gs.include("j2js"); var tbl = new TableUtils(current.u_table.name.getValue()).getHierarchy(); "active=true^nameIN" + j2js(tbl);
- Scoped application
Surprisingly, same goal is more simple in a scoped application as you don't need to deal with JAVA objects.
javascript: "active=true^nameIN" + new GlideTableHierarchy(current.u_table.name.getValue());
‼️ Disclaimer: Please, always test the script in non-productive environments before running in a productive instance. Script was reviewed at the creation time but may break/get unexpected results due to instance versioning and SN API upgrades.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Update for scoped application:
javascript: "active=true^nameIN" + new GlideTableHierarchy(current.u_table.name.toString()).getTables().toString();