Get internal names of the field from a list using JavaScript Object Model (jsom) in SharePoint 2013/2016/Online
In this JSOM SharePoint tutorial, we will discuss how to get internal names of fields from list using JSOM (JavaScript object model) in SharePoint 2013/2016 or SharePoint Online.
Every SharePoint list column has an internal name as well as the display name. You can change the display name but you can not change the internal name once the column got created in SharePoint Online or SharePoint 2013/2016.
Get internal names of field from list using JavaScript Object Model (jsom) in SharePoint
Below is the JSOM code which will retrieve internal names of field from list using JavaScript Object Model (jsom) in SharePoint.
You can add the below code inside a script editor web part or inside a content editor web part in SharePoint Online or SharePoint 2013/2016.
<input type="text" id="txtListTime"></input>
<input type='button' value='Get column names' onclick="GetFieldList();"/>
<script language="javascript" type="text/javascript">
function GetFieldList()
{
var listname = document.getElementById('txtListTime').value;
var ctx = SP.ClientContext.get_current();
this.web = ctx.get_web();
ctx.load(this.web);
this.list = web.get_lists().getByTitle(listname);
ctx.load(this.list);
this.fields = this.list.get_fields();
ctx.load(this.fields);
ctx.executeQueryAsync(Function.createDelegate(this, this.getListInfoSuccess), Function.createDelegate(this, this.getListInfoFail));
}
function getListInfoSuccess(sender, args)
{
var fieldEnumerator = this.fields.getEnumerator();
var results="";
while (fieldEnumerator.moveNext()) {
var oField = fieldEnumerator.get_current();
if (!oField.get_hidden())
results+= oField.get_title()
+ " – " + oField.get_internalName()
+ " – " + oField.get_hidden()
+ "\n";
}
alert(results);
}
function getListInfoFail(sender, args)
{
alert('Something failed. Error:'+args.get_message());
}
</script>
Once you Save the above code and click on the button, it will display all the internal names of the fields of SharePoint list using JavaScript. You can see the result below:
You may like following jsom SharePoint examples:
- Get Current User Details Using JavaScript Object Model (jsom) and jQuery in SharePoint 2013/2016/Online
- SharePoint online: Add Columns or Fields to SharePoint List or Document Library using JavaScript Object Model (jsom)
- Uncaught TypeError: Cannot read property get_current of undefined error sharepoint online jsom
- CRUD Operations with ECMA or jsom in SharePoint 2013 and SharePoint 2016 Part-2
- Upload multiple attachments to list items using JSOM and REST API in SharePoint online
- Working with Sites in SharePoint online office 365 using JavaScript Object Model jsom
- How to read file content using JavaScript object model jsom in SharePoint Online Office 365?
- How to update file content using JavaScript object model jsom in SharePoint Online Office 365?
I hope this SharePoint tutorial helps to Get internal names of the field from a list using JavaScript Object Model (jsom) in SharePoint 2013/2016/Online.
I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SPGuides.com