Is there any method to get the list of fields from a form view?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2012 11:22 AM
From gliderecord object I get glideElement as follows
var gr = new GlideRecord('cmdb_ci_server');
gr.setLimit(1);
gr.query()
if (gr.next())
{
var fields = gr.getFields(); // This method returns all the field
}
Is there any way by which we can get the fields from specific view?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2012 10:40 AM
There is no OOB function to get this data, but this data can certainly be retrieved from a query. I have created a query to gather this data based on the view and table you provide. In the below example, I gather the fields in the default view on the incident table. It queries the sys_ui_view table to determine the sys_id of the view, then queries the sys_ui_section table to get all the sections on that form, then queries the sys_ui_element table to get all the elements (fields) on those sections.
var viewName = "default";
var tableName = "incident";
var grView = new GlideRecord("sys_ui_view");
if (grView.get("name", viewName))
{
var grSection = new GlideRecord("sys_ui_section");
grSection.addQuery("view", grView.sys_id);
grSection.addQuery("name", tableName);
grSection.query();
while(grSection.next())
{
var grElement = new GlideRecord("sys_ui_element");
grElement.addQuery("sys_ui_section", grSection.sys_id);
grElement.addNullQuery("type");
grElement.orderBy("position");
grElement.query();
while(grElement.next())
{
gs.print("Section = " + grSection.caption + "\tPosition = " + grElement.position + "\tElement = " + grElement.element);
}
}
}
Let me know if this is the data you are looking for, thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2012 02:25 AM
Thanks Mike, It works !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2021 09:48 AM
Thank you, this was very helpful!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2022 01:52 AM
I've had this question so many times and great to find a script which does this. Great stuff.