Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Error while retrieving a SP List server relative url using CSOM

$
0
0

Hello Guys,

I'm pretty with the sharepoint CSOM and i'm not able to find out how to get the serverRelativeUrl of a list.

I tried the following code but i'm getting an error :

The property or field 'ServerRelativeUrl' has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.

$(document).ready(function () {
    WriteLists();
});

function WriteLists() {
    var clientContext = new SP.ClientContext('/sites/DevApp/');
    var web = clientContext.get_web();
    var lists = web.get_lists();
    clientContext.load(lists);
    clientContext.executeQueryAsync(onListsQuerySucceeded, onListsQueryFailed);

    function onListsQuerySucceeded() {
        var listEnumerator = lists.getEnumerator();
        while (listEnumerator.moveNext()) {
            var oList = listEnumerator.get_current();
            if (oList.get_hidden() === false) {
                clientContext.load(oList);
                rootFolder = oList.get_rootFolder();
                clientContext.load(rootFolder);
                clientContext.executeQueryAsync(onRootFolderQuerySucceeded, onRootFolderQueryFailed)

                function onRootFolderQuerySucceeded() {
                    url = rootFolder.get_serverRelativeUrl();
                    clientContext.load(url);
                    clientContext.load(title);
                    clientContext.executeQueryAsync(onUrlQuerySucceeded, onUrlQueryFailed);

                    function onUrlQuerySucceeded() { AddTile(title, url) }
                    function onUrlQueryFailed(sender, args) {
                        alert("Failed: " + args.get_message());
                    }
                }

                function onRootFolderQueryFailed(sender, args) {
                    alert("Failed: " + args.get_message());
                }
            }
        }
    }

    function onListsQueryFailed(sender, args) {
        alert("Failed: " + args.get_message());
    }
}

Where's my mistake?

Thanks and regards,


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>