1

I am trying to retrieve list items using date range based on date column. It implicit both 'Fromdate' and 'Todate'.My CAML query is also querying on two other conditions as well. I am using the below query but it is not retrieving the data.when I remove the date range from query data is retrieved fine. But i want date range as well in my query how would i do this. Little help would work for me.

camlQuery.set_viewXml('<View><Query><Where><And><And><Neq><FieldRef Name="ID" /><Value Type="Number">0</Value></Neq><Eq><FieldRef Name="_ModerationStatus" /><Value Type="ModStat">0</Value></Eq><Geq><FieldRef Name="Created" /><Value Type="DateTime">' + fromDate + '</Value></Geq><Leq><FieldRef Name="Created" /><Value Type="DateTime">' + toDate + '</Value></Leq></And></And></Where><OrderBy><FieldRef Name="_ModerationStatus" Ascending="True" /></OrderBy></Query></View>');

2 Answers 2

0

I have edited your caml query but i have not tested it. Try this caml query. If issue occurs please let me know.

<View><Query>
<Where>
    <And>
        <And>
            <And>
                <Neq><FieldRef Name="ID" /><Value Type="Number">0</Value></Neq>
                <Eq><FieldRef Name="_ModerationStatus" /><Value Type="ModStat">0</Value></Eq>
            </And>
            <Geq><FieldRef Name="Created" /><Value Type="DateTime">' + fromDate + '</Value></Geq>       
        </And>
        <Leq><FieldRef Name="Created" /><Value Type="DateTime">' + toDate + '</Value></Leq>
    </And>
</Where>
<OrderBy><FieldRef Name="_ModerationStatus" Ascending="True" /></OrderBy></Query></View>
1
  • HI rohit i tried your caml query it is not giving the results . Everything is showing empty. Could you pleasee help me out. Thanks
    – SPLearner
    May 8, 2015 at 13:03
0

I have used CAML query builder to re create your query. I hope this works!! I suspect the AND clause were not properly placed.

<View>
<Query>
    <Where>
        <And>
            <Neq>
                <FieldRef Name="ID" />
                <Value Type="Number">0</Value>
            </Neq>
            <And>
                <Eq>
                    <FieldRef Name="_ModerationStatus" />
                    <Value Type="ModStat">0</Value>
                </Eq>
                <And>
                    <Geq>
                        <FieldRef Name="Created" />
                        <Value Type="DateTime">' + fromDate + '</Value>
                    </Geq>
                    <Leq>
                        <FieldRef Name="Created" />
                        <Value Type="DateTime">' + toDate + '</Value>
                    </Leq>
                </And>
            </And>
        </And>
    </Where>
    <OrderBy><FieldRef Name="_ModerationStatus" Ascending="True" /></OrderBy>
</Query>

This CAML Query Builder is a very nice and handy tool to create complex queries. You can download and use it.

3
  • HI Asad , It is not giving the results. Showing empty.
    – SPLearner
    May 11, 2015 at 19:16
  • The field ID if this is the OOB List unique ID, then I guess its type should be counter. Can you try updating that.
    – Asad Refai
    May 12, 2015 at 5:41
  • I updated it to counter still same no results are up.
    – SPLearner
    May 12, 2015 at 15:06

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.