4

Normally I have this query, filtered with MostrarHome eq 'No'

 var queryGallery = "$select=Title,Description,Enlace,EncodedAbsUrl,Categoria/Title&$expand=Categoria/Title&$orderby=Title asc&$filter=MostrarHome eq 'No'";

So I try to do it in Calm Query and it returns values but the filter doesn´t works:

 queryStringGaleria += string.Format("<Query><Where><Eq><FieldRef Name='MostrarHome'/><Value Type='Boolean'>0</Value></Eq></Where></Query><RowLimit>1000</RowLimit>");
               queryStringGaleria += "<ViewFields>";
               queryStringGaleria += "<FieldRef Name='FileRef' />";
               queryStringGaleria += "<FieldRef Name='Categoria' />";
               queryStringGaleria += "<FieldRef Name='Categoria_x003a_English' />";
               queryStringGaleria += "<FieldRef Name='Title' />";
               queryStringGaleria += "<FieldRef Name='TitleEnglish' />";
               queryStringGaleria += "<FieldRef Name='Enlace' />";
               queryStringGaleria += "<FieldRef Name='DescriptionEnglish' />";
               queryStringGaleria += "<FieldRef Name='Description' />";
               queryStringGaleria += "</ViewFields></View>";

How can I filter it correctly?

  • 2
    Are you opening the <View> tag somewhere not shown above? – Erin L Aug 18 '16 at 23:32
2

I think that that issue related to MostrarHome type value it's should be integer rather than Boolean

Details:

The <Value Type='Boolean'> take value 0 for false and 1 for true

Regarding Yes / No field contains integer data (1 for Yes and 0 for No option), so your query should look like,

queryStringGaleria += string.Format("<Query><Where><Eq><FieldRef Name='MostrarHome'/><Value Type='Integer'>0</Value></Eq></Where></Query><RowLimit>1000</RowLimit>");
               queryStringGaleria += "<View><ViewFields>";
               queryStringGaleria += "<FieldRef Name='FileRef' />";
               queryStringGaleria += "<FieldRef Name='Categoria' />";
               queryStringGaleria += "<FieldRef Name='Categoria_x003a_English' />";
               queryStringGaleria += "<FieldRef Name='Title' />";
               queryStringGaleria += "<FieldRef Name='TitleEnglish' />";
               queryStringGaleria += "<FieldRef Name='Enlace' />";
               queryStringGaleria += "<FieldRef Name='DescriptionEnglish' />";
               queryStringGaleria += "<FieldRef Name='Description' />";
               queryStringGaleria += "</ViewFields></View>";

Note : I also put in mind , you might miss <view> tag as @ErinL said in her comment.so I put it at the above-modified query.

  • 1
    Both Type='Integer' and Type='Boolean' are valid for Yes/No fields – Erin L Aug 18 '16 at 23:27
  • Thanks @ErinL for this info , I tried to do that for integer and worked properly , I think he may be miss <view> as you told him in your comment but if he has error in his query it's should not work but he said he return data but not filtered so let us wait for him,I am also will update my answer Thanks again :) – Mohamed El-Qassas MVP Aug 18 '16 at 23:48
0

1 for Yes(true) and 0 for No (false)

var queryGallery = "$select=Title,Description,Enlace,EncodedAbsUrl,Categoria/Title&$expand=Categoria/Title&$orderby=Title asc&$filter=MostrarHome eq 0"; //false

or

var queryGallery = "$select=Title,Description,Enlace,EncodedAbsUrl,Categoria/Title&$expand=Categoria/Title&$orderby=Title asc&$filter=MostrarHome eq 1"; //true

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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