none
Get user data based on people picker value in SharePoint 2010 RRS feed

  • Question

  • Dear All,

    I want to get the user data based on the people picker value that we select, please refer below screenshot for your reference.


    Harshavardhan

    Monday, June 29, 2020 2:59 AM

Answers

  • Dear All,

    Here is my solution,

        var invokeAfterEntityEditorCallback =  function(func) {
        var old__EntityEditorCallback = EntityEditorCallback;
        if (typeof EntityEditorCallback != 'function') {
            EntityEditorCallback = func;
        } else {
            EntityEditorCallback = function(result, ctx) {
                old__EntityEditorCallback(result, ctx);
            func(result, ctx);
            }
        }
    };
    var userDeptValue =[];
    var PplpickeraccountName = '';
    function onPeoplePickerFieldSet(result, ctx){
        if(ctx.indexOf("ctl00_ctl00_UserField")!=-1){
        
        var xmlDoc=$.parseXML(result);
        var $xml=$(xmlDoc);
        var $keys=$xml.find("Key");
        //console.log($keys);
        $keys.each(function(){
        var name=$(this).text();
       
        if(name=="AccountName")
        {
        //console.log($(this).next());
                    var PplpickeraccountName =$(this).next().text();
        //alert(PplpickeraccountName);
        getPeoplePickerDetails(PplpickeraccountName);
           
        }
       
        });
          }
    }



    function getPeoplePickerDetails(PplpickeraccountName)
    {
    //var pplPickerName = $().SPServices.SPGetCurrentUser();

    $().SPServices({
    operation: "GetUserProfileByName",
    async: false,
    AccountName: PplpickeraccountName,
    completefunc: function (xData, Status) {

    $("#tblAddNew>tbody>tr").each(function(i,v){
    var tdHtml=$("#tblAddNew tbody tr:nth-child("+(i+1)+")").children("td:nth-child(3)").html();
    //console.log(i+":"+tdHtml);
    if(tdHtml!=undefined){
    if(tdHtml.indexOf(PplpickeraccountName)>-1){
    $(xData.responseXML).find("PropertyData > Name:contains('SPS-JobTitle')").each(function() {
    userJob= $(this).parent().find("Values").text();
    //console.log(i+" userJob:"+userJob);
    $("#tblAddNew>tbody>tr:nth-child("+(i+1)+")>td:nth-child(7) input[type='text']").val(userJob);
    });

    $(xData.responseXML).find("PropertyData > Name:contains('EnglishDivision')").each(function() {
    userDivision= $(this).parent().find("Values").text();
    //console.log(i+" userDivision:"+userDivision);
    $("#tblAddNew>tbody>tr:nth-child("+(i+1)+")>td:nth-child(5) input[type='text']").val(userDivision);
    });

    $(xData.responseXML).find("PropertyData > Name:contains('OracleNumber')").each(function() {
    userEmployeeNumber= $(this).parent().find("Values").text();
    //console.log(i+" userDivision:"+userDivision);
    $("#tblAddNew>tbody>tr:nth-child("+(i+1)+")>td:nth-child(4) input[type='text']").val(userEmployeeNumber);
    });

    $(xData.responseXML).find("PropertyData > Name:contains('Department')").each(function() {
    userDepartment = $(this).parent().find("Values").text();
    userDeptValue.push(userDepartment);
    //console.log(i+" userDivision:"+userDivision);
    $("#tblAddNew>tbody>tr:nth-child("+(i+1)+")>td:nth-child(6) input[type='text']").val(userDeptValue[0]);
    });


    }
    }
    userDeptValue=[];
    });

    //console.log("Response XML:",PplpickeraccountName,",",xData.responseXML);

    }

    });

    }

    // ABOVE CODE CALL OUTSIDE DOCUMENT.READY AND CALL BELOW LINE INSIDE DOCUMENT.READY

    invokeAfterEntityEditorCallback(onPeoplePickerFieldSet);

    Hope it helps someone :) it works in 2010, not tested in 2013/2016/2019


    Harshavardhan


    Friday, July 3, 2020 8:30 AM

