4

I have a Sharepoint list that has a multi value field which stores Person or Group.

In the GET call to the Sharepoint list, I get the following response. Collaborators is the name of the field in discussion.

                "Id": 1,
            "ContentTypeId": "0x0100B86E441274F847A599E46276483F9FBB009692E8772BC86A4F8BB8570C018F79BC",
            "Title": "One Microsoft Way",
            "StartDate": "2015-04-15T06:55:19Z",
            "EndDate": "2015-04-15T06:55:19Z",
            "CollaboratorsId": {
                "results": [
                    18
                ]
            },
            "ID": 1,
            "Modified": "2015-04-15T06:55:26Z",
            "Created": "2015-04-15T06:55:26Z",
            "AuthorId": 1,
            "EditorId": 1,

I get an array of IDs in the response, but I wish to expand that field to show the Person or Group name. I tried to use $expand=Collaborators&$select=Collaborators/Title. But this does not work.

Any way to expand the values in a multi-value field?

  • 1
    Just to confirm, this is a People Picker in which you can select multiple people, correct? – wjervis Apr 17 '15 at 12:45
  • Yes. Collaborators is a people picker field with multiple people. – Omkar Khair Apr 19 '15 at 4:53
2

Try this sample

var call = $.ajax({
    async: false,
    url: _spPageContextInfo.webAbsoluteUrl 
    + "/_api/Web/Lists/GetByTitle('AppointmentInfo')/items"
    + "?$select=Id,Collaborators/Id, Collaborators/Title,Title"
    + "&$expand=Collaborators/Id",
    type: "GET",
    dataType: "json",
    headers: {
      Accept: "application/json;odata=verbose"
    }
});

call.done(function(data, textStatus, jqXHR) {
    var items = data.d.results;
    for (var i = 0; i < items.length; i++) {          
      var CollaboratorsArray = items[i].Collaborators.results;
      for (var j = 0; j < CollaboratorsArray.length; j++) {
        console.log(Collaborators[j].Id + ' - ' + Collaborators[j].Title);
      }       
    }
});
  • Tried it. Doesnt work. :( – Omkar Khair Apr 20 '15 at 10:29
  • Expanding on Id did work, but only after I created a new list. Solved my problem though. – Omkar Khair Apr 29 '15 at 6:30
2

Its should be

$select=Collaborators/Title&$expand=Collaborators

Example your URL should like

 http://yoursite/_api/web/lists/GetByTitle('Employee Details')/items("1")?$select=ManagerName/Title,FirstName,LastName,Position,Phone,Fax,PreviousCompany,Reference,BirthDate,Relocate,EmailAddress&$expand=ManagerName
  • I am trying exactly that. Note that I am dealing with a multi select field. Also, I don't think the order of expand and select queries matter. – Omkar Khair Apr 17 '15 at 10:03
  • you are missing a "$" before a select its not about reordering – Akshay Randive Apr 17 '15 at 12:02
  • Sorry, I missed the $ while posting the question. I'm using it in my query. Here is my exact url mydomain/sites/demosite/_api/web/lists/… – Omkar Khair Apr 17 '15 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.