How to get all incident form fields in a custom field

Sowmya T
Tera Contributor

Hello,

As per the project implementation, I am trying to get all the incident column names in a custom list field. So that the user  can select all the fields for those they want to get values from incident table.

with the code below (this I got from one of the community post) I can able to get only 21 incident fields. But I want the task fields on incident form as well (Number, Short description, Description, Assignment group etc.) Any help would be appreciated.

var arr_fields=[];
var gr = new GlideRecord('sys_dictionary');
gr.addQuery('name', 'incident');
gr.addActiveQuery();
gr.addEncodedQuery('internal_type!=collection^ORinternal_type=NULL');
gr.query();
gs.addInfoMessage("number of incident fields :" + gr.getRowCount());

while (gr.next()) {
arr_fields.push(gr.column_label.toString());
}
for(var i=0; i<arr_fields.length; i++)
{
gs.info(arr_fields[i]);
}

 

1 ACCEPTED SOLUTION

Jaspal Singh
Mega Patron
Mega Patron

Try below

var arr_fields=[];
var gr = new GlideRecord('sys_dictionary');
gr.addEncodedQuery('name=incident^ORname=task');
gr.addActiveQuery();
gr.addEncodedQuery('internal_type!=collection^ORinternal_type=NULL');
gr.query();
gs.addInfoMessage("number of incident fields :" + gr.getRowCount());

while (gr.next()) {
arr_fields.push(gr.column_label.toString());
}
for(var i=0; i<arr_fields.length; i++)
{
gs.info(arr_fields[i]);
}

View solution in original post

2 REPLIES 2

Jaspal Singh
Mega Patron
Mega Patron

Try below

var arr_fields=[];
var gr = new GlideRecord('sys_dictionary');
gr.addEncodedQuery('name=incident^ORname=task');
gr.addActiveQuery();
gr.addEncodedQuery('internal_type!=collection^ORinternal_type=NULL');
gr.query();
gs.addInfoMessage("number of incident fields :" + gr.getRowCount());

while (gr.next()) {
arr_fields.push(gr.column_label.toString());
}
for(var i=0; i<arr_fields.length; i++)
{
gs.info(arr_fields[i]);
}

Sowmya T
Tera Contributor

Hi There,

I am trying to show all the task and incident fields in a custom list type field. With the above code I am getting all the required fields in a comma separated array but I am facing challenges to populate the list type field. Whatever I am doing, the list type field which is reference to Dictionary entry is showing all the dictionary records instead of the only the task and incident fields. I should only get Task and Incident field to be selected on "Field" list. Any help would be much appreciated.

Below is my Script include:

find_real_file.png

List type field:

find_real_file.png

Output:

find_real_file.png