getFields() on GlideRecord shows more columns than sys_db_object columns

Nisar3
Giga Guru

Consider the "incident" table

 

Under sys_db_object table, ServiceNow lists 161 columns

Nisar3_0-1756471509297.png

You can see that it shows columns from parent as well as incident table

 

But if do the following:

var body = {};
var recObj = new GlideRecord("incident");
if (recObj.get("<some sys_id goes here>") {
	var data = recObj.getFields();
	for (var i = 0; i < data.size(); i++) {
		var field = data.get(i);
		var name = field.getName();
		var value = field.getValue();
		body[name] = value;
	}
	body.sys_id = recObj.getUniqueValue();
}
gs.print(Object.keys(body).length);

If gives me a count of 182 and I see certain columns with names that I don't remember creating.

 

Why is there such a huge difference? I'm sensing getFields() is also pulling columns that might have been deleted from the table but is there a way to confirm this?

 

Any suggestions?

1 ACCEPTED SOLUTION
9 REPLIES 9

kaushal_snow
Mega Sage

Hi @Nisar3 ,

 

1. The incident table extends from the task table, so getFields() returns fields from both incident and its parent tables, not just those directly defined on incident. In contrast, sys_dictionary (used by the Tables & Columns UI) shows only fields explicitly defined on that table.


2. GlideRecord internal object model can include synthetic elements or GlideElement level constructs not necessarily real database columns. This might account for fields you don’t recognize as having created.

 

To Confirm Which Fields Are Actually in the Database:

 

Compare with sys_dictionary entries across inheritance hierarchy, To get all true database columns, including those inherited, you can query sys_dictionary for both the table and its parent(s), like:

 

 

name=incident^ORname=task

 

 

This ensures you only include real fields defined in the dictionary.

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/

Ankur Bawiskar
Tera Patron
Tera Patron

@Nisar3 

getFields() will return incident + task fields.

to confirm if any field is deleted, check "Deleted Records" left nav module and check

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Nisar3 

it gave me correct count

Via Script - 106 (it excluded the 2 collection type fields as that's expected as those are not actual fields on table), 1 each for task and incident

Via dictionary - 108

AnkurBawiskar_0-1756476999276.png

Via configure table - 106

AnkurBawiskar_2-1756477092130.png

 

Via script

AnkurBawiskar_1-1756477010166.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Nisar3 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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