How to get the extended table names in a script?

gokulraj
Giga Expert

Hi Team,

I want to get the all extended table names by passing a table name.

Example:"Incident,Problem,Change Request "these tables Extends the table name called Task.If I pass the Task Table I have to Populate those three tables "I...

Regards,

Gokulkraj

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Gokulraj,

Following is the script:

var tableArray = [];

var tableName = 'task';

var gr = new GlideRecord('sys_db_object');

gr.addEncodedQuery('super_class.name='+ tableName);

gr.query();

while(gr.next()){

tableArray.push(gr.name.toString());

}

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

gokulraj
Giga Expert

Hi,

I have tried that but my o/p is like below;

*** Script: the table names are1
*** Script: the table names are2
*** Script: the table names are3
*** Script: the table names are4
*** Script: the table names are5
*** Script: the table names are6
*** Script: the table names are7
*** Script: the table names are8
*** Script: the table names are9
*** Script: the table names are10
*** Script: the table names are11
*** Script: the table names are12
*** Script: the table names are13
*** Script: the table names are14
*** Script: the table names are15
*** Script: the table names are16
*** Script: the table names are17
*** Script: the table names are18
*** Script: the table names are19
*** Script: the table names are20
*** Script: the table names are21
*** Script: the table names are22
*** Script: the table names are23
*** Script: the table names are24
*** Script: the table names are25
*** Script: the table names are26
*** Script: the table names are27
*** Script: the table names are28
*** Script: the table names are29

My script:
var tableArray = [];
var ext='';
var tableName = 'task';

var gr = new GlideRecord('sys_db_object');
gr.addEncodedQuery('super_class.name='+ tableName);
gr.query();
while(gr.next()){
ext = tableArray.push(gr.name.toString());
gs.print('the table names are'+ext);
}


Correct you script

 

var tableArray = [];
var ext='';
var tableName = 'task';

var gr = new GlideRecord('sys_db_object');
gr.addEncodedQuery('super_class.name='+ tableName);
gr.query();
while(gr.next()){
tableArray.push(gr.name.toString());
gs.print('the table names are'+gr.name.toString());
}

Please mark this response as correct or helpful if it assisted you with your question.

Pranay Tiwari
Kilo Guru

Hi Gokulraj,

 

You need to write an Script Include for it,follow below code then call it in Advance reference qualifier.

It work definitely.

 

var getExTable = Class.create();
getExTable.prototype = {
    initialize: function() {
    },
getEx: function() {
	var a=[];
	var gr=new GlideRecord("sys_db_object");
	gr.addQuery("super_class",current.u_name_table);
	gr.query();
	
	while(gr.next()){
		a.push(gr.sys_id.toString());
	}
	return "sys_idIN"+a;

    },

    type: 'getExTable'
};

 

getEXTable is my Script Include and getEx is function.

 

you need to call it in Reference qualifier By write javascript: new getExTable().getEx();  in advance Reference qualifier .

 

Mark correct or helpful if it helps you.

 

Warm Regards,

Pranay Tiwari

| www.DxSherpa.com |