1

Sharepoint 2010, Below is my CAML query used in javascript. I like to have the 1st FOLDER which is greater or equal to TODAY.

The doclib- view contains a column MeetingDate (type: datetime) which I fill in the date as below. e.g. yesterday it was 28/09/2015. I like to get the folder/row 28/09/2015 selected in my CAML query. But it always took 05/10/2015.

I deleted the 05/10/2015 folder then it took 12/10/2015. I also deleted this folder then it took 28/09/2015 which is good. then I recreated the 2 folders 05/10/15 and 12/10/2015 it kept taking the row/foler 28/09/2015 yesterday which is good.

today is 29/09/2015 when I run the code it takes 28/09/15, which is not good , because in my CAML query I use greather or Equal then...

So there is an issue which I can solve it and don't know what the problem is.

in otherwords it looks like caching and keeping. I deleted all my browsers cache tested on other browsers it's still not correct. I tried with order by in CAML without. change to TRUE/FALSE, with offsetdays, without offsetdays... none are giving other results.... always the same result.

EDIT: I only need 1 row back, the row with meetingdate which is greater than or equal to today's date. so when I run this script today (29/09/2015) it should give me 1 row which is 05/10/2015. Greater than Today and rowlimit =1.

Can someone advice?

e.g.

Name MeetingDate

Folder1 12/10/2015

Folder2 05/10/2015

Folder3 28/09/2015

Folder4 21/09/2015

    <View Scope="RecursiveAll">
  <Query>
    <Where>
      <And>
        <Eq>
          <FieldRef Name="FSObjType" />
          <Value Type="Integer">1</Value>
        </Eq>
        <Geq>
          <FieldRef Name="MeetingDate"/>
          <Value Type="DateTime">
            <Today OffsetDays="-1"/>
          </Value>
        </Geq>
      </And>
    </Where>
  </Query>
  <RowLimit>1</RowLimit>
  <OrderBy>
    <FieldRef Name="MeetingDate" Ascending ="FALSE"/>
  </OrderBy>
</View>

    var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('DocumentsLIB');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View Scope="RecursiveAll"><Query><Where><And><Eq><FieldRef Name="FSObjType" /><Value Type="Integer">1</Value></Eq><Geq><FieldRef Name="MeetingDate"/><Value Type="DateTime"><Today OffsetDays=-1/></Value></Geq></And></Where></Query><RowLimit>1</RowLimit><OrderBy><FieldRef Name="MeetingDate" Ascending ="FALSE"/></OrderBy></View>');
this.collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

function onQuerySucceeded(sender, args) {
var listItemInfo = '';
var folderName = '';
var listItemEnumerator = collListItem.getEnumerator();

while (listItemEnumerator.moveNext()) {
    var oListItem = listItemEnumerator.get_current();
    folderName = oListItem.get_item('Title');
//    I always get 1 record back, which is good, but it's wrong;
}

var urlOfTheDocumentsMT = "http//myurlsite";
document.getElementById("current-documentsmt").href = urlOfTheDocumentsMT + folderName

}

2 Answers 2

2
  1. <Today OffsetDays="-1"/> Here you are saying OffsetDays="-1", which means yesterday. So your caml query will bring all items which is greater than equal to yesterday. You need to change it to : <Today/> .

  2. Secondly your <OrderBy> is not valid since it is outside <Query>. It should be inside the <Query>.

Below is the corrected query:

<View Scope="RecursiveAll">
  <Query>
    <Where>
      <And>
        <Eq>
          <FieldRef Name="FSObjType" />
          <Value Type="Integer">1</Value>
        </Eq>
        <Geq>
          <FieldRef Name="MeetingDate"/>
          <Value Type="DateTime">
            <Today/>
          </Value>
        </Geq>
      </And>
    </Where>
   <OrderBy>
    <FieldRef Name="MeetingDate" Ascending ="True"/>
  </OrderBy>
  </Query>
  <RowLimit>1</RowLimit>     
</View>
2
  • @ Unnie: thank you for the correction, when I run now it takes 05/10/2015 which is good... but I created a meetingdate folder with 03/10/2015 it should take this now, because this is more close by 29/09/2015 (today), but it still shows and take 05/10/2015. I did clear browser cached (IE/Chrome)... it takes 05/10/2015... which is wrong. Sep 29, 2015 at 10:17
  • 1
    @unnie---> It works... I changed the Ascending to TRUE and my tests are correct.. now... thank you so much... So my issue was the order by was outside the query... thanks thanks thanks. Sep 29, 2015 at 10:25
0

You get only one row because you have

<RowLimit>1</RowLimit>

in your query

1
  • @ Leopold Lerch: yes that's fine... I only want 1 row... I do greater or equal than todays date. so I should get all rows, but then with <rowlimit>1 - I want only 1 row... in fact just get the row just before today.... ... btw: I only need 1 row... just the row which is greater than TODAY. but the issue: it takes wrong row. Sep 29, 2015 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.