Display SharePoint List Items in Hyperlink in SharePoint Hosted Add-in or Apps

Display SharePoint List Items in Hyperlink in SharePoint Hosted Add-in or Apps

This SharePoint tutorial explains, how to display SharePoint list items in a hyperlink in SharePoint hosted add-in or apps using visual studio 2015/2017/2019.

Display SharePoint List Items in Hyperlink in SharePoint Hosted Add-in or Apps

First, create a SharePoint hosted add-in or apps and then we will write the jsom code. If you are new to SharePoint hosted add-in or apps, you can follow below tutorials:

SharePoint deveopment training course

Open your visual studio then click on File -> New -> Project…

Next, it will open a new project window, Go to Office/SharePoint, here select Add-ins and select SharePoint Add-in. Next, enter Name and select your project location and then click OK.

It will open a new SharePoint add-in window. select your SharePoint site for debugging and next select SharePoint Add-In and select SharePoint-hosted and click on Next.

Then enter the username and password to connect to the SharePoint Online site.

Now select SharePoint online and click Finish.

Now, we can the code inside the App.js file.

'use strict';

ExecuteOrDelayUntilScriptLoaded(getURLParameters, "sp.js");
ExecuteOrDelayUntilScriptLoaded(SPListHyperLink, "sp.js");
var listItems;
var hostUrl;

function SPListHyperLink() {
hostUrl = decodeURIComponent(getURLParameters("SPHostUrl"));
varclientContext = newSP.ClientContext.get_current();
varhostcontext = newSP.AppContextSite(clientContext, hostUrl);
var web = hostcontext.get_web();
var list = web.get_lists().getByTitle('Employee');
var cmlquery = newSP.CamlQuery();
listItems = list.getItems(cmlquery);
load(listItems, 'Include(Title,ID)');
executeQueryAsync(GetDataSuccess,GetDataFailed);
}

functionGetDataSuccess() {
var listInfo = ";
var ListEnumeratorAcc = listItems.getEnumerator();
listInfo += "<table><thead><tr>" +
"<th>Title</th>" +
"</tr></thead><tbody>";
while (ListEnumeratorAcc.moveNext()) {
var currentItem = ListEnumeratorAcc.get_current();
var url = hostUrl + "/Lists/Employee/DispForm.aspx?ID=" + currentItem.get_item('ID');
listInfo += '<tr><td>' + "<a href='" + url +"'>" + currentItem.get_item('Title') + "</a>" + '</td>';
+'</tr>';
}

listInfo += '</tbody></table>';
$('#EmployeeData').html(listInfo);
//$('#SPTable').dataTable();
}

functionGetDataFailed() {
alert("Error Message:\n" + "URL: " + sender.get_url() + ". \n\Error Description:" + args.get_message());
}

functiongetURLParameters(param) {
var params = document.URL.split('?')[1].split('&');
var strParams = ";
for (vari = 0; i<params.length; i = i + 1) {
var singleParam = params[i].split('=');
if (singleParam[0] == param) {
returnsingleParam[1];
}
}
}

The Default.aspx code will look like below:

<asp:ContentContentPlaceHolderID="PlaceHolderMain"runat="server">
<divid="EmployeeData">
</div>
</asp:Content>

Build and deploy your project and if you have items in the SharePoint list, you can see the output.

Display SharePoint List Items in Hyperlink in SharePoint Hosted Add-in or Apps
Display SharePoint List Items in Hyperlink in SharePoint Hosted Add-in or Apps

You may also like following SharePoint hosted add-in tutorials:

Hope this SharePoint tutorial explains, how to display SharePoint list items as hyperlinks in SharePoint hosted apps.

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

About Bhawana Rathore

Hello Everyone!! I am Bhawana a SharePoint MVP and having about 8+ years of SharePoint experience as well as in .Net technologies . I have worked in all the versions of SharePoint from wss to Office 365. I have good exposure in Customization and Migration using Nintex, Metalogix tools . Now exploring more in SharePoint 2016 :) Hope here I can contribute and share my knowledge to the fullest. As I believe "There is no wealth like knowledge, and no poverty like ignorance"

View all posts by Bhawana Rathore →