Is there any method to get the list of fields from a form view?

Pradnya6
Giga Contributor

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?

4 REPLIES 4

michaelhade
Tera Contributor

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.



Thanks Mike, It works !


Community Alums
Not applicable

Thank you, this was very helpful!

 

I've had this question so many times and great to find a script which does this. Great stuff.