locked
CAML query for specific user in content query web part RRS feed

  • Question

  • I want to retrieve user specific data using CAML query in content query web part. Below is my code.

    <property name="QueryOverride" type="string" >

              <![CDATA[<Where>

              <and>

            <Geq>

                <FieldRef Name="Request Status"/>

                <Value Type="Choice">

                Completed

                </Value>

            </Geq>

            <eq>

            <FieldRef Name="Editor" />

        <Value Type="User">user_windows_login_id</Value>

            </eq>

              </and>

        </Where>]]>

     

    But I am getting below error “There is a problem with the query that this Web Part is issuing. Check the configuration of this Web Part and try again.

     

    Any idea how I can retrieve the records of a specific user by using CAML ??

     

    Wednesday, September 21, 2011 12:15 PM

All replies

  • Hi Parshant,

     

    You should use the following CAML query (assuming internal name of your Person or Group field is Person from your CAML query above):

    SPUser user = web.EnsureUser(loginName);
    SPQuery query = new SPQuery();
    query.Query = String.Format("<Where><Eq><FieldRef Name='Person' LookupId='TRUE' /><Value Type='Integer'>{0}</Value></Eq></Where>", user.ID);

    or you can test 

     

    SPQuery viewQuery = new SPQuery();

    SPView customView = list.Views.Add("Simple", viewFields, defaultView.Query, defaultView.RowLimit, defaultView.Paged, true);

    view.Query = "<Where><Eq><FieldRef Name=\"AssignedTo\" /><Value Type=\"Integer\"><UserID Type=\"Integer\" /></Value></Eq></Where>";


    Krishana Kumar http://mosstechnet-kk.com
    Thursday, September 22, 2011 7:15 AM
  • Thanks for ur replay,

    I am using out-of-box 2007.I can't do this with coding. I am embeeding caml in exported file of web part.

    I need to display records of specific user.

    can u pls tel me how to do this ?

    Thanks

     

    Thursday, September 22, 2011 8:40 AM