Autopopulate logged in User's info

rss

Posted by christopher.young - Oct 6 ’16 at 07:42

I am using the following Javascript to Autopopulate the User's information into the form

SP.SOD.executeOrDelayUntilScriptLoaded((function () {
var ctx = new SP.ClientContext.get_current();
var web = ctx.get_web();
ctx.load(web);
var user = web.get_currentUser();
user.retrieve();
ctx.executeQueryAsync(
function () {
fd.field('User_x0020_who_x0020_needs_x0020').value(user.get_loginName());
fd.field('User_x0027_s_x0020_Official_x002').value(user.get_email());
});
}), "SP.js");

I would like to inlcude other information such as the User's Work Phone and User Name, see image below from SharePoint

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 7 years 29 days
    #1 by Dmitry Kozlov Oct 7 ’16 at 03:33

    Hi,

    You can obtain user's display name from the user object:

    user.get_title()

    As for the phone, you should retrieve it from user's profile:

    https://msdn.microsoft.com/en-us/library/office/jj920104.aspx

  • christopher.young
    Member
    Member for: 4 years 13 days
    #2 by christopher.young Oct 12 ’16 at 02:50

    I have attempted to use the information in that link several times but not only have I been unsuccessful, when I attempt to merge the scripts the original script becomes inoperable.

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 7 years 29 days
    #3 by Dmitry Kozlov Oct 13 ’16 at 04:46

    [#2]: Hi,

    Our support team ca implement the script for you. Please, send the detailed requirements to [email protected] and we will estimate them.

Displaying 1 to 3 of 3 messages