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() {
    var clientContext = new SP.ClientContext(siteUrl);
    var oList = clientContext.get_web().get_lists().getByTitle('Links');

    var camlQuery = new SP.CamlQuery.createAllItemsQuery();
    this.collListItem = oList.getItems(camlQuery);


    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');


function onQueryFailed(sender, args) {

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

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();
|improve this answer|||||

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.