locked
user form from active directory RRS feed

  • Question

  • Hallo, I need to set form with the user logged data. The data should be get from active directory.

    I'm using SharePoint online.

    I'm new with SharePoint , could you tell me the easiest way to do fill the form with user logged  data?

    Something like this:

    Thank you

    Alex

    Thursday, March 21, 2019 1:19 PM

Answers

  • Hi Alex,

    Please use the code below.

    <script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function(){	 
    	GetMyProperties().done(function(data){
    		var email=data.d.Email;
    		var personalUrl=data.d.PersonalUrl;
    		$("#MyProperties").append('<img src="/_layouts/15/userphoto.aspx?size=M&username='+email+'"/>');
    		$("#MyProperties").append("<p>PersonalUrl:"+personalUrl+"</p>");
    		$.each(data.d.UserProfileProperties.results,function(i,property){
    			if(property.Key=="PreferredName"||property.Key=="Department"||property.Key=="SPS-JobTitle"||property.Key=="CellPhone"||property.Key=="WorkEmail"){
    				$("#MyProperties").append("<p>"+property.Key+":"+property.Value+"</p>");
    			}					
    		});
    	});
    });
    function GetMyProperties(accountName){
    	return $.ajax({
            url: _spPageContextInfo.siteAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties",
            type: "GET",               
            headers: {
                "Accept": "application/json;odata=verbose",
            }        
        });
    }
    </script>
    <div id="MyProperties"/>

    Best Regards,

    Dennis


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

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Marked as answer by Alex Loja Thursday, April 4, 2019 9:33 AM
    Monday, March 25, 2019 1:42 AM

