4

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.

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!

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

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

ctx.listName

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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