Caml Query Date condition not working
-
21-02-2021 - |
Question
In the below query after adding date condition the query returns error - Cannot complete this action. Please try again..
"<View><Query><Where><And><Eq><FieldRef Name='Company' /><Value Type='Text'>" + CompanyName + "</Value></Eq>" +
"<And><Eq><FieldRef Name='License' /><Value Type='Text'>" + License + "</Value></Eq>" +
"<And><Eq><FieldRef Name='Active' /><Value Type='Boolean'>0</Value></Eq> <IsNull><FieldRef Name='ReplacementUserID'/></IsNull >" +
"<And><Geq><FieldRef Name='LicenseExpiryDate'/><Value IncludeTimeValue='FALSE' Type='DateTime'><Now /></Value></Geq>" +
"</And></And></And></And></Where></Query><RowLimit>100</RowLimit></View>"
La solution
<And>
element can have only two child elements (two conditions). Your query should be in below format:
<View>
<Query>
<Where>
<And>
<Eq><FieldRef Name='Company' /><Value Type='Text'>CompanyName</Value></Eq>
<And>
<Eq><FieldRef Name='License' /><Value Type='Text'>License</Value></Eq>
<And>
<Eq><FieldRef Name='Active' /><Value Type='Boolean'>0</Value></Eq>
<And>
<IsNull><FieldRef Name='ReplacementUserID'/></IsNull >
<Geq><FieldRef Name='LicenseExpiryDate'/><Value IncludeTimeValue='FALSE' Type='DateTime'><Now /></Value></Geq>
</And>
</And>
</And>
</And>
</Where>
</Query>
<RowLimit>100</RowLimit>
</View>
Add variables, +
and "
accordingly.
Documentation: CAML Query schema
Autres conseils
Change your caml query to the following, check if it works for you:
<Query>
<Where>
<And>
<And>
<And>
<Eq><FieldRef Name='Company' /><Value Type='Text'>" + CompanyName + "</Value></Eq>
<Eq><FieldRef Name='License' /><Value Type='Text'>" + License + "</Value></Eq>" +
"</And>
<Eq><FieldRef Name='Active' /><Value Type='Boolean'>0</Value></Eq> <IsNull><FieldRef Name='ReplacementUserID'/></IsNull >" +
"</And>
<Geq><FieldRef Name='LicenseExpiryDate'/><Value IncludeTimeValue='FALSE' Type='DateTime'><Now /></Value></Geq>" +
"</And>
</Where>
</Query>
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange