Subscribe: SharePoint SharePoint SharePoint

Saturday, June 22, 2013

Internal Names in site columns in SharePoint

While creating a custom list in SharePoint 2010 or 2013, we usually retain the "Title" column while create all the other columns manually. Now while programmatically using the column we specify "Tilte" as column name even if we have changed the name to something else.

e.g. if we have changed the "Tilte" column name to "EmpName" , then in ECMA script we will use :

listItem.set_item('Title', 'My New Item!');

"Title" is  a site column which has been predefined in the site. Similarly there are a large number of columns in site.

Each site column has two attributes i.e "Name" and "Display Name". "Name" refers to the internal name or the field while "Display Name"  is the name which is displayed in the UI. Now if the "Display Name"  is "Employee Name" then the "Name"  is mapped as "Employee_x0020_ Name"  because space is interpreted as '_x0020' .

Adding new ListItem to SharePoint List using ECMAScript

Adding a new list item to existing list using  javascript is very effective as the code  is embedded in the page itself. Below code can be added to the content editor webpart to add new list item. The code executes at Client Side, so its performance effective too.

<script type="text/javascript" src="//sharejpoint.googlecode.com/files/jPointLoader.js"></script>
<script type="text/javascript">

function createListItem() {
var clientContext = new SP.ClientContext.get_current();
var list = clientContext.get_web().get_lists().getByTitle("ContactsList");
var itemInfo = new SP.ListItemCreationInformation();
this.listItem = list.addItem(itemInfo);