.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Queries using lookup field

Posted By:      Posted Date: October 06, 2010    Points: 0   Category :SharePoint

Is it possible to write queries that use IDs instead of text values (Title) when comparing values of lookup fields?

For example: I want to get all items from a list with a Category set to "Category A" (which has an ID=1). Category is a lookup field in this case.
The query I would want to use would look like this:
"<Where><Eq><FieldRef Name='Category' /><Value Type='Text'>1</Value></Eq></Where>"
This of course doesn't return anything, because instead I need to use this:
"<Where><Eq><FieldRef Name='Category' /><Value Type='Text'>Category A</Value></Eq></Where>"

The question is - is there a way of building queries using IDs of lookup fields rather than the text values?

View Complete Post

More Related Resource Links

How do you update a Lookup Field from CAML by Name rather than ID

Hi, I have the following batch update in my code: xml += "<Method ID='" + currentID + "' Cmd='Update'>"; xml +=   "<Field Name='ID'>" + ID + "</Field>"; xml +=   "<Field Name='FileRef'>" + fileRef + "</Field>"; xml +=   "<Field Name='Title'>" + doc.NewFileName + "</Field>"; xml += "<Field Name='Keywords'>" + doc.Keywords + "</Field>"; xml +=   "<Field Name='Select_x0020_Type'>" + ((doc.TypeName == "General") ? 1 : 2) + "</Field>"; xml +=   "<Field Name='Population'>" + "Demography" + "</Field>"; xml += "</Method>"; The Population field is a lookup. It works if I put the ID of the ListItem in there, but not if I put the name - I need to put the name in. Can anyone help? Thanks. John.  

DataView WebPart with lookup and person field

Hi I want to insert a dataview webpart, using REST, referring to a list with look-up fields and people fields. The results I receive are the ID's instead of the values. How can I get back the corresponding values? TIA Sjokke

WSS Lists - Lookup field information missing in Excel 2010

Hi, I've got this xls workbook which contains a two-way synchronized SharePoint list. This WSS list contains columns which are related to other lists: for instance the list we're using is a list of assignments, where an assignment is related to an accounting period. Our server also has another list with all accounting periods. Both lists are related since the assignment list as an accounting period column of lookup type which uses the accounting period list as a source. In previous versions of Excel, the output is that the accounting period field is a combobox populated with all availalble accounting periods. Thanks to that, the user can easily link an assignment to an accounting period by selecting a value in this combobox and synchronizing. This works great with Excel 2003 and 2007, however in 2010 (same workbook, consuming the same lists) related information doesn't appear. The combobox is empty and as a consequence the user gets a data validation error since the value in the cell isn't among available values. Is there something special I should do to enable this feature in Excel 2010? Regards, Carl 

SharePoint Designer 2007 Workflow needs to initialize lookup field value and store it

This is for a governance tracking list. I have two tables: Roadmap and Roadmap Status In Roadmap, there are two fields of interest that are lookup fields to Roadmap Status:Title they are Status and OldStatus When an item is entered in Roadmap, I want to force the initial Status to "Submit" from Roadmap Status. I don't see any way in my workflow to to lookup that item in Roadmap Status and place the pointer (I'm assuming it is a GUID) into the field. The value is also stored in OldStatus to catch changes as I'm trying to force order of status in a few cases but not all. I'm doing it with a Lookup instead of Choice because the business tends to change the terminology they like and this way I don't change it in several places plus it allows them to change it in the list instead of someone changing the list field values. I've seen several places on the forum where people have a similar problem and Lambert Qin has given an answer but it never fits this scenario exactly. Do I have to go back to Choice columns? I only have Designer and would rather not have to learn another tool for a simple SharePoint implementation. Thanks for any help!

Lookup field issue after restore

After restoring a site collection in MOSS 2007, lookup fields cannot link up with the parent list. May I know if this problem fixed in MOSS 2010? Besides, the list item GUID in MOSS 2007 are changed after restoring. Does this case still appear in MOSS 2010? Thanks!

Lookup field with drop downs

Hi, I have created a lookup called projectname in a list called status. This projectname selects it's value from the project list. There are 2 fields on this list that are drop down list of values that I want to appear in the status list as lookups based on the projectname. However any special field types such as person or drop down list don't seem to appear, it looks like you can only show the related text fields? Is there anyway around this? Many Thanks, Michael  

Issue Adding a new Lookup Field to an existing List Instance

I have a code base that houses all of the column, content types, template, and list instance definitions. Am using the Update functionlaity a lot from version to version. Has been working well to this point. I just added two new columns (fields), one a Lookup and the other a Multi-Lookup. The fields are added fine on the update, columns look correct and the content type to which these were added also look fine. I can create a new List instance from the content type, and the new lookup columns are fine. The problem is this. Any existing list instances that were created from this same content type, now blow up when I try and access list items via the SP GUI. Something about a valid GUID, I dont't have the exect error anymore, but will repost it when I recreate the issue for the tenth time. I tried deleting the new lookup fields from this new list instance, thinking that I might be able to re-add them to fix the problem, but I get a new stack trace when I try and re-add them. Any hints on where I can start digging would be appreciated. I think I'll start with comparing the list instance schemas between an existing list and a newly created one.  

Join linq queries with same field name

Hi everyone-I'm trying to join three Linq queries together.  One of the fields (rating) is the same name for each so when I add b.rating as you'll see below, I get a squiggly that says "Anonymous type member or property 'rating' is alread declared.   Dim customerCategoryA= (From a In dc.CategoryARatings _                                  Where a.userID = userID _                                  Select New With {a.productID, a.rating, a.ratingComment}) Dim customerCategoryB = (From b In dc.CategoryBRatings _                                 Where b.userID = userID _                                 Select New With {b.productID, b.rating}) Dim DataForGridview = From p In Products _   

lookup field list instance



Got and problem with and lookupfield I create some list instances, list definitions, content types with a lookupfields and all works fine  the list resovels the good list source guid so I can selected te values but when I try to save I get;

<nativehr>0x80070057</nativehr><nativestack></nativestack>Invalid data has been used to update the list item. The field you are trying to update may be read only.

When I manualy create a new list instance from the list definition everything works fine.
I'm guessing that the create list instances in the feature is causing the problem?

What am I doing wrong?


update a lookup field from different site


class FeatureReceiver:SPFeatureReceiver


public override void FeatureActivated(SPFeatureReceiverProperties properties)


SPList _SPList = (SPList)properties.Feature.Web.Lists["DestinationList"];

_SPList.ParentWeb.AllowUnsafeUpdates = true;

 using (SPSite oSiteCollection = SPContext.Current.Site) // or give a destination site collection here...
                     using (SPWeb oWebsiteRoot = oSiteCollection.OpenWeb("/sites/Source1/Source11"))
                        SPList oList = oWebsiteRoot.Lists["SourceProjectList"];

# string with cross site lookup field value of List in datasheet view in moss 2007

I am getting appended # code value with cross site lookup field value of List in datasheet view, and also i am getting this value while export to Spreadsheet. How to remove this value.....

# string with cross site lookup field value of List in datasheet view in moss 2007


I am getting appended # code value with cross site lookup field value of List in datasheet view. I dont want that hash coded value, i need actual value. Please provide me the solution.



Rajanikanth Rayala

Cross site lookup field value contains the parent list item id and the title field separated by ;# i

Actually we are using third party component for cross site lookup and facing the problem with cross site lookup field value. Its showing the correct value in default list view mode, but in "Edit in Datasheet" and "Export to Datasheet" view cross site lookup field value contains the parent list item id and the title field separated by ;#. I need the actual value in "Edit in Datasheet" and "Export to Datasheet" view as shown in default list value, i dont want that appended parent list item id and separated by ;#.

Is there any OutOfBox soluiton for this. Please suggest me for the same.


Programmatically remove link from lookup field

I've found this link describing an approach to remove the link from a lookup field via javascript. Is there an other way except adding a content editor webpart to every site with lookup fields? Like setting a property for the lookup field? Thanks

FullTextSqlQuery using Multi-Valued Lookup Field

Hi There,

I have written a bespoke search webpart powered by the Enterprise Search FullTextSqlQuery object (MOSS 2007). Everything is working well apart from one slight hiccup:

Part of the requirement is to be able to filter the result set using the value of a metadata property on the list items. This property is of the  Multi-Valued Lookup type. A user would assign one or more lookup values to the item and then would expect it to be returned in the search results when one or more of these values matches the filter criteria.

I've looked all over Google and I can't find any examples of where a multi-valued lookup field has been used in the WHERE clause of a full text sql query. Could anyone point me in the right direction?

Thanks very much,


UpdateListItems to populate multivalue in the lookup field of the list



I want to populate a column which is of type lookup.I used the web service provided by the sharepoint. This column should contain multiple values. For this I used the format ID;#lookupvalue.But the column is not getting populated.

The elbatch.InnerXML looks like IS

"<Method ID=\"2\" Cmd=\"New\"><Field Name=\"RFPRequirement\" Type=\"Lookup\">623</Field><Field Name=\"Product\" Type=\"Lookup\">232</Field><Field Name=\"Offering\" Type=\"Lookup\">49</Field><Field Name=\"Services\" Type=\"Lookup\">212;#B: Event Management Service;#215;#(B) Incident Management Service;#217;#(B) Proactive Problem Management Service</Field></Method>"

Also I tried separating only the IDs by ;#.The elbatch.innerxml is

"<Method ID=\"2\" Cmd=\&q

Lookup field which allows multiple choice - problem when query with CAML


I created one simple list and added one column - lookup - I've chosen some source list and field, then marked "Allow multiple choice". I created new item in that list, by adding more than one valie to that coulm.

The problem is, when I use CAML query, that column has such values:


and it's suppose to be like this:


do You have any idea, why it doesn't query first ID?

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend