Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Unable to get the pending item in the query

  Asked By: Judson    Date: Oct 29    Category: Sharepoint    Views: 1473

I just wrote a webpart to get item from a list according to the ID
and was able to get the items that are approved. Yes, i use the
control Required Approval for the list. The webpart i wrote contains
a query to pick the item according to the ID but unable to get the
items that are in pending or rejected status. Anybody had this
problem before? or am i missing with something? i need some help on
this. I have given the code below.

\\think only this chunk is required to solve the problem
SPSite site = new SPSite("http://test");
SPWeb web = site.AllWebs["sites/testsite"];
SPList list = web.Lists["test"];

SPQuery query = new SPQuery();
int ID = int.Parse(Context.Request.Params["ID"]);

query.Query = "<Where><Eq><FieldRef Name='ID'/><Value

Please i need some help in this matter,
Thank You.

SPListItemCollection listItems = list.GetItems(query);

foreach (SPListItem listItems1 in listItems)
CreatedUser = listItems1["Created By"].ToString();
int num = CreatedUser.IndexOf(";");
int userID = int.Parse(CreatedUser.Substring(0,num));
SPUser user = web.AllUsers.GetByID(userID);



3 Answers Found

Answer #1    Answered By: Christop Mcfadden     Answered On: Oct 29

What user  context is the web  part being run under? If it's run under a user
that cannot view pending  or rejected, the OM will not return them either.

Answer #2    Answered By: Gopal Jamakhandi     Answered On: Oct 29

Well as an admin to our site, think this is running
under admin. Is there a way to view pending  and rejected  items?

Answer #3    Answered By: Chantal Rosa     Answered On: Oct 29

but i think im running it under Admin. So basically
i think i can use a list  view to get this problem solved where it
retrieves the pending  items.

SPList list = site.Lists["Test"];

SPView listView = list.Views["Approve/reject Items"]; // That will
return pending items

SPListItemCollection listItems = list.GetItems(listView);

foreach ( SPListItem item  in listItems)

But if u can see my codes where i use a query  to pic according to ID,
will Ed's code  can help  me out or do u think there is a better way?
Please send your comments. I really need some help to sort it out.

Didn't find what you were looking for? Find more on Unable to get the pending item in the query Or get search suggestion and latest updates.