0
function getListsInformation()
{
    debugger;
    var oClientContext = new SP.ClientContext.get_current();
    oWebsite = oClientContext.get_web();
    oList = oWebsite.get_lists().getByTitle('Students');
    oClientContext.load(oList);
    oClientContext.executeQueryAsync(ListInformationSuccess,ListInformationFailed);   
}

function ListInformationSuccess()
{
    var listTitle = oList.get_title();
    var listUrl = oList.get_url();
    alert("List Title = " + listTitle + "\n List URL = "+listUrl);
}
2

While loading the list object make sure you include the properties to get url. Also List object in JSOM doesn't have method get_url() like Site or Web object have in JSOM. In order to retrieve the complete List URL, I use list default view url property along with window.location.origin property.

var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
var list = web.get_lists().getByTitle("Documents");
ctx.load(list, 'DefaultViewUrl');

ctx.executeQueryAsync(done, fail);

function done(){
    var listFullUrl = window.location.origin + list.get_defaultViewUrl();
    console.log(listFullUrl);
}

function fail(){
    console.log("Error");
}
0
function getListsInformation()
{
    var oClientContext = new SP.ClientContext.get_current();
    oWebsite = oClientContext.get_web();
    oList = oWebsite.get_lists().getByTitle('Students');
    oClientContext.load(oWebsite);
    oClientContext.load(oList,'Id','Title','DefaultViewUrl','ParentWebUrl');
    oClientContext.executeQueryAsync(ListInformationSuccess,ListInformationFailed);   
}
function ListInformationSuccess()
{
    var webUrl = oWebsite.get_url();
    var parentUrl = oList.get_parentWebUrl();
    var listfullurl = webUrl.substr(0,webUrl.length-parentUrl.length).concat(oList.get_defaultViewUrl());
    alert(listfullurl);

}

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.