1. CAML是顺序操作,如果要实现类似 “A or B or C or D” 的结果,最好写成 “(((A or B) or C) or D)”的形式,但写成 “((A or B) or (C or D))” 也可以正常工作;
2. CAML中对时间操作时,时间格式为 “yyyy-MM-ddTHH:mm:ssZ”,需要注意T和Z都需要大写,例如:2014-10-29T14:45:00Z;但是,SharePoint数据库中的DateTime类型数据格式为:YYYY-MM-DD hh:mm:ss,例如:2015-05-12 03:45:09;因此在使用Caml进行查询时,需要先将datetime字段值转换为ISO Format,即 YYYY-MM-DDThh:mm:ss,例如:2015-05-12T03:45:09Z;然后再进行查询操作,否则不起作用
3. 以下代码用于检测当前时间段内的会议室是否已被预订:
var camlQuery = new SP.CamlQuery(); var queryXML= "<View><Query>" + "<ViewFields>" + "<FieldRef Name='Title' />" + "<FieldRef Name='EventDate' />" + "<FieldRef Name='EndDate' />" + "<FieldRef Name='Meeting_x0020_Room' />" + "<FieldRef Name='ID'/>" + "</ViewFields>" + "<Where>" + "<And>" + "<Or>" + "<Or>" + "<Or>" + "<And>" + "<Leq>" + "<FieldRef Name='EventDate' />" + "<Value Type='DateTime' IncludeTimeValue='TRUE'>" + startDateTime +"</Value>" + "</Leq>" + "<Gt>" + "<FieldRef Name='EndDate' />" + "<Value Type='DateTime' IncludeTimeValue='TRUE'>"+ startDateTime +"</Value>" + "</Gt>" + "</And>" + "<And>" + "<Lt>" + "<FieldRef Name='EventDate' />" + "<Value Type='DateTime' IncludeTimeValue='TRUE'>"+ endDateTime +"</Value>" + "</Lt>" + "<Geq>" + "<FieldRef Name='EndDate' />" + "<Value Type='DateTime' IncludeTimeValue='TRUE'>"+ endDateTime +"</Value>" + "</Geq>" + "</And>" + "</Or>" + "<And>" + "<Geq>" + "<FieldRef Name='EventDate' />" + "<Value Type='DateTime' IncludeTimeValue='TRUE'>"+ startDateTime +"</Value>" + "</Geq>" + "<Leq>" + "<FieldRef Name='EndDate' />" + "<Value Type='DateTime' IncludeTimeValue='TRUE'>"+ endDateTime +"</Value>" + "</Leq>" + "</And>" + "</Or>" + "<And>" + "<Leq>" + "<FieldRef Name='EventDate' />" + "<Value Type='DateTime' IncludeTimeValue='TRUE'>"+ startDateTime +"</Value>" + "</Leq>" + "<Geq>" + "<FieldRef Name='EndDate' />" + "<Value Type='DateTime' IncludeTimeValue='TRUE'>"+ endDateTime +"</Value>" + "</Geq>" + "</And>" + "</Or>" + "<Eq>" + "<FieldRef Name='Meeting_x0020_Room' />" + "<Value Type='Lookup'>"+ meetingRoom +"</Value>" + "</Eq>" + "</And>" + "</Where>" + "</Query></View>"; camlQuery.set_viewXml(queryXML); this.collListItem = oList.getItems(camlQuery);
4. 判断People类型字段的值是否等于当前用户:
<Eq> <FieldRef Name="Filter_Users"/> <Value Type="Integer"> <UserID/> </Value> </Eq>
5. 判断当前用户是否属于People类型字段中的一员(Filter_Users是一个People类型字段,允许多选,包含User和Group):
<Membership Type="CurrentUserGroups"> <FieldRef Name="Filter_Users"/> </Membership>
6. 在CAML语句中使用Lookup字段进行查询时,并不需要做特殊处理,只需要注明字段类型为Lookup,然后使用字段值直接进行查询即可,类似普通的单行文本(Text类型);
<Eq> <FieldRef Name='Location' /> <Value Type='Lookup'>Room-1</Value> </Eq>
7.