Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

PrashantLearnIT
Tera Sage

There are two scripts (option 1 & 2) that can be used to get information about table relationships and all tables that extend the current table.

However, if you use ServiceNow GlideTableHierarchy API's getAllExtensions() methods in option 2 script, you can get the same information with fewer codes rather than the complex codes in option 1 script

Correction for the image:
Option 1 is
var parentName = 'sn_hr_core_case'; 
getExtendedChildedTableName(parentName);

function getExtendedChildedTableName(parentName) {
  var grDBObject = new GlideRecord('sys_db_object');
  grDBObject.addQuery('super_class.name', parentName);
  grDBObject.query();

  while (grDBObject.next()) {
    gs.print(grDBObject.name);
  }}

Output:
*** Script: sn_hr_core_case_workforce_admin
*** Script: sn_hr_core_case_talent_management
*** Script: sn_hr_core_case_payroll
*** Script: sn_hr_core_case_total_rewards
*** Script: sn_hr_core_case_operations
*** Script: sn_hr_core_case_corporate_communication
*** Script: sn_hr_core_case_benefits
*** Script: sn_hr_core_case_global_mobility
*** Script: sn_hr_core_case_compensation

Option 2 is
var table = new GlideTableHierarchy();
gs.info(table.getAllExtensions());

 

If my content helped you in anyway, please mark this content as BOOKMARK, SUBSCRIBE & HELPFUL

 

Best Regards,

Prashant Kumar (LearnIT)

 

YouTube Channel LearnIT: https://www.youtube.com/@learnitwithprashant

Blog LearnIT: https://medium.com/@LearnITbyPrashant

Prashant Kumar LinkedIn: https://www.linkedin.com/in/learnitbyprashant/

ServiceNow Community Prashant Kumar - https://www.servicenow.com/community/user/viewprofilepage/user-id/19635