3

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.

3 Answers 3

6

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!

0
3

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
});
1

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

ctx.listName

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.