0
votes

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 ?Jerry

1 Answers

0
votes

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