SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have different sites like

  • http://SP.abc.com/SPSite1
  • http://SP.abc.com/SPSite2
  • http://SP.abc.com/SPSite3

and each having one Library with the same name called Lib1. Now I want to get GUID of this library using jquery or using any other method that is on client side.

share|improve this question
up vote 4 down vote accepted

You can get it using REST query. The code should be:

$( document ).ready(function() {
    GetListGuid('Lib1');
});

function GetListGuid(listTitle){
    try {
    //REST Query to get the List Title 
    jQuery.ajax(
    {
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('"+listTitle+"')?$select=Id",
        type: "GET",
        async: false,
        headers: { "Accept": "application/json;odata=verbose" },
        success: function (data, textStatus, xhr) {
            alert(data.d.Id);
        },
        error: function (data, textStatus, xhr) {
            console.error("Error.");
        }
    });
}
catch (ex) {
    alert(ex);
}
}

Hope this helps!

share|improve this answer
    
Thanks it works :) – DRS Feb 22 at 10:14

Nice Solution added by @users1100 for SharePoint 2013.

You can try JSOM also. It will work for both 2010 & 2013.

var clientContext = new SP.ClientContext();
var oList = clientContext.get_web().get_lists().getByTitle('Name of List or Library');
clientContext.load(oList)
clientContext.executeQueryAsync(function() {
    console.log(oList.get_id())
}, function() {
    // error handler
});
share|improve this answer

On a page with the ListView WebPart displayed the listGUID is available as

ctx.listName

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.