Pregunta

The Following CAML Query Not Working for me.. I am not aware much about sharepoint platform. i am using SP 2007 and trying to use IN operator for a lookup field.

"<Where>"
                                + "<And>"
                                + "<And>"
                                + "<In>"
                                + "<FieldRef Name='Role'/>"
                                + "<Values>"
                                + "<Value Type = 'Text'>A</Value>"
                                + "<Value Type = 'Text'>B</Value>"
                                + "</Values>"
                                + "</In>"
                                + "<Leq>"
                                + "<FieldRef Name='Enddate'/><Value Type = 'DateTime'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(Dt) + " </Value>"
                                + "</Leq>"
                                + "</And>"
                                + "<Includes>"
                                + "<FieldRef Name='Menu'/><Value Type='Text'>Benefits</Value>"
                                + "</Includes>"
                                + "</And>"
                                + "</Where>";

The above query not return anything but i have values in my list for the above combination.

If I slightly modify the query like following w/o using IN then it is working fine.

"<Where>"
                                + "<And>"
                                + "<And>"
                                + "<Eq>"
                                + "<FieldRef Name='Role'/>"
                                //+ "<Values>"
                                + "<Value Type = 'Text'>A</Value>"
                                //+ "<Value Type = 'Text'>B</Value>"
                                //+ "</Values>"
                                + "</Eq>"
                                + "<Leq>"
                                + "<FieldRef Name='Enddate'/><Value Type = 'DateTime'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(Dt) + " </Value>"
                                + "</Leq>"
                                + "</And>"
                                + "<Includes>"
                                + "<FieldRef Name='Menu'/><Value Type='Text'>Benefits</Value>"
                                + "</Includes>"
                                + "</And>"
                                + "</Where>";

(Please Don't Suggest me to use CAML Query builder cuz I cannot install anything on my DEV box. And Moreover I haven't install SP WSS in my local :) )

¿Fue útil?

Solución

The IN operator for CAML was introduced in Sharepoint 2010. You cannot use it in Sharepoint 2007. To achieve the same result you will have to write it as a OR's instead.

<Or>
 <Eq>
  <FieldRef Name='Role' />
  <Value Type='Text'>A</Value>
 </Eq>
 <Eq>
  <FieldRef Name='Role' />
  <Value Type='Text'>B</Value>
 </Eq>
</Or>

Otros consejos

If Someone still Use Sharepoint 2007 and want to use IN operator with multiple Conditions, You can achieve this like following,Here I used "OR" operator instead "IN"

string lCAMLQuery =                "<Where>"
                                        + "<And>"
                                        + "<And>"
                                            + "<Leq>"
                                                + "<FieldRef Name='Enddate'/><Value Type = 'DateTime'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(Dt) + " </Value>"
                                            + "</Leq>"
                                        + "<Or>"
                                            + "<Eq>"
                                                + "<FieldRef Name='Role' />"
                                                + "<Value Type='Text'>A</Value>"
                                            + "</Eq>"
                                             + "<Eq>"
                                                + "<FieldRef Name='Role' />"
                                                + "<Value Type='Text'>D</Value>"
                                            + "</Eq>"
                                        + "</Or>"
                                        + "</And>"
                                            + "<Includes>"
                                                + "<FieldRef Name='Menu'/><Value Type='Text'>Benefits</Value>"
                                            + "</Includes>"
                                        + "</And>"
                                    + "</Where>";
string lCAMLQuery = @"<Where>
                    <And>
                    <And>
                        <Leq>
                            <FieldRef Name='Enddate'/><Value Type = 'DateTime'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(Dt) + " </Value>
                        </Leq>
                    <Or>
                        <Eq>
                            <FieldRef Name='Role' />
                            <Value Type='Text'>A</Value>
                        </Eq>
                        <Eq>
                            <FieldRef Name='Role' />
                            <Value Type='Text'>D</Value>
                        </Eq>
                    </Or>
                    </And>
                        <Includes>
                            <FieldRef Name='Menu'/><Value Type='Text'>Benefits</Value>
                        </Includes>
                    </And>";
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top