1

Right now my code is is Equals in the query how can i prevent for example that if i book 2014-12-01 01:00 to 2014-12-02 01:00 This is a hole day, that no one else can for example book the same time but between any time and that range?

My code looks like this right now.

var camlQuery = new SP.CamlQuery();

    camlQuery.set_viewXml('<View><Query><And><Eq><FieldRef Name=\'EventDate\' /><Value IncludeTimeValue=\'TRUE\' Type=\'DateTime\'>'
        + fromTime.toISOString() + '</Value></Eq><Eq><FieldRef Name=\'EndDate\' /><Value IncludeTimeValue=\'TRUE\' Type=\'DateTime\'>' + toTime.toISOString() +
        '</Value></Eq></And></Where></Query></View>');


    this.collListItem = list.getItems(camlQuery);
    context.load(collListItem);
0

2 Answers 2

0

You can use Geq and Leq to formulate the range query as below

query.set_viewXml('<View><Query><Where><And><Geq><FieldRef Name=\'EventDate\'/>' + 
    '<Value IncludeTimeValue=\'TRUE\' Type=\'DateTime\'>' + fromTime.toISOString() + '</Value></Geq><Leq><FieldRef Name=\'EndDate\' /><Value IncludeTimeValue=\'TRUE\' Type=\'DateTime\'>' + toTime.toISOString() + '</Value></Leq></And></Where></Query></View>');
0

you are missing missing opening tag <Where>.Your code must be

var camlQuery = new SP.CamlQuery();

camlQuery.set_viewXml('<View><Query><Where><And><Eq><FieldRef Name=\'EventDate\' /><Value IncludeTimeValue=\'TRUE\' Type=\'DateTime\'>'
    + fromTime.toISOString() + '</Value></Eq><Eq><FieldRef Name=\'EndDate\' /><Value IncludeTimeValue=\'TRUE\' Type=\'DateTime\'>' + toTime.toISOString() +
    '</Value></Eq></And></Where></Query></View>');


this.collListItem = list.getItems(camlQuery);
context.load(collListItem);

Your Answer

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

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