How to identify if a table structure is Table Per Hierarchy, Table Per Class, or Table Per Partition

SB87
Tera Expert

Is there an easy way to identify whether a table structure is formed using Table Per Hierarchy, Table Per Class, or Table Per Partition via the UI in ServiceNow? e.g. is there an indicator of some sort on Table & Columns that can be used?

 

The reason for my question is that I am trying to identify what Child tables store a separate set of values compared to its Parent table that it is extending. For example, when viewing the field values for an [incident_task] record, it doesn't appear to have the same values for the fields in the parent table, [task] with the same sys_id. I presume this is because [incident_task] is not Table Per Class(TPC). Is this correct?

1 ACCEPTED SOLUTION

Bert_c1
Kilo Patron

Hi,

 

query sys_db_object and include 'Extension model' in the list view.

 

incident_task is a child table of task, and that table's Extenstion model is TPH.

View solution in original post

4 REPLIES 4

Bert_c1
Kilo Patron

Hi,

 

query sys_db_object and include 'Extension model' in the list view.

 

incident_task is a child table of task, and that table's Extenstion model is TPH.

New Developer_S
Giga Sage

@SB87 

 

You can try to commit xplore developer tool kit which is available in service now share . With this you can see the table hierarchy like below.

 

NewDeveloper_S_0-1681448371713.png

 

Bert_c1
Kilo Patron

And here is a simple script to get the extension model.  Please note, extension_model is empty for child tables of task, they inherit the extension_model of the parent.

 

var tableToCheck = "tsp2_project";

getTableHierarchy(tableToCheck);

function getTableHierarchy(table) {

	// Get the table's hierarchy
	var tl = new TableUtils(table);
	var tableHierarchy = tl.getHierarchy();
//	the above returns an object that matches the implemented logic here
	gs.print(table + ",s hierarcy is " + tableHierarchy);
	
	// get the table's parents
	var parentTables = getParents(table);
	gs.print("The " + table + "'s parent hierarchy is " + parentTables + ".");
}

function getParents(table) {
	var tableList = [];
	tableList.push(table);
//	gs.print("getHierarchy: starting with " + tableList[0] + ".");

	var tableName = getParent(table);
	while (tableName != "") {
		tableList.push(tableName);
		tableName = getParent(tableName);
	}
	return tableList;
}

function getParent(table) {
	var tr = new GlideRecord('sys_db_object');
	tr.addQuery('name', table);
	tr.query();
//	gs.print("getParent: found " + tr.getRowCount() + " records for " + table + ".");
	if (tr.next()) {
		// want the table_name value here
		var tableSysId = tr.super_class;
		var ptr = new GlideRecord('sys_db_object');
		ptr.addQuery('sys_id', tableSysId);
		ptr.query();
		if (ptr.next()) {
			gs.print("Table: " + ptr.name + "'s extention moded = " + ptr.extension_model)
			return ptr.name;
		}
		else {
			gs.print("Parent table: " + tr.name + "'s extention moded = " + tr.extension_model)
			return tr.super_class;
		}
	}
	else
		return "";
}

Output:

*** Script: tsp2_project,s hierarcy is [tsp2_project, pm_project, planned_task, task]
*** Script: Table: pm_project's extention moded = 
*** Script: Table: planned_task's extention moded = 
*** Script: Table: task's extention moded = hierarchy
*** Script: Parent table: task's extention moded = hierarchy
*** Script: The tsp2_project's parent hierarchy is tsp2_project,pm_project,planned_task,task.

You will see the parent table's extension model at the end. Here's the same script for a table in the cmdb hierarchy, that used TPP

*** Script: cmdb_ci_service_business,s hierarcy is [cmdb_ci_service_business, cmdb_ci_service, cmdb_ci, cmdb]
*** Script: Table: cmdb_ci_service's extention moded = 
*** Script: Table: cmdb_ci's extention moded = 
*** Script: Table: cmdb's extention moded = partition
*** Script: Parent table: cmdb's extention moded = partition
*** Script: The cmdb_ci_service_business's parent hierarchy is cmdb_ci_service_business,cmdb_ci_service,cmdb_ci,cmdb.

 

and here's the output for a TPC hiearchy:

*** Script: activitydef_scriptfile,s hierarcy is [activitydef_scriptfile, sys_metadata]
*** Script: Table: sys_metadata's extention moded = 
*** Script: Parent table: sys_metadata's extention moded = 
*** Script: The activitydef_scriptfile's parent hierarchy is activitydef_scriptfile,sys_metadata.

extension_model is empty for each.