All replies

  • Hi, Harshavardhan,

    You can create a data connection to get data from User Information list or SOAP user profile service to get data back. Then add a rule to set the fields with proper value retrieved from these data connections. 

    Here are some examples for your reference.

    https://claytoncobb.com/2009/06/21/userprofileservice-extended/

    https://spvee.wordpress.com/2013/04/10/auto-populate-user-information-in-infopath-with-claims-based-authentication-part-1-of-3/

    https://www.c-sharpcorner.com/blogs/an-alternative-approach-to-query-user-profile-service-in-infopath-using-sharepoint-online (It is for SharePoint Online but the user information list also works for SharePoint 2010)

    Please Note: Since the web site is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.

    Best Regards

    Jerry


    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.

    Tuesday, June 30, 2020 7:15 AM
  • Dear Jerry,

    Thanks for your reply, This is not infopath form, it is SharePoint designer custom form. i got the solution anyways, thank you so much.

    Regards,


    Harshavardhan

    Wednesday, July 1, 2020 3:05 AM
  • Hi, Harshavardhan,

    Glad to hear that you get the solution. Thanks for your reply. If possible, would you like to share your solution here and mark it as answer? It will provide help to community members with similar concerns.

    Best Regards

    Jerry


    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, July 1, 2020 6:17 AM
  • Dear All,

    Here is my solution,

        var invokeAfterEntityEditorCallback =  function(func) {
        var old__EntityEditorCallback = EntityEditorCallback;
        if (typeof EntityEditorCallback != 'function') {
            EntityEditorCallback = func;
        } else {
            EntityEditorCallback = function(result, ctx) {
                old__EntityEditorCallback(result, ctx);
            func(result, ctx);
            }
        }
    };
    var userDeptValue =[];
    var PplpickeraccountName = '';
    function onPeoplePickerFieldSet(result, ctx){
        if(ctx.indexOf("ctl00_ctl00_UserField")!=-1){
        
        var xmlDoc=$.parseXML(result);
        var $xml=$(xmlDoc);
        var $keys=$xml.find("Key");
        //console.log($keys);
        $keys.each(function(){
        var name=$(this).text();
       
        if(name=="AccountName")
        {
        //console.log($(this).next());
                    var PplpickeraccountName =$(this).next().text();
        //alert(PplpickeraccountName);
        getPeoplePickerDetails(PplpickeraccountName);
           
        }
       
        });
          }
    }



    function getPeoplePickerDetails(PplpickeraccountName)
    {
    //var pplPickerName = $().SPServices.SPGetCurrentUser();

    $().SPServices({
    operation: "GetUserProfileByName",
    async: false,
    AccountName: PplpickeraccountName,
    completefunc: function (xData, Status) {

    $("#tblAddNew>tbody>tr").each(function(i,v){
    var tdHtml=$("#tblAddNew tbody tr:nth-child("+(i+1)+")").children("td:nth-child(3)").html();
    //console.log(i+":"+tdHtml);
    if(tdHtml!=undefined){
    if(tdHtml.indexOf(PplpickeraccountName)>-1){
    $(xData.responseXML).find("PropertyData > Name:contains('SPS-JobTitle')").each(function() {
    userJob= $(this).parent().find("Values").text();
    //console.log(i+" userJob:"+userJob);
    $("#tblAddNew>tbody>tr:nth-child("+(i+1)+")>td:nth-child(7) input[type='text']").val(userJob);
    });

    $(xData.responseXML).find("PropertyData > Name:contains('EnglishDivision')").each(function() {
    userDivision= $(this).parent().find("Values").text();
    //console.log(i+" userDivision:"+userDivision);
    $("#tblAddNew>tbody>tr:nth-child("+(i+1)+")>td:nth-child(5) input[type='text']").val(userDivision);
    });

    $(xData.responseXML).find("PropertyData > Name:contains('OracleNumber')").each(function() {
    userEmployeeNumber= $(this).parent().find("Values").text();
    //console.log(i+" userDivision:"+userDivision);
    $("#tblAddNew>tbody>tr:nth-child("+(i+1)+")>td:nth-child(4) input[type='text']").val(userEmployeeNumber);
    });

    $(xData.responseXML).find("PropertyData > Name:contains('Department')").each(function() {
    userDepartment = $(this).parent().find("Values").text();
    userDeptValue.push(userDepartment);
    //console.log(i+" userDivision:"+userDivision);
    $("#tblAddNew>tbody>tr:nth-child("+(i+1)+")>td:nth-child(6) input[type='text']").val(userDeptValue[0]);
    });


    }
    }
    userDeptValue=[];
    });

    //console.log("Response XML:",PplpickeraccountName,",",xData.responseXML);

    }

    });

    }

    // ABOVE CODE CALL OUTSIDE DOCUMENT.READY AND CALL BELOW LINE INSIDE DOCUMENT.READY

    invokeAfterEntityEditorCallback(onPeoplePickerFieldSet);

    Hope it helps someone :) it works in 2010, not tested in 2013/2016/2019


    Harshavardhan


    Friday, July 3, 2020 8:30 AM