SharePoint: In a CAML query, filter by lookup item ID, not by its value
2011-11-15 15:09
411 查看
Your filter for the CAML query probably looks like this currently:
But the "Customer" field is a lookup column to a different list of customers and on most view pages for customers, you probably need to fetch the related data using the Customer ID (the ID column for the customer list) and not the customer name.
Also, Sharepoint designer 2007 does not, using the UI, allow you to set a filter on a data form webpart and using a lookup column's ID field. You can only use the value of a lookup column in the filter.
Here's how I was able to do it after a bit of research...
Just add the LookupId = "true" attribute to the FieldRef tag and change the Value Type attribute to "Lookup". Your filter now looks up the value of the lookup column by using the ID of the item instead of the value.
http://www.vishalseth.com/post/2009/12/02/SharePoint-In-a-CAML-query-filter-by-lookup-item-ID-not-by-its-value.aspx
<Query> <Where> <Eq> <FieldRef Name ="Customer"/> <Value Type ="Text"> Dunder Mifflin </Value> </Eq> </Where> </Query>
But the "Customer" field is a lookup column to a different list of customers and on most view pages for customers, you probably need to fetch the related data using the Customer ID (the ID column for the customer list) and not the customer name.
Also, Sharepoint designer 2007 does not, using the UI, allow you to set a filter on a data form webpart and using a lookup column's ID field. You can only use the value of a lookup column in the filter.
Here's how I was able to do it after a bit of research...
<Query> <Where> <Eq> <FieldRef Name ="Customer" LookupId="true" /> <Value Type ="Lookup"> 15 </Value> </Eq> </Where> </Query>
Just add the LookupId = "true" attribute to the FieldRef tag and change the Value Type attribute to "Lookup". Your filter now looks up the value of the lookup column by using the ID of the item instead of the value.
http://www.vishalseth.com/post/2009/12/02/SharePoint-In-a-CAML-query-filter-by-lookup-item-ID-not-by-its-value.aspx
相关文章推荐
- 学习:CAML – Query Lookup Field by ID; not by Value (转)
- ERROR: The node /hbase is not in ZooKeeper. It should have been written by the master. Check the val
- Android - 警告:it is always overridden by the value specified in the Gradle build script
- invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause
- Request header field sessionId is not allowed by Access-Control-Allow-Headers in preflight response.
- SharePoint : This item cannot be deleted because it is still referenced by other pages
- Android - 警告:it is always overridden by the value specified in the Gradle build script
- SharePoint, No item exists at It may have been deleted or renamed by another user.
- sql --it is not contained in either an aggregate function or the GROUP BY clause.
- dict in dict : sort and filter dict by sub-dict value in multi condition
- [SharePoint]javascript client object model 获取lookup 类型的field的值,包括user类型(单人或者多人)的值。how to get the multiple user type/lookup type field value by Javascript client object model
- Can not delete a master page "This item cannot be deleted because it is still referenced by other pa
- error: Apostrophe not preceded by \ (in haven't input accoount or it isn't a legal E-mail)
- dict in dict : sort and filter dict by sub-dict value in multi condition
- Mybatis框架不同命名空间相同查询id出现queryById is ambiguous in Mapped Statements collection
- SharePoint 2010中新增的GetItemByIdSelectedFields方法
- 'ddlCities' has a SelectedValue which is invalid because it does not exist in the list of items
- Populating Display Item Value On Query In Oracle Forms
- SharePoint 2010中新增的GetItemByIdSelectedFields方法
- Hint: A potential Change-Id was found, but it was not in the footer (last paragraph) of the commit message