4

Using CSOM (JavaScript) how do you get the URL and description fields from a Hyperlink field?

12

Here is the working code:

var context = SP.ClientContext.get_current();
var myListItem = context.get_web().get_lists().getByTitle("ListName").getItemById(1);
context.load(myListItem);

context.executeQueryAsync(function(){

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

},function(sender,args){alert(args.get_message());});
  • I did this and it worked fine. But it only gets a single record without using a CAML query. I tried to to add the the .get_url() and get_description() to my code that loops through all the items while (enumerator.moveNext()) { var listItem = enumerator.get_current(); markup += '<td>' + listItem.get_item('Name') + '</td>'; markup += '<td>' + listItem.get_item('Level') + '</td>'; markup += '<td> + listItem.get_item("URL").get_description() + '</td>'; markup +='</tr>'; This failed. If I remove the .get_description() it returns [object, Object]. Ideas why how to fit? – PianoMan Jun 10 '16 at 21:15

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.