- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Consider the "incident" table
Under sys_db_object table, ServiceNow lists 161 columns
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
It was the same issue as this one https://www.servicenow.com/community/itsm-forum/deleted-filed-still-shows-up-in-the-list-layout-and-...
This solved my problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
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.
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
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
Via configure table - 106
Via script
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader