There are scenarios where we need to show and compare Internal and Static field names of a SharePoint list.
For instance, if we want to do CAML query over some custom fields, but we don’t remember exactly the Internal Name of the field, we can use this code directly copied and pasted in the browser console to get all the names.
JavaScript Object Model reference
Using JSOM or JavaScript Object Model, It is important the difference between get all fields directly from a list and get all view fields from a view.
This is the code to get all the field information:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var view = list.get_views().getByTitle('All Documents');
//get_viewFields() returns SP.ViewFieldCollection object --- only field names (Internal Names), but not a SP.Field object > https://msdn.microsoft.com/en-us/library/office/jj244841.aspx
var viewFieldCollection = view.get_viewFields();
ctx.load(viewFieldCollection);
ctx.executeQueryAsync(function (){
var cont=0;
var fields = 'SP.FieldCollection from list.get_fields()'
fields += 'Internal Name - Static Name \n';
fields += '--------------------------- \n';
var listEnumerator = fieldCollection.getEnumerator();