Reference Qualifier for Table Name field

DrewW
Mega Sage
Mega Sage

So I have been looking for a way to filter a field that has the type of "Table Name" to only show tables that are an instance of CMDB and I'm not finding a way to do it.

I tried "nameINSTANCEOFcmdb" but that did not work.

Anyone have any thoughts on this?

1 ACCEPTED SOLUTION

The system does not show the fields on the form.  I'm/was hoping that I could find a way to do it.

Right now I'm using a reference field to sys_db_object then I used the Ref Qual of "nameINSTANCEOFcmdb".  Just not a fan of how it came out.

View solution in original post

16 REPLIES 16

Michael Fry1
Kilo Patron

Are you trying to filter it so when someone inserts a new CI there tables are limited to valid choices?

Something like that but not for creating CI's.  I need the user to select a table that is a child of cmdb_ci so that they can create a filter for the table they selected.  I was hoping to use a Table Name field but it appears that there is no easy way to get it to filter to a sub set of tables.

 

Aqib
Tera Contributor

You can write a script include to do this, the tableChoicesScript dictionary attribute allows you to write a reference qualifier for the 'table_name' field type.

https://docs.servicenow.com/bundle/paris-platform-administration/page/administer/reference-pages/concept/c_DictionaryAttributes.html

Exactly what I needed.  I didn't even know that feature existed.  Thanks!

(EDIT: Version-neutral link to the doc referenced above: https://docs.servicenow.com/csh?topicname=c_DictionaryAttributes.html&version=latest)

 

And for anyone looking for this solution in the future - in a scoped app you can create a script include for this exact purpose that looks like this:

var CmdbTables = Class.create();
CmdbTables.prototype = {
    initialize: function() {
    },
    process: function() {
        var table = new GlideTableHierarchy('cmdb_ci');
        var cmdbTables = table.getAllExtensions();
        return cmdbTables;
    },
    type: 'CmdbTables'
};

Then just add this attribute to your Table Name type field:

tableChoicesScript=CmdbTables

 

If you want to do this in Global, I believe you'll need to use the out-of-box TableUtils script include. Your process function should look something like this:

var table = new TableUtils("cmdb_ci");
var cmdbTables = table.getAllExtensions();
var cmdbTablesArr = j2js(cmdbTables);
return cmdbTablesArr;

 

Aqib
Tera Contributor

That's a great explanation 🙂