All replies

  • Hi Alex,

    We can use user profile REST API to get all the current user profile properties, then build the form.

    The following code for your reference.

    <script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function(){	 
    	GetMyProperties().done(function(data){		
    		$.each(data.d.UserProfileProperties.results,function(i,property){			
    			$("#MyProperties").append("<p>"+property.Key+":"+property.Value+"</p>");
    		});
    	});
    });
    function GetMyProperties(accountName){
    	return $.ajax({
            url: _spPageContextInfo.siteAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties",
            type: "GET",               
            headers: {
                "Accept": "application/json;odata=verbose",
            }        
        });
    }
    </script>
    <div id="MyProperties"/>

    More information:

    SharePoint 2013: Get UserProfile Properties with REST API

    Best Regards,

    Dennis


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

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Friday, March 22, 2019 2:21 AM
  • Hallo, that's work but I need only name, surname, company, site, department, job title, phone, email.

    Please help me

    Thank you

    Alex

    Friday, March 22, 2019 9:14 AM
  • Hi Alex,

    We can add if condition in the code to get all the properties you want.

    <script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function(){	 
    	GetMyProperties().done(function(data){		
    		$.each(data.d.UserProfileProperties.results,function(i,property){
    			if(property.Key=="PreferredName"||property.Key=="Department"||property.Key=="SPS-JobTitle"||property.Key=="CellPhone"||property.Key=="WorkEmail"){
    				$("#MyProperties").append("<p>"+property.Key+":"+property.Value+"</p>");
    			}					
    		});
    	});
    });
    function GetMyProperties(accountName){
    	return $.ajax({
            url: _spPageContextInfo.siteAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties",
            type: "GET",               
            headers: {
                "Accept": "application/json;odata=verbose",
            }        
        });
    }
    </script>
    <div id="MyProperties"/>

    Best Regards,

    Dennis


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

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Friday, March 22, 2019 9:30 AM
  •  Please, that work but I see all the A.D. list and it's not good for me:

    I 'd like to see just name, surname, company, site, department, job title, phone, email and the user's photo profile too...

    Please be patient

    Thank you

    Alex



    • Edited by Alex Loja Saturday, March 23, 2019 11:36 AM
    Friday, March 22, 2019 3:30 PM
  • Hi Alex,

    Please use the code below.

    <script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function(){	 
    	GetMyProperties().done(function(data){
    		var email=data.d.Email;
    		var personalUrl=data.d.PersonalUrl;
    		$("#MyProperties").append('<img src="/_layouts/15/userphoto.aspx?size=M&username='+email+'"/>');
    		$("#MyProperties").append("<p>PersonalUrl:"+personalUrl+"</p>");
    		$.each(data.d.UserProfileProperties.results,function(i,property){
    			if(property.Key=="PreferredName"||property.Key=="Department"||property.Key=="SPS-JobTitle"||property.Key=="CellPhone"||property.Key=="WorkEmail"){
    				$("#MyProperties").append("<p>"+property.Key+":"+property.Value+"</p>");
    			}					
    		});
    	});
    });
    function GetMyProperties(accountName){
    	return $.ajax({
            url: _spPageContextInfo.siteAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties",
            type: "GET",               
            headers: {
                "Accept": "application/json;odata=verbose",
            }        
        });
    }
    </script>
    <div id="MyProperties"/>

    Best Regards,

    Dennis


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

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Marked as answer by Alex Loja Thursday, April 4, 2019 9:33 AM
    Monday, March 25, 2019 1:42 AM
  • Hi Dennis, ,thank you for  your reply, but doesn't work as expected:
    Monday, March 25, 2019 8:01 AM
  • Hi,

    Please manage user profiles in the admin center. And check if some the user properties are empty.

    Or you can use Graph API to achieve it.

    https://docs.microsoft.com/en-us/graph/api/user-get?view=graph-rest-1.0

    Example about using SPFx for your reference.

    https://docs.microsoft.com/en-us/sharepoint/dev/spfx/use-aad-tutorial

    Best Regards,

    Dennis


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

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.



    • Proposed as answer by Divya Akula Monday, March 25, 2019 8:45 AM
    • Edited by Dennis Guo Monday, March 25, 2019 9:05 AM
    Monday, March 25, 2019 8:15 AM
  • Hi Dennis, what should I do exactly? Please, I do not understood:

    Tuesday, March 26, 2019 3:14 PM
  • Hi Alex,

    In admin center, select "user profiles", then open Manage User Profiles page, and find the user, then click "Edit My Profile", then edit the user profile properties for the user.

    Best Regards,

    Dennis


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

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Wednesday, March 27, 2019 8:47 AM
  • Hi Dennis, please be patient,  the content of data are correct. But I need to view just these fields: name, surname, company, site, department, job title, phone, email.

    Meanwhile with this code I see all the A.D data:

    <script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $
    (function(){
    GetMyProperties().done(function(data){
    var email=data.d.Email;
    var personalUrl=data.d.PersonalUrl;
    $
    ("#MyProperties").append('<img src="/_layouts/15/userphoto.aspx?size=M&username='+email+'"/>');
    $
    ("#MyProperties").append("<p>PersonalUrl:"+personalUrl+"</p>");
    $
    .each(data.d.UserProfileProperties.results,function(i,property){
    if(property.Key=="PreferredName"||property.Key=="Department"||property.Key=="SPS-JobTitle"||property.Key=="CellPhone"||property.Key=="WorkEmail"){
    $
    ("#MyProperties").append("<p>"+property.Key+":"+property.Value+"</p>");
    }
    });
    });
    });
    function GetMyProperties(accountName){
    return $.ajax({
            url
    : _spPageContextInfo.siteAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties",
            type
    : "GET",              
            headers
    : {
               
    "Accept": "application/json;odata=verbose",
           
    }       
       
    });
    }
    </script>
    <div id="MyProperties"/>

    I just need to see name, surname, company, site, department, job title, phone, email.

    Thank you

    Alex

    Wednesday, March 27, 2019 5:03 PM
  • Hi Alex,

    If we add the If condition below, we don't get all the user profile properties.

    if(property.Key=="PreferredName"||property.Key=="Department"||property.Key=="SPS-JobTitle"||property.Key=="CellPhone"||property.Key=="WorkEmail"){
    	$("#MyProperties").append("<p>"+property.Key+":"+property.Value+"</p>");
    }

    Best Regards,

    Dennis


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

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Thursday, March 28, 2019 7:50 AM
  • Hi Dennis, tnks that work!!!! In web part:  Modern script Editor !

    Thank you very mutch

    Thursday, April 4, 2019 9:35 AM