none
SharePoint 2013 - REST API - Retrieve People Picker Name RRS feed

  • Question

  • Hello Community,

    I am working in SharePoint 2013, and I am using REST API to retrieve the name property from a People Picker field.  Using the query string below in Postman I am able to retrieve the name field from the People Picker control:

    https://projects.dliflc.edu/prgm/provost/CampaignPlan/_api/web/lists/getbytitle('Master Tasks')/items?$select=AO_x0020_Assigned/Title&$expand=AO_x0020_Assigned/Id

    However, when I incorporate this Query String in my code the value comes back undefined (see code below):

    <script type="text/javascript" src="//code.jquery.com/jquery-1.12.0.min.js"></script>
    <script type="text/javascript" src="/prgm/provost/CampaignPlan/SiteAssets/JQuery/jquery-dateFormat.min.js"></script>
    <script type="text/javascript">
        function getListDetails() {
            $.ajax({
                url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Master Tasks')/items"
    				+ "?$select=Status,Task_x0020__x0023_,vOrganization,vLOE,MoP_x0020_Goal,"
    				+ "MoP_x0020_Status,MoE_x0020_Goal,MoE_x0020_Status,Last_x0020_Modified1," 
    				+ "Priority,AO_x0020_Assigned/Title&$expand=AO_x0020_Assigned/Id"
    				,
                method: "GET",
                headers: {
                    "Accept": "application/json; odata=verbose" 
                },
                success: function(data) {
                    var listItemInfo = "<table><tbody><tr class='Header'><td>Status</td><td>Task #</td>"
    					+ "<td>Org</td><td>LOE</td><td>AO Assigned</td><td>Priority</td><td>MOP Goal</td>"
    					+ "<td>MOP Status</td><td>MOE Goal</td><td>MOE Status</td><td>Last Mod</td></tr>";
    
                    $.each(data.d.results, function(key, value) {
                        listItemInfo += "<tr><td>" + value.Status 
    					+ "</td><td>" + value.Task_x0020__x0023_ 
    					+ "</td><td>" + value.vOrganization
    					+ "</td><td>" + value.vLOE
    					+ "</td><td>" + value.AO_x0020_Assigned.Title
    					+ "</td><td>" + value.Priority
    					+ "</td><td>" + Math.floor((value.MoP_x0020_Goal) * 100) + "%" 
    					+ "</td><td>" + Math.floor((value.MoP_x0020_Status) * 100) + "%" 
    					+ "</td><td>" + Math.floor((value.MoE_x0020_Goal) * 100) + "%" 
    					+ "</td><td>" + Math.floor((value.MoE_x0020_Status) * 100) + "%"  
    					+ "</td><td>" + $.format.date(value.Last_x0020_Modified1, "d MMM yyyy, h:mm a") 
    					+ "</td></tr>";					
    			
                    });
    				
    				listItemInfo += "</tbody></table>"
    
                    $("#listItems").html(listItemInfo);
                },
                error: function(data) {
                    alert('An Error Has Occured');
                }
            });
        }
        _spBodyOnLoadFunctionNames.push("getListDetails");
    </script>
    

    Can anyone help resolve this issue? Please provide code examples and guidance.

    Thanks!

    Tom


    Tom Molskow - Senior SharePoint Architect - Microsoft Community Contributor 2011 and 2012 Award - Linked-In - SharePoint Gypsy

    Monday, March 20, 2017 6:13 PM

Answers

  • Hi Tom

    Try the below code, in the expand parameter only pass the name of the column:

    <script type="text/javascript" src="//code.jquery.com/jquery-1.12.0.min.js"></script>
    <script type="text/javascript" src="/prgm/provost/CampaignPlan/SiteAssets/JQuery/jquery-dateFormat.min.js"></script>
    <script type="text/javascript">
        function getListDetails() {
            $.ajax({
                url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Master Tasks')/items"
    				+ "?$select=Status,Task_x0020__x0023_,vOrganization,vLOE,MoP_x0020_Goal,"
    				+ "MoP_x0020_Status,MoE_x0020_Goal,MoE_x0020_Status,Last_x0020_Modified1," 
    				+ "Priority,AO_x0020_Assigned/Title&$expand=AO_x0020_Assigned"
    				,
                method: "GET",
                headers: {
                    "Accept": "application/json; odata=verbose" 
                },
                success: function(data) {
                    var listItemInfo = "<table><tbody><tr class='Header'><td>Status</td><td>Task #</td>"
    					+ "<td>Org</td><td>LOE</td><td>AO Assigned</td><td>Priority</td><td>MOP Goal</td>"
    					+ "<td>MOP Status</td><td>MOE Goal</td><td>MOE Status</td><td>Last Mod</td></tr>";
    
                    $.each(data.d.results, function(key, value) {
                        listItemInfo += "<tr><td>" + value.Status 
    					+ "</td><td>" + value.Task_x0020__x0023_ 
    					+ "</td><td>" + value.vOrganization
    					+ "</td><td>" + value.vLOE
    					+ "</td><td>" + value.AO_x0020_Assigned.Title
    					+ "</td><td>" + value.Priority
    					+ "</td><td>" + Math.floor((value.MoP_x0020_Goal) * 100) + "%" 
    					+ "</td><td>" + Math.floor((value.MoP_x0020_Status) * 100) + "%" 
    					+ "</td><td>" + Math.floor((value.MoE_x0020_Goal) * 100) + "%" 
    					+ "</td><td>" + Math.floor((value.MoE_x0020_Status) * 100) + "%"  
    					+ "</td><td>" + $.format.date(value.Last_x0020_Modified1, "d MMM yyyy, h:mm a") 
    					+ "</td></tr>";					
    			
                    });
    				
    				listItemInfo += "</tbody></table>"
    
                    $("#listItems").html(listItemInfo);
                },
                error: function(data) {
                    alert('An Error Has Occured');
                }
            });
        }
        _spBodyOnLoadFunctionNames.push("getListDetails");
    </script>

    Regards

    Paramdeep Singh


    SharePoint Architect

    Monday, March 20, 2017 6:59 PM