CAML查询肥皂SharePoint

时间:2012-06-08 20:48:31

标签: sharepoint soap

我正在尝试访问SharePoint列表并返回我制作的自定义Web部件的日历日期。它工作正常,然后我决定只检索所选日期而不是整个日历,所以我想添加一个where子句。

我试过'yyyy-MM-dd','yyyy-MM-ddThh:mm:ssZ','yyyy-MM-dd hh:mm:ssZ'作为字符串格式 我也试过MM / dd / yyyy作为日期格式。

我正在使用jQuery,我在日历中确实有列表项。我假设我的日期格式不正确。

        var date = $(this).attr('date');            

        var sharepointDate = Date.parse(date).toString('yyyy-mm-ddT00:00:01Z');
        var soapEnv =
            "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
            <soapenv:Body> \
            <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
            <listName>CorporateCalendar</listName> \
            <viewFields> \
            <ViewFields> \
            <FieldRef Name='Title' /> \
            </ViewFields> \
            </viewFields> \
            <query><Query><Where><Geq><FieldRef Name='EventDate' /><Value Type='DateTime'>" + sharepointDate + "</Value></Geq></Where></Query></query> \
            <rowLimit>500</rowLimit> \
            </GetListItems> \
            </soapenv:Body> \
            </soapenv:Envelope>";

如果我拿出where子句,我会收到日历中的所有项目。如果查询在那里,我没有收到任何结果。

提前致谢

工作代码:

    var sharepointDate = Date.parse(date).toString('yyyy-MM-dd');
        var soapEnv =
            "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
            <soapenv:Body> \
            <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
            <listName>CorporateCalendar</listName> \
            <viewFields> \
            <ViewFields> \
            <FieldRef Name='Title' /> \
            </ViewFields> \
            </viewFields> \
            <query><Query><Where><Eq><FieldRef Name='EventDate' /><Value Type='DateTime' IncludeTimeValue='False'>" + sharepointDate + "</Value></Eq></Where></Query></query>\
            <rowLimit>1500</rowLimit> \
            </GetListItems> \
            </soapenv:Body> \
            </soapenv:Envelope>";

2 个答案:

答案 0 :(得分:0)

问题不在于您的CAML查询,而在于解析日期。不幸的是,JavaScript中的Date.toString方法不支持格式化,就像C#一样。 toString方法不接受任何参数,因此您必须自己将其解析为有效的ISO格式。

我从问题How do I output an ISO-8601 formatted string in Javascript?中获取了ISODateString方法。我们可以使用此方法获取sharepointDate的有效值,代码应如下所示:

function ISODateString(d){
 function pad(n){return n<10 ? '0'+n : n}
 return d.getUTCFullYear()+'-'
      + pad(d.getUTCMonth()+1)+'-'
      + pad(d.getUTCDate())+'T'
      + pad(d.getUTCHours())+':'
      + pad(d.getUTCMinutes())+':'
      + pad(d.getUTCSeconds())+'Z'}
var sharepointDate = ISODateString(new Date(Date.parse(date)));

现在,sharepointDate将采用'yyyy-mm-ddT00:00:01Z'格式。由于这是CAML查询中预期的格式,您现在可以获取在日期过滤的项目。

答案 1 :(得分:0)

    var sharepointDate = Date.parse(date).toString('yyyy-MM-dd');
        var soapEnv =
            "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
            <soapenv:Body> \
            <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
            <listName>CorporateCalendar</listName> \
            <viewFields> \
            <ViewFields> \
            <FieldRef Name='Title' /> \
            </ViewFields> \
            </viewFields> \
            <query><Query><Where><Eq><FieldRef Name='EventDate' /><Value Type='DateTime' IncludeTimeValue='False'>" + sharepointDate + "</Value></Eq></Where></Query></query>\
            <rowLimit>1500</rowLimit> \
            </GetListItems> \
            </soapenv:Body> \
            </soapenv:Envelope>";