only My site

Thursday, January 17, 2013

ECMAScript to read Hyperlink URL and description


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

context.executeQueryAsync(
function()
{
    /* On Success */
    alert(myListItem.get_item("HyperLinkFieldName").get_description());
    alert(myListItem.get_item("HyperLinkFieldName").get_url());
},
function(sender,args)
{
    /* On Failure */
   alert(args.get_message());
}
);

No comments: