Querying the “Person or Group” field using SPQuery (Update)

One of the weak points of Sharepoint 2007 is documentation. If you want to query a “Person or Group” field, the documentation on MSDN is a bit sparse.
Here is how to query a person:

<where>
  <eq>
    <fieldref name="PersonFieldName"/>
    <value type="User">User Display Name</value>
  </eq>
</where>
 

Replace PersonFieldName with the internal Name of the Field.
The two important things here: Value Type is “User”, and the String to search for is the Display Name. So if you have a user called “John Doe” whose login is “mydomain\jdoe”, you have to search for “John Doe”, not for “mydomain\jdoe”.
There is an obvious drawback to this: What if you have two users called John Doe?

I was quite disappointed that the Person field does not store the LoginName by default and can therefore not be queried for it.
There are two workarounds. The first one: Go to the properties of the field in the list, and at the bottom you can change “Show Field” to “Account”.
This has the advantage that you can use the “domain\username” Syntax now. The drawback: The field looks bad in the list as it does now show the Login, not the Display Name with the neat presence status.

The second workaround: Use the undocumented LookupId property and search for the numeric ID:

<where>
  <eq>
    <fieldref name="PersonFieldName" LookupId="TRUE"/>
    <value type="int">UserID</value>
  </eq>
</where>

The UserID is not the “domain\username”, but the numeric internal ID (SPUser.ID). As I use this in a workflow, I can easily access this through workflowProperties.OriginatorUser.ID, which is good enough for me.

Update: The second code example was incorrect, I fixed it now.

[备查]使用 SPQuery 查询 "Person or Group" 字段的更多相关文章

  1. SQL查询每个表的字段数量

    --SQL查询每个表的字段数量select b.[name], count(*) As AllCount,ISNULL(ISNULL(sum(case when isnullable=0 then 1 ...

  2. [转]SQL数据库查询到的汉字字段是乱码

    使用英文版SQL数据库查询到的汉字字段是乱码的解决方案 2007-12-04 14:55:45 标签:函数 SQL 数据库 乱码 排序规则 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出 ...

  3. Mysql 单表查询-排序-分页-group by初识

    Mysql 单表查询-排序-分页-group by初识 对于select 来说, 分组聚合(((group by; aggregation), 排序 (order by** ), 分页查询 (limi ...

  4. MongoDB查询操作限制返回字段的方法

    这篇文章主要介绍了MongoDB查询操作限制返回字段的方法,需要的朋友可以参考下   映射(projection )声明用来限制所有查询匹配文档的返回字段.projection以文档的形式列举结果集中 ...

  5. linq查询结果转换为指定字段类型的list集合

    转换查询结果为ProductId字段的类型的list集合 (from s in _db.Mobile_TeamAction || s.ActionStatus == select new { s.Pr ...

  6. Java 通过JDBC查询数据库表结构(字段名称,类型,长度等)

    Java 通过JDBC查询数据库表结构(字段名称,类型,长度等) 发布者:唛唛家的豆子   时间:2012-11-20 17:54:02   Java 通过JDBC查询数据库表结构(字段名称,类型,长 ...

  7. mysql查询order by 指定字段排序

    当MySQL查询时排序的字段不是数字时而是汉字的时候也可以用when  then 来指定排序. 列如yewu_check表的status 字段不是0,1,2而是汉字待办,已办,退回.可以如下写法: S ...

  8. Oracle数据库里面查询字符串类型的字段不为空和为空的SQL语句:

    一:查询字符串类型的字段的值不为空的SQL: select * from TB_CMS_FLGTINFO_A t where (t.fsta is not null and t.fsta <&g ...

  9. Qt+QGIS二次开发:自定义类实现查询矢量数据的属性字段值(图查属性)

    在GIS领域,有两种重要的查询操作,图查属性和属性查图. 本文主要介绍如何在QGIS中通过从QgsMapToolIdentify中派生自定义类实现查询矢量数据的属性字段值(图查属性). 重点参考资料: ...

随机推荐

  1. wireshark 相关提示

    Packet size limited during capture      提示说明标记的包没有抓全,在某些操作系统中,默认只抓96个字节,tcpdump中有"-s"参数可用于 ...

  2. 项目游戏开发日记 No.0x000001

    14软二杨近星(2014551622) 既然已经决定了开发软件, 时不时就要练练手, 还要时不时的去寻找素材, 因为开发的人物设定就是DotA2里面的祈求者, 所以, 就去找了他的相关人物图片和模型, ...

  3. 深入理解Spring MVC

    如何让一个普通类成为Controller? 方案一:实现接口Controller 解析:handleRequest(request,response) 方案二:继承AbstractController ...

  4. 为支持ASP.NET5跨平台,Jexus再添新举措

    Jexus作为一款运行于Linux/FreeBSD平台上,以支持ASP.NET著称的高性能HTTP服务器和反向代理服务器,继5.6版完成对OWIN标准应用的支持后,就把着力点放到了对ASP.NET5的 ...

  5. 从淘宝 UWP 的新功能 -- 比较页面来谈谈 UWP 的窗口多开功能

    前言 之前在 剁手党也有春天 -- 淘宝 UWP ”比较“功能诞生记 这篇随笔中介绍了一下 UWP 淘宝的“比较”新功能呱呱坠地的过程.在鲜活的文字背后,其实都是程序员不眠不休的血泪史(有血有泪有史) ...

  6. Web应用多账号系统设计及微信扫码登录实现

    Web应用多账号系统设计及微信扫码登录实现 1   前言概述 公司对功能测试,性能测试,安全测试等等都做了比较好的自动化后,急需要一个MIS系统来统一管理这些结果及报表. 此MIS系统特点如下: 仅内 ...

  7. ReactNative&weex&DeviceOne对比

    React Native出来有一段时间了,国内的weex和deviceone是近期发布的,我可以说从2011年就开始关注快速开发的跨平台平台技术了,接触过phoneGap.数字天堂.appcan等早期 ...

  8. IOCP Internals

    Buffer Type Buffer I/O 针对Buffer I/O的请求,系统会为其分配一个非换页内存作为缓存区,其大小等同于I/O请求的缓存区大小.对于写操作,I/O管理器在创建IRP时,将请求 ...

  9. 【初探Spring】------Spring IOC(一)

    IOC:Inversion of Control(控制反转).IOC它所体现的并不是一种技术,而是一种思想,一种将设计好的对象交给容器来管理的思想.IOC的核心思想就体现在控制.反转这两个词上面,要理 ...

  10. struts debug 标签

    < s:debug> 引起下面的错误 org.apache.jasper.JasperException: Caught an exception while getting the pr ...