How to: Reference qualifier on dictionary entry
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.
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);
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.
https://www.servicenow.com/community/now-platform-articles/how-to-reference-qualifier-on-dictionary-entry/ta-p/2313798