Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am trying to retrieve a list of items including lookup fields via listdata.svc. My lookup points to a list of companies which has the following fields: Title, Address, Phone.

By default, listdata doesn't return the lookup data, only a link to it. If I use the $expand parameter, then listdata returns all the fields of the lookup.

How can I make listdata return the lookup title only, not the other fields like address and phone?

share|improve this question
add comment

2 Answers

up vote 9 down vote accepted

This page has some good examples on using listdata.svc and specific examples on drilling down into specific items to be selected.

Using the REST Interface

Examples from page

Using code:

var query = (DataServiceQuery<InventoryLocationsItem>)context.
    CreateQuery<InventoryLocationsItem>("InventoryLocations")
       .Expand("Part")
       .AddQueryOption("$select", 
                       "BinNumber,Quantity,Title,Id,PartId,Part/SKU,Part/Title")
       .Where(p => p.Part.SKU.StartsWith(SearchSku)).OrderBy(p => p.Part.SKU);

Manually constructing the URL:

http://contoso/sites/sharepointlist/_vti_bin/listdata.svc/InventoryLocations()
  ?$filter=startswith(Part/SKU,'sku')
    &$orderby=Part/SKU
      &$expand=Part
        &$select=BinNumber,Quantity,Title,Id,PartId,Part/SKU,Part/Title
share|improve this answer
    
thx, I'll try this. The [list]/[column] notation seems to be what I'm looking for. –  Christophe Dec 29 '11 at 1:02
    
Worked great! Do you happen to know how to get rid of the _metadata? –  Christophe Dec 29 '11 at 1:29
    
Unfortunately, no, I do not know how to get rid of the _metadata. –  Alban Dec 29 '11 at 15:27
add comment

Assuming that the Title is the "foreign key" don't you already have that value in the primary list? Alternatively, don't you get the values if you add the other columns to the Lookup column to pull them across with the key?

share|improve this answer
    
No you don't (contrary to what Web services will do for example). You don't get the lookup id either. Let's say that REST services are very "performance concious" ;-) –  Christophe Dec 29 '11 at 0:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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