How to get all fields which are available on form only.

Peter Wood
Kilo Guru

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.

1 ACCEPTED SOLUTION

Dhananjay Pawar
Kilo Sage

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.

View solution in original post

11 REPLIES 11

@Peter Wood 

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Peter Wood 

Can you try this on client side

var allFields = g_form.getFieldNames();

console.log(allFields);

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi,

I tried but nothing I am getting.

Ankur Bawiskar
Tera Patron
Tera Patron

@Peter Wood 

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

fetch all fields in a g_form

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Pranav Bhagat
Kilo Sage

@Peter Wood 

To get all the fields use this script in the background scripts

 

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