0

I am getting user profile info like this but I have to split and get from anchors (a href) or on a query. why I can't get directly the data insted of a html dom?

    <script>
    $(function() {
        var CurrentUser = {         
          AccountName: '<SPSWC:ProfilePropertyValue PropertyName="AccountName" TitleMode="true" runat="server" />'.split("accountname=")[1].split("\">")[0],
          UserName: '<SPSWC:ProfilePropertyValue PropertyName="UserName" TitleMode="true" runat="server" />',
          FirstName: '<SPSWC:ProfilePropertyValue PropertyName="FirstName" TitleMode="true" runat="server" />',
          LastName: '<SPSWC:ProfilePropertyValue PropertyName="LastName" TitleMode="true" runat="server" />',
          PictureURL: $('<SPSWC:ProfilePropertyValue PropertyName="PictureURL" TitleMode="true" runat="server" />').attr("href"),
          Status: '<SPSWC:ProfilePropertyValue PropertyName="SPS-StatusNotes" TitleMode="true" runat="server" />'
        };  

        $("#lblUserName").html(CurrentUser.FirstName + " " + CurrentUser.LastName);
        $("#imgProfilePicture").attr("src", CurrentUser.PictureURL);
        $("#lnkEditProfile").attr("href", "/_layouts/15/EditProfile.aspx?accountname=" + CurrentUser.AccountName);
    });
    </script>
1

If you have SP2013, you should access the user profile properties via the client object model, or via the corresponding REST endpoint, instead of downloading the EditProfile.aspx page and parsing the page.

See this post and this one as well for code samples.

If you have a pre-SP2013 version, the best choice might be to call the User Profiles web service. In this case I suggest to use the corresponding objects of the SPServices library.

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.