none
How to query the Task Items assigned to current user. RRS feed

  • Question

  • Hi

    I am developing a custom webpart in which i am going to populate the current user(Assigned To=currentuser) tasks by filtering a column called Category(LookUp field). I am using the SPQuery class.

     

    If i give/hard coded the user login name (domainname\\username) it is working fine>But if i use web.CurrentUser.LoginName it is not showing the tasks. My query is

    SPQuery queryCATASSG = new SPQuery();     

          
    queryCATASSG.Query = "<Where><And><Eq><FieldRef Name='AssignedTo'/><Value Type='User'>"+web.CurrentUser.LoginName+"</Value></Eq><Eq><FieldRef Name='Category'/><Value Type='Lookup'>"+"AssgTasks"+"</Value></Eq></And></Where>";

     

    Can any one help me??

     

    • Edited by Purna Chander.M Saturday, April 10, 2010 9:25 AM heading changed 2
    Saturday, April 10, 2010 9:24 AM

Answers

  • Hi, Purna

        

          If you need to add a filter in “AssignedTo” field for current user’s tasks, would you please try the following CAML schema:

     

           -----------------------------------------------------------------------------------------------------------------------------

           queryCATASSG.Query =

           “<Where>

                <Eq><FieldRef Name=" AssignedTo" /><Value Type="Integer"><UserID Type="Integer" /></Value></Eq>

           </Where>”

          -----------------------------------------------------------------------------------------------------------------------------

          OOB task list achieve this with [Me] filter like this.

     

          Hope this can help.

     

    Best Regards,

    -Aaron

     

    Monday, April 12, 2010 2:49 AM

All replies

  • Hi

    Your problem is based on the fact that <Value Type='User'> expects value as ;#userID;#UserLoginName e.g ;#1;#myUserName;# as the Lookup value type. In order to solve this problem you should specify that you want to query items using CurrentUserID

    e.g

    var queryString = "<WHERE><Eq>"+
                          "<FieldRef Name='AssignedTo'/>" +
                          "<Value Type='User' LookupId='True'>" + web.CurrentUser.ID + "</Value>"
                      "</Eq></Where>"

    Hope this helps,

    Viko

    Saturday, April 10, 2010 11:10 AM
  • Hi, Purna

        

          If you need to add a filter in “AssignedTo” field for current user’s tasks, would you please try the following CAML schema:

     

           -----------------------------------------------------------------------------------------------------------------------------

           queryCATASSG.Query =

           “<Where>

                <Eq><FieldRef Name=" AssignedTo" /><Value Type="Integer"><UserID Type="Integer" /></Value></Eq>

           </Where>”

          -----------------------------------------------------------------------------------------------------------------------------

          OOB task list achieve this with [Me] filter like this.

     

          Hope this can help.

     

    Best Regards,

    -Aaron

     

    Monday, April 12, 2010 2:49 AM
  • Thanks Aaron,


    It worked fine.But for the system account(Sharepoint\\System ) the UserId is not working.Im checking this condition and writing for this explicitly.

     

    Purna.

     

     

     

     

    Tuesday, April 13, 2010 3:06 AM