0

I'm trying to use REST API in SharePoint to getlistitems to display the link from a hyperlink field from my sharepoint list.

I AM successfully using the code to display the title field - but NOT the url from the hyperlink field.

I've tried appending the url in the code below with "/_api/web/lists/getbytitle('test')/items**?$select=URL**" without success.

<html>
<body>
<div>
<input type="button" id="btnSubmit" value="Get List Data using Rest API">
&nbsp;</div>
<div id="divResults" unselectable="on"></div>

<script src="/jquery.com/jquery-3.5.1.min.js" unselectable="on"></script>

<script unselectable="on">
$(function () {
$("#btnSubmit").on("click", function () {
getListData();
});
});
function getListData() {
var fullUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('test')/items";
$.ajax({
url: fullUrl,
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
},
success: onQuerySucceeded,
error: onQueryFailed
});
}
function onQuerySucceeded(data) {
var listItemInfo = '';
$.each(data.d.results, function (key, value) {
listItemInfo += '<b>Title:</b> ' + value.Title + '<br />';
});
$("#divResults").html(listItemInfo);
}
function onQueryFailed() {
alert('Error!');
}

</script>


</body>

</html>
1
  • Is there any update ? Did the code snippet work ? Commented Jan 11, 2021 at 6:15

1 Answer 1

0

In onQuerySucceeded function, Try this line:

listItemInfo += '<b>UrlFromHyperLinkField:</b> ' + value.TestHyperLink.Url+ '<br />';

In my side, the HyperLink named "TestHyperLink", you can replace this field name with yours to make it work.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.