5

I want a caml query that only retrieves items created by the user currently logged in. I tried this

specifier = "<Eq><FieldRef Name='AssignedTo'/><Value Type='Integer'><UserID/></Value></Eq>";
camlquerystring = "<View><Query><Where>" + specifier + "</Where><OrderBy><FieldRef Name='Modified' Ascending='FALSE' /></OrderBy></Query></View>"; 

However I am not getting any items. I should be getting a lot of items...

Does anyone know the right way to do this?

Thanks

3

AssignedTo should be replaced with Author and you should then see all your items.

  • I tried that, but I am still getting 0 items back. – omega May 30 '13 at 13:07
  • Nevermind, this worked, I just had another issue. – omega May 30 '13 at 13:58
2
SPQuery query = new SPQuery();
query.Query = @"<Where><Eq><FieldRef Name='Author' LookupId='TRUE' /><Value Type='Integer'>" + _id + @"</Value></Eq></Where><OrderBy><FieldRef Name='Created' Ascending='False' /></OrderBy>";

where _id is user's ID.

1

Simpler CAML - items created by current user

query.Query = @"<Where>
                  <Eq>
                    <FieldRef Name='Author' />
                    <Value Type='User'><UserID/></Value>
                  </Eq>
                </Where>";  

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.