none
attaching link to a user from a rest query sharepoint

    Question

  • Hi,

    I am using REST query to display title and user/group column details in a page.

    However, i want to have a hyperlink anchored to the user as well, so that when a person clicks on the user  name ; it displays their profile page(mysite, delve or any standard link).

    How do i amend this change below.

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
    <script type="text/javascript">
    
        function getCareerLinks() {
     $.ajax({
            url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('TeamSiteConfiguration')/Items?$select=Title,TeamOwner/Account&$expand=TeamOwner/Id",
            type: "GET",
            headers: {
                "accept": "application/json;odata=verbose",
            },
            success: function (data) {
                 $.each(data.d.results, function(index, item){
                   //alert(item.Title);
                
                   var varFocusItem = "<div style='height:75px; width:200px; border:1px solid #f6f6f6; margin-bottom:5px;padding:5px 0px 0px 5px'><div>" + item.TeamOwner.Account + "</div></div>"
                   $('#InFocusDivision').append(varFocusItem);
    
                });
                
            },
            error: function (error) {
                alert(JSON.stringify(error));
            }
        });
    }
    _spBodyOnLoadFunctionNames.push("getCareerLinks");
    </script><br/>

    Thanks

    Monday, April 10, 2017 1:06 PM

All replies

  • Hi,

    You can use userdisp.aspx page for construct the link for users, it will redirect to user's profile page if user profile service application has been configured and associated with the web application where the page exists.

    Please refer to the JS demo below:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
    <script type="text/javascript">
    
        function getCareerLinks() {
     $.ajax({
            url: _spPageContextInfo.webAbsoluteUrl +"/_api/web/lists/GetByTitle('TeamSiteConfiguration')/Items?$select=Title,TeamOwner/Account,TeamOwner/Id&$expand=TeamOwner/Id",
            type: "GET",
            headers: {
                "accept": "application/json;odata=verbose",
            },
            success: function (data) {
                 $.each(data.d.results, function(index, item){
                   var varFocusItem = "<div style='height:75px; width:200px; border:1px solid #f6f6f6; margin-bottom:5px;padding:5px 0px 0px 5px'><div><a href='"+_spPageContextInfo.webAbsoluteUrl+"/_layouts/15/userdisp.aspx?ID="+item.TeamOwner.Id+"'>" + item.TeamOwner.Account + "</a></div></div>";
                   $('#InFocusDivision').append(varFocusItem);
                });
                
            },
            error: function (error) {
                alert(JSON.stringify(error));
            }
        });
    }
    _spBodyOnLoadFunctionNames.push("getCareerLinks");
    </script>

    Best Regards,

    Victoria  


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, April 11, 2017 9:33 AM
    Moderator
  • Hi,

    I am checking to see how things are going there on this issue. Please let us know if you would like further assistance.

    Best Regards,

    Victoria


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, April 25, 2017 1:36 AM
    Moderator