Get List of Tables who Extends Task Table using script (Not By Task Table SysID)

Chinmay Tawade1
Tera Guru

Hello Everyone,

 

I need to get the list of tables who extends Task Table.

Using Task Table sys id we can Glide on sys_db_object and get the list of those tables, using below script -

 
var sysDbObj = new GlideRecord('sys_db_object');
sysDbObj.addEncodedQuery('super_class=e44e166aa5300110c0a0e1db2cdc951f'); //Task Table Sys ID
sysDbObj.query();
while(sysDbObj.next()){
    gs.info('Table - '+sysDbObj.label);
}
 
Is there any alternative for this. Because I dont want to use the static task table sysid?
 
Thanks in advance!
 
1 ACCEPTED SOLUTION

smarti37
Kilo Sage

Hi Chinmay,

 

I already did that kind of script to get the full hierarchy of a table like 'task' :

https://www.linkedin.com/posts/s%C3%A9bastien-martin-ba580622_servicenow-tablehierarchy-activity-699...

View solution in original post

3 REPLIES 3

Mike_R
Kilo Patron
Kilo Patron

You can use this, but if someone else creates a table called 'Task' in the future it might mess up your script.

'super_class.name=Task'

 

If i were you I would stick with using the table's sys_id. This is never going to change, so in this case the hard coded sys_id is probably best

RaghavSh
Kilo Patron

The best practise is to create a system property in "sys_properties" table.

create a property with any name maybe "table_id"  and add the sys_id there in value field. After that make below changes to your code:

sysDbObj.addEncodedQuery('super_class='+gs.getProperty('table_id')); 


Raghav
MVP 2023

smarti37
Kilo Sage

Hi Chinmay,

 

I already did that kind of script to get the full hierarchy of a table like 'task' :

https://www.linkedin.com/posts/s%C3%A9bastien-martin-ba580622_servicenow-tablehierarchy-activity-699...