There may be some condition where we need to get SP List properties like ID, relative URL.
Following is the CSOM code to get SP List properties.
<script type="text/javascript">
var list;
var listRootFolder;
ExecuteOrDelayUntilScriptLoaded(init, "sp.js");
function init() {
//load site
var currentcontext = new SP.ClientContext.get_current();
list = currentcontext.get_web().get_lists().getByTitle('LIST_NAME');
listRootFolder= list.get_rootFolder();
currentcontext.load(list, 'Title', 'Id');
currentcontext.load(listRootFolder);
currentcontext.executeQueryAsync(Function.createDelegate(this, result), Function.createDelegate(this, oncListQueryFailed));
}
function result() {
var listID = list.get_id();
var listName= list.get_title();
var listURL = listRootFolder.get_serverRelativeUrl();
alert(listID + listName + listURL);
}
function oncListQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
Following is the CSOM code to get SP List properties.
<script type="text/javascript">
var list;
var listRootFolder;
ExecuteOrDelayUntilScriptLoaded(init, "sp.js");
function init() {
//load site
var currentcontext = new SP.ClientContext.get_current();
list = currentcontext.get_web().get_lists().getByTitle('LIST_NAME');
listRootFolder= list.get_rootFolder();
currentcontext.load(list, 'Title', 'Id');
currentcontext.load(listRootFolder);
currentcontext.executeQueryAsync(Function.createDelegate(this, result), Function.createDelegate(this, oncListQueryFailed));
}
function result() {
var listID = list.get_id();
var listName= list.get_title();
var listURL = listRootFolder.get_serverRelativeUrl();
alert(listID + listName + listURL);
}
function oncListQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
Check all the properties for SP List.
No comments:
Post a Comment