0

I want to get URLs from SharePoint Links list using client object model javascript, can someone help me, I tried the following script but when I am alerting its result it shows me the URL value as [object Object] but not the actual URL.

<script type="text/javascript">


var siteUrl = '/';

function retrieveListItems() {
alert("hello");
    var clientContext = new SP.ClientContext(siteUrl);
    var oList = clientContext.get_web().get_lists().getByTitle('Links');

    var camlQuery = new SP.CamlQuery.createAllItemsQuery();
    //camlQuery.set_viewXml('<View><Query></Query></View>');
    this.collListItem = oList.getItems(camlQuery);

    clientContext.load(collListItem);

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));        

}

function onQuerySucceeded(sender, args) {

    var listItemInfo = '';

    var listItemEnumerator = collListItem.getEnumerator();

    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();
        listItemInfo += '\nID: ' + oListItem.get_id() + 
            '\nURL: ' + oListItem.get_item('URL');
            //'\nFieldName: ' + oListItem.get_item('Notes');
    }

    alert(listItemInfo.toString());
}

function onQueryFailed(sender, args) {

    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}</script><input id="button1" onclick="retrieveListItems()" type="button" value="GetItems"/>

1 Answer 1

2

You need to use .get_url()

This should work:

var oListItem = listItemEnumerator.get_current();
        listItemInfo += '\nID: ' + oListItem.get_id() + 
            '\nURL: ' + oListItem.get_item('URL').get_url();
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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