0

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>";
4

2 に答える 2

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>";
于 2012-06-11T15:11:33.383 に答える
0

問題は CAML クエリではなく、日付の解析にあります。残念ながら、JavaScript の Date.toString メソッドは、C# と同じ方法で書式設定をサポートしていません。toString メソッドは引数を受け入れないため、自分で有効な ISO 形式に解析する必要があります。

ISODateString メソッドは、Javascript で ISO-8601 形式の文字列を出力するにはどうすればよいですか?という質問から取得しました。. このメソッドを使用して、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 クエリで期待される形式であるため、日付でフィルター処理されたアイテムを取得できるようになりました。

于 2012-06-10T10:12:40.153 に答える