• Upgrade your Internet Experience
  • Sign in
  • Microsoft.com
  • United States (English)
    Brasil (Português)Česká republika (Čeština)Deutschland (Deutsch)España (Español)France (Français)Italia (Italiano)Россия (Русский)대한민국 (한국어)中华人民共和国 (中文)台灣 (中文)日本 (日本語)香港特别行政區 (中文)
 
 
Microsoft Developer Network
 
 
Home
 
 
Library
 
 
Learn
 
 
Downloads
 
 
Support
 
 
Community
 
 
Forums
 
 
 
Microsoft Developer Network > SharePoint Products and Technologies Forums > SharePoint - Workflow > How to CAML query workflow tasks assigned to other users?
Ask a questionAsk a question
Search Forums:
  • Search SharePoint - Workflow Forum Search SharePoint - Workflow Forum
  • Search All SharePoint Products and Technologies Forums Search All SharePoint Products and Technologies Forums
  • Search All MSDN Forums Search All MSDN Forums
 

AnswerHow to CAML query workflow tasks assigned to other users?

  • Thursday, June 12, 2008 3:57 PMJunHOV Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

    Hello,

     

    I am trying to do a CAML query to get all the workflow tasks assigned to a specific user, not the current context user. The query would be something like below:

     

    <Eq><FieldRef Name='AssignedTo'/><Value Type='Integer'>17</Value></Eq>

    or

    <Eq><FieldRef Name='AssignedTo'/><Value Type='User'>[user ID]</Value></Eq>

     

    However, none of the above approaches works. Putting an Integer there gave me exception and putting userID there finds no result. Some post mentioned that using a user name instead of userID will work, but this is not a good approach since users can have duplicate names and my users basically don't have names.

     

    I know putting <UserID/> as value returns tasks for the current user. Please let me know what should be put in as AssignedTo Value and Type to get tasks for other users. BTW, the script is running on admin account, so there is no permission issue to see other users tasks. Please advise on the right approach.

     

    Thanks,

    Jun
    • ReplyReply
    • QuoteQuote
     

Answers

  • Friday, June 13, 2008 10:29 PMwss_cool Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Vote As Helpful
    0

    Jun,

    Go to the task list setting and check properties (Edit Column) of Assigned To column. If the Show field: is set to Name (with presence) then change it to Account and try the with abou CAML.

     

    I know this is not a solution. If you are using Show field as Name then you need to construct a user name string like <user id> + ";#" + <user name>  eg "2;#Thomas Mathew".

     

    Thanks

     

     

    • ReplyReply
    • QuoteQuote
     

All Replies

  • Thursday, June 12, 2008 9:59 PMwss_cool Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0
    If you have the SPUser object which you can get by looping through Web.AllUsers

     

    try

    <Eq><FieldRef Name='AssignedTo'/><Value Type='Text'>SPUserObject.LoginName</Value></Eq>

     

    Thanks

    • ReplyReply
    • QuoteQuote
     
  • Friday, June 13, 2008 1:59 PMJunHOV Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

    Thanks for your reply. I tried your approach with LoginName (which is known to the application), but the query returns no result. Below is my query part:

     

    string.Format("<Eq><FieldRef Name='AssignedTo'/><Value Type='Text'>{0}</Value></Eq>", loginName));

     

    Is there any other SPUser property to use as AssignedTo value?

     

    Thanks,

    Jun

    • ReplyReply
    • QuoteQuote
     
  • Monday, June 16, 2008 4:48 PMJunHOV Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

    Hi,

     

    Thanks for your input. Very helpful although not exactly match my test result. I have played with the column Show Field between Name (with presence) and Account and below is my test reaults:

     

    1) If the Show Field is set to Account, query by full account name will work

    <Eq><FieldRef Name='AssignedTo'/><Value Type='Text'>accountName</Value></Eq>

     

    2) If the Show Field is set to Name or Name (with presence), query by User Name alone will work. The User Name string cannot contain "<userID>;#" at the beginning, like the example below.

    <Eq><FieldRef Name='AssignedTo'/><Value Type='Text'>Andy Smith</Value></Eq>

     

    Once I put the value as "26;#Andy Smith", the query dosen't find anything. I don't know why it cannot contain user id in the value part in my case and this is not a good situation either since the duplicate user name will become a problem then.

     

    Since I want to leave the Show Field as Name (with presence), please let me know how to make the query work with userID as part of the value.

     

    Thanks,

    Jun

    • ReplyReply
    • QuoteQuote
     
  • Friday, August 08, 2008 12:05 AMIDicker Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed AnswerHas Code
    Vote As Helpful
    0
    We had trouble with this so I built a view using the UI and set the filter condition to [Me], then got a handle to the SPView object and pulled the Query from it - the result is below - works for us with AD as authentication provider.

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

    • Edited byIDicker Friday, August 08, 2008 12:06 AMClarified how view created
    • Proposed As Answer byIDicker Friday, August 08, 2008 12:28 AM
    •  
    • ReplyReply
    • QuoteQuote
     
  • Tuesday, April 14, 2009 1:33 PMQ-Ian Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0
    I know this post is quite old, but I've just spent 3 hours on this problem and got a different solution that works well for me.

    Add LookupId=\"TRUE\" to the fieldref tag and you can search by just the SPUser.ID

    <Where><Eq><FieldRef Name=\"AssignedTo\" LookupId=\"TRUE\" /><Value Type=\"User\">SPUser.ID</Value></Eq></Where>

    Hope this helps someone!
    • ReplyReply
    • QuoteQuote
     
  • Thursday, June 11, 2009 8:25 PMdeepakjg Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0
    Q-Ian, I like your solution better.

    Thanks.
    • ReplyReply
    • QuoteQuote
     
Need Help with Forums? (FAQ)
 
© 2009 Microsoft Corporation. All rights reserved.
Terms of Use
|
Trademarks
|
Privacy Statement