SharePoint: In a CAML query, filter by lookup item ID, not by its value

 

Your filter for the CAML query probably looks like this currently:

 

<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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值