0

I have a value that looks like "mailto:a@b.com, mailto:a@b.com'. This is basically a hyperlink field and I want to parse this properly using SharePoint JSOM. I tried SP.FieldUrlValue, but it does not seem to have a method that lets you parse.

spdev
  • 361
  • 3
  • 9

1 Answers1

0

You can use the .get_url() function on the actual item value to get the hyperlink URL, or the .get_description() function to get the hyperlink's display text.

var linkField = "internalColumnName";
var listName = "List Title";
var clientContext = new SP.ClientContext();
var list = clientContext.get_web().get_lists().getByTitle(listName);
var camlQuery = new SP.CamlQuery();
var items = list.getItems(camlQuery);   
clientContext.load(items);
clientContext.executeQueryAsync(Function.createDelegate(this,function(){ 
    var itemEnumerator = items.getEnumerator();
    while(itemEnumerator.moveNext()){   
        var item = itemEnumerator.get_current(); 
        var url = item.get_item(linkField).get_url(); // <-- Get URL
        var text = item.get_item(linkField).get_description(); // <-- Get Text
        alert(url + ", " + text);
    }     
}),Function.createDelegate(this,function(sender, args){alert(args.get_message());}));
Thriggle
  • 7,009
  • 2
  • 26
  • 37