SharePoint - CAML

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-DD\Thh:mm:ss\Z,例如: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);
View Code

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. 

 

转载于:https://www.cnblogs.com/qijiage/p/4059462.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值