1

I have this code which gets the items from a list and outputs them in an alert, however with urls it inputs [object object]. How can I make it print out the URL or the description

var siteUrl = mysite;

var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('Privacy Statements');

var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('');
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 += 
        '\nTitle: ' + oListItem.get_item('Title')
         + 
        '\nPrivacy Statement Urls: ' + oListItem.get_item('PrivacyStatementUrls') ;
}

  alert(listItemInfo.toString());  

}

function onQueryFailed(sender, args) {

alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());

}

1

You can use following:

alert(myListItem.get_item("HyperLinkFieldName").get_description());
alert(myListItem.get_item("HyperLinkFieldName").get_url());

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.