Wednesday, 4 September 2013

Sharepoint 2013 - Get SP List Title, ID, RelativeURL using CSOM

There may be some condition where we need to get SP List properties like ID, relative URL.

Following is the CSOM code to get SP List properties.

<script type="text/javascript">

var list;
var listRootFolder;
ExecuteOrDelayUntilScriptLoaded(init, "sp.js");

function init() {

    //load site
   var currentcontext = new SP.ClientContext.get_current();
   list = currentcontext.get_web().get_lists().getByTitle('LIST_NAME');
   listRootFolder= list.get_rootFolder();

    currentcontext.load(list, 'Title', 'Id');
    currentcontext.executeQueryAsync(Function.createDelegate(this, result), Function.createDelegate(this, oncListQueryFailed));

function result() {
var listID = list.get_id();
    var listName= list.get_title();
var listURL = listRootFolder.get_serverRelativeUrl();
alert(listID + listName + listURL);

function oncListQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());


Check all the properties for SP List.