Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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"/>
share|improve this question

1 Answer 1

up vote 1 down vote accepted

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();
share|improve this answer
    
Thanks mate..it worked! –  RHM Feb 19 '13 at 13:43
    
Np, same goes for other types too, like lookup. You should take a look in the SP.Namespace overview: msdn.microsoft.com/en-us/library/ee557057(v=office.14).aspx –  Anders Aune Feb 20 '13 at 8:36
    
thanks.......... –  RHM Feb 21 '13 at 13:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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