locked
get user ID numbers in REST API RRS feed

  • Question

  • Hello,

    I have a requirement. I need to update a list item with REST API.

    The list has a people picker that accepts multi value. So, in rest API, I am able to do this by putting the numbers for users specific to the User Information List. However, as I need to copy this item to other list then how can I get these IDs dynamically?

    Please help


    For anything related to SharePoint https://www.fiverr.com/rashu268

    Friday, October 26, 2018 5:15 PM

All replies

  • Hi Rahul. When you use REST API to get the list information, you would just need to use $expand in your call on the field that captures the people picker. You then iterate through them (since it's multi-select) and pick the ID field.

    Please remember to mark as answer if you found this to be helpful. Andy Wessendorf | Belcan

    Friday, October 26, 2018 7:32 PM
  • I hope they help

    https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/get-user-identity-and-properties-in-sharepoint

    https://sharepoint.stackexchange.com/questions/164818/get-user-profile-picture-url-using-id-csom?rq=1


    Please remember to click Mark as Answer on the answer if it helps you

    Friday, October 26, 2018 8:35 PM
  • Hi Rashu,

    User ID can be got from Rest API response directly:

    In the page, we could use Jquery ajax to get these multiple value person field like this:

    <script src="https://code.jquery.com/jquery-3.3.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function(){
    var items= getUsersID();
    $.each(items,function(index,item){
            console.log(item.multiusersId.results);
        })
    });
    function getUsersID(){
    	var items;
    	var url =_spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbyTitle('MyList4')/items";
    	$.ajax({
    		url: url,
    		method: "GET",
    		async: false,
    		headers: { "Accept": "application/json; odata=verbose" },
    		success: function (data) {
    			items= data.d.results;
                           //console.log(items);		
    		},
    		error: function (data) {
    		}
    	});
    	return items;
    }
    
    </script>
    

    This code snippet will return the multiple person field user Id as a array as this field is multiple value, then you could pass this array to update into another list.

    Thanks

    Best Regards


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


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Monday, October 29, 2018 8:50 AM
  • Hi,

     

    I am checking to see how things are going there on this issue. Please let us know if you would like further assistance.

     

    You can mark the helpful post as answer to help other community members find the helpful information quickly.

     

    Thanks

     

    Best Regards


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


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Tuesday, October 30, 2018 2:03 PM