- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2020 12:10 AM
Hi All,
I am working on Application table(cmdb_ci_appl) how do I get only fields which are on form not all class fields.
Thanks.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2020 06:02 AM
Hi,
Check this, It may help you.
function onLoad() {
var arr = [];
for (var x = 0; x < g_form.elements.length; x++) {
arr.push(g_form.elements[x].fieldName);
}
alert("array value = " + arr);
}
Thanks,
Dhananjay.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2020 01:28 AM
To get all the fields use this script in the background scripts, this script will give you the label of all the fields related to that class.
var gr = new GlideRecord('sys_dictionary');
gr.addEncodedQuery('nameSTARTSWITHcmdb_ci_appl'); //repace it with class table name
gr.query();
if(gr.next()){
gs.print(gr.column_label);
}
Regards
Pranav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2020 01:15 AM
Can you try this on client side
var allFields = g_form.getFieldNames();
console.log(allFields);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2020 01:21 AM
Hi,
I tried but nothing I am getting.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2020 01:21 AM
Best way is to query the dictionary table with that table and get only those fields belonging to the particular table to avoid getting inherited fields
also refer below link for help
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2020 01:27 AM