1

I have a column defined as a Hyperlink or Picture.

Using JSOM and CAML in the CAML is have specified <FieldRef Name='HyperLinkFieldName' /><Value Type='URL'></value>"

I'm able to access the field using myListItem.get_item("HyperLinkFieldName") but it appears as an [object Object] which indicates that the item is an object containing values. I'm guessing one value is the URL the other is the description.

but when I add to myListItem.get_item("HyperLinkFieldName").geturl() it fails, nothing appears.

What is the proper way to extract the url and description from the object using JSOM?

  • did you try get_url()? – bdimag Aug 10 '16 at 22:01
0

In my situation I got WorkflowLink using CSOM and the URL was a property of the object and not a method.

You can try (probably case sensitive):

myListItem.get_item("HyperLinkFieldName").Url;

You can also do some simple browser debugging to see what the object looks like.

console.debug(["this is a url object", myListItem.get_item("HyperLinkFieldName")]);

console.debug should work on most major browsers... maybe not some IE =)

UPDATE

I used this post as reference for my code: https://msdn.microsoft.com/en-us/library/office/hh185007(v=office.14).aspx

here is code chunks of what I am using:

this.CAMLListView = function(listName, query, fields) {
  var context;
  var web;
  var list;
  var camlQuery;
  var items;
  var result = [];
  var deferred = $.Deferred(function() {
    function execOperation() {
      context = new SP.ClientContext.get_current();
      web = context.get_web();
      list = web.get_lists().getByTitle(listName);
      camlQuery = new SP.CamlQuery();
      camlQuery.set_viewXml(query);
      items = list.getItems(camlQuery);
      context.load(items);
      context.executeQueryAsync(
        function() {
          var iterator = items.getEnumerator();
          while(iterator.moveNext()) {
            var item = iterator.get_current();
            var entry = {"id":item.get_id()};
            for(var i in fields) {
              entry[fields[i]] = item.get_item(fields[i]);
            }
            result.push(entry);
          }
          deferred.resolve();
        },
        function (sender, args) {
          deferred.reject(args.get_message());
        });
    };
    execOperation();
  });
  var promise = deferred.then(function() {
    return result;
  });
  return {$promise:promise};
}

then i call that function:

  var query = `
    <View Scope='Recursive'>
      <Query>
        <Where>
        </Where>
      </Query>
      <RowLimit>1000</RowLimit>
    </View>
  `;
      SharepointAPI.CAMLListView("Surveys",query, ["Title","Author","FileRef"]).$promise.then(function(result) {
    console.debug({"CAMLListView":result});
    return;
  });

In my case, I was able to pull up partial url from the "FileRef" field.

if you open "developer tools" or similar in FF,IE,Chrome, then load the page, you should start seeing the debug statements show up on a 'console' tab. in FF you need to "enable" it for the first time.

Hope this helps.

  • Thanks for the response. I'm assuming that myListItem is equivalent to simply listItem - which i what I'm using. Your suggestion did not work, the code simply failed. I'm not familiar with the console.debug will look into that on how to use. This seems to be such a simply task but for some reason I can not find any info on this for the JSOM. – PianoMan Aug 7 '16 at 1:31

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.