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);
}
-
sharepoint.stackexchange.com/questions/23517/…– SynozeN TechnologiesCommented May 30, 2017 at 10:46
Add a comment
|
2 Answers
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");
}
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);
}