How can I get names of all the fields of table

Abhijit Das7
Tera Expert

Hi Everyone,

 

I want to get names of all the fields present in table into array in scripted rest api.

 

Thanks in advance.

1 ACCEPTED SOLUTION

@Abhijit Das7 

Please try with below code, i checked on background script

 

var arr_fields=[];
var fields = new GlideRecord('sys_dictionary');
fields.addQuery('name','incident');

fields.addEncodedQuery('internal_type!=collection^ORinternal_type=NULL');//To ignore all the table dictionaries(optional)

fields.query();

while(fields.next())
{
arr_fields.push(fields.column_label.toString()+"("+fields.element.toString() + ")" );
}

for(var i=0; i<arr_fields.length; i++)
{
   gs.print(arr_fields[i]);
}

 

Kindly mark helpful/accepted if it helps you.

Thanks

View solution in original post

5 REPLIES 5

Aniket Chavan
Tera Sage
Tera Sage

@Abhijit Das7 

Give a try to the code below.

 

var arr_fields = [];
var fields = new GlideRecord('sys_dictionary');
fields.addQuery('name', 'u_customer_details'); // Change 'incident' to 'u_customer_details'

fields.addEncodedQuery('internal_type!=collection^ORinternal_type=NULL'); // To ignore all the table dictionaries(optional)

fields.query();

while (fields.next()) {
    arr_fields.push(fields.column_label.toString() + "(" + fields.element.toString() + ")");
}

for (var i = 0; i < arr_fields.length; i++) {
    gs.print(arr_fields[i]);
}

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Aniket