How to CAML query workflow tasks assigned to other users?<p align=left><font face=Arial size=2>Hello,</font></p> <p align=left> </p> <p align=left>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:</p> <p align=left> </p> <p>&lt;Eq&gt;&lt;FieldRef Name='AssignedTo'/&gt;&lt;Value Type='Integer'&gt;17&lt;/Value&gt;&lt;/Eq&gt;</p><font color="#a31515" size=2> <p>or</p> <p align=left><font color="#000000">&lt;Eq&gt;&lt;FieldRef Name='AssignedTo'/&gt;&lt;Value Type='User'&gt;[user ID]&lt;/Value&gt;&lt;/Eq&gt;</font></p> <p align=left><font color="#000000"></font> </p> <p align=left><font color="#000000">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.</font></p> <p align=left><font color="#000000"></font> </p> <p align=left><font color="#000000">I know putting &lt;UserID/&gt; 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. </font><font color="#000000">Please advise on the right approach.</font></p> <p align=left><font color="#000000"></font> </p> <p align=left><font color="#000000">Thanks,</font></font></p>Jun© 2009 Microsoft Corporation. All rights reserved.Wed, 11 Nov 2009 08:26:05 Ze8891d49-1d82-422e-8c7f-eb99326ec14chttp://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/e8891d49-1d82-422e-8c7f-eb99326ec14c#e8891d49-1d82-422e-8c7f-eb99326ec14chttp://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/e8891d49-1d82-422e-8c7f-eb99326ec14c#e8891d49-1d82-422e-8c7f-eb99326ec14cJunHOVhttp://social.msdn.microsoft.com/Profile/en-US/?user=JunHOVHow to CAML query workflow tasks assigned to other users?<p align=left><font face=Arial size=2>Hello,</font></p> <p align=left> </p> <p align=left>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:</p> <p align=left> </p> <p>&lt;Eq&gt;&lt;FieldRef Name='AssignedTo'/&gt;&lt;Value Type='Integer'&gt;17&lt;/Value&gt;&lt;/Eq&gt;</p><font color="#a31515" size=2> <p>or</p> <p align=left><font color="#000000">&lt;Eq&gt;&lt;FieldRef Name='AssignedTo'/&gt;&lt;Value Type='User'&gt;[user ID]&lt;/Value&gt;&lt;/Eq&gt;</font></p> <p align=left><font color="#000000"></font> </p> <p align=left><font color="#000000">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.</font></p> <p align=left><font color="#000000"></font> </p> <p align=left><font color="#000000">I know putting &lt;UserID/&gt; 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. </font><font color="#000000">Please advise on the right approach.</font></p> <p align=left><font color="#000000"></font> </p> <p align=left><font color="#000000">Thanks,</font></font></p>JunThu, 12 Jun 2008 15:57:09 Z2008-06-16T16:34:19Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/e8891d49-1d82-422e-8c7f-eb99326ec14c#a0c4aebf-067a-4d87-a108-98bd2091a98chttp://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/e8891d49-1d82-422e-8c7f-eb99326ec14c#a0c4aebf-067a-4d87-a108-98bd2091a98cwss_coolhttp://social.msdn.microsoft.com/Profile/en-US/?user=wss_coolHow to CAML query workflow tasks assigned to other users?If you have the SPUser object which you can get by looping through Web.<font size=2>AllUsers</font> <p align=left><font face=Arial size=2></font> </p> <p>try </p> <p align=left><font color="#000000">&lt;Eq&gt;&lt;FieldRef Name='AssignedTo'/&gt;&lt;Value Type='Text'&gt;SPUserObject.LoginName&lt;/Value&gt;&lt;/Eq&gt;</font></p> <p> </p> <p align=left>Thanks</p>Thu, 12 Jun 2008 21:59:03 Z2008-06-12T21:59:03Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/e8891d49-1d82-422e-8c7f-eb99326ec14c#badf79fd-81ae-414e-942a-e333a082d2c8http://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/e8891d49-1d82-422e-8c7f-eb99326ec14c#badf79fd-81ae-414e-942a-e333a082d2c8JunHOVhttp://social.msdn.microsoft.com/Profile/en-US/?user=JunHOVHow to CAML query workflow tasks assigned to other users?<p align=left><font face=Arial size=2>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:</font></p> <p align=left> </p><font color="#0000ff" size=2> <p>string</font><font size=2>.Format(</font><font color="#a31515" size=2>&quot;&lt;Eq&gt;&lt;FieldRef Name='AssignedTo'/&gt;&lt;Value Type='Text'&gt;{0}&lt;/Value&gt;&lt;/Eq&gt;&quot;</font><font size=2>, loginName));</font></p> <p align=left><font size=2></font> </p> <p align=left><font size=2>Is there any other SPUser property to use as AssignedTo value? </font></p> <p align=left> </p> <p align=left>Thanks,</p> <p align=left>Jun</p>Fri, 13 Jun 2008 13:59:49 Z2008-06-13T13:59:49Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/e8891d49-1d82-422e-8c7f-eb99326ec14c#c02525d1-23d6-44f3-b43e-f18a88a58647http://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/e8891d49-1d82-422e-8c7f-eb99326ec14c#c02525d1-23d6-44f3-b43e-f18a88a58647wss_coolhttp://social.msdn.microsoft.com/Profile/en-US/?user=wss_coolHow to CAML query workflow tasks assigned to other users?<p>Jun,</p> <p align=left>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. </p> <p align=left> </p> <p align=left>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 &lt;user id&gt; + &quot;;#&quot; + &lt;user name&gt;  eg &quot;2;#Thomas Mathew&quot;.</p> <p align=left> </p> <p align=left>Thanks</p> <p align=left> </p> <p align=left><font face=Arial size=2></font> </p>Fri, 13 Jun 2008 22:29:59 Z2008-06-16T16:34:19Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/e8891d49-1d82-422e-8c7f-eb99326ec14c#dc7c5d41-dfdb-4d3a-8534-72f4bcf005bfhttp://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/e8891d49-1d82-422e-8c7f-eb99326ec14c#dc7c5d41-dfdb-4d3a-8534-72f4bcf005bfJunHOVhttp://social.msdn.microsoft.com/Profile/en-US/?user=JunHOVHow to CAML query workflow tasks assigned to other users?<p align=left><font face=Arial size=2>Hi,</font></p> <p align=left> </p> <p align=left>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:</p> <p align=left> </p> <p align=left>1) If the Show Field is set to Account, query by full account name will work</p> <blockquote dir=ltr style="margin-right:0px"><font color="#0000ff" size=2> <p></font><font color="#a31515" size=2>&lt;Eq&gt;&lt;FieldRef Name='AssignedTo'/&gt;&lt;Value Type='Text'&gt;accountName&lt;/Value&gt;&lt;/Eq&gt;</font></p> <p align=left><font color="#a31515"></font><font size=2> </p></font></blockquote> <p align=left>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 &quot;&lt;userID&gt;;#&quot; at the beginning, like the example below. </p> <blockquote dir=ltr style="margin-right:0px"><font color="#0000ff" size=2> <p></font><font color="#a31515" size=2>&lt;Eq&gt;&lt;FieldRef Name='AssignedTo'/&gt;&lt;Value Type='Text'&gt;Andy Smith&lt;/Value&gt;&lt;/Eq&gt;</font><font size=2></p></font></blockquote> <p align=left> </p> <p align=left>Once I put the value as &quot;26;#Andy Smith&quot;, 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.</p> <p align=left> </p> <p align=left>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.</p> <p align=left> </p> <p align=left>Thanks,</p> <p align=left>Jun</p>Mon, 16 Jun 2008 16:48:21 Z2008-06-16T16:48:21Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/e8891d49-1d82-422e-8c7f-eb99326ec14c#9aee96b3-e707-400d-8930-c45d5f474033http://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/e8891d49-1d82-422e-8c7f-eb99326ec14c#9aee96b3-e707-400d-8930-c45d5f474033IDickerhttp://social.msdn.microsoft.com/Profile/en-US/?user=IDickerHow to CAML query workflow tasks assigned to other users?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.<br><br>SPQuery myqry;<br>myqry.Query = &quot;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name=\&quot;AssignedTo\&quot; /&gt;&lt;Value Type=\&quot;Integer\&quot;&gt;&lt;UserID Type=\&quot;Integer\&quot; /&gt;&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;&quot;;<br><br> Fri, 08 Aug 2008 00:05:06 Z2008-08-08T00:06:18Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/e8891d49-1d82-422e-8c7f-eb99326ec14c#9803225b-ab6d-4d60-8cf8-0ab81d98c850http://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/e8891d49-1d82-422e-8c7f-eb99326ec14c#9803225b-ab6d-4d60-8cf8-0ab81d98c850Q-Ianhttp://social.msdn.microsoft.com/Profile/en-US/?user=Q-IanHow to CAML query workflow tasks assigned to other users?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.<br/> <br/> Add LookupId=\&quot;TRUE\&quot; to the fieldref tag and you can search by just the SPUser.ID<br/> <br/> &lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name=\&quot;AssignedTo\&quot; LookupId=\&quot;TRUE\&quot; /&gt;&lt;Value Type=\&quot;User\&quot;&gt;SPUser.ID&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;<br/> <br/> Hope this helps someone!Tue, 14 Apr 2009 13:33:27 Z2009-04-14T13:33:27Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/e8891d49-1d82-422e-8c7f-eb99326ec14c#bb046e07-049c-427e-8b9e-c0a5ff351222http://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/e8891d49-1d82-422e-8c7f-eb99326ec14c#bb046e07-049c-427e-8b9e-c0a5ff351222deepakjghttp://social.msdn.microsoft.com/Profile/en-US/?user=deepakjgHow to CAML query workflow tasks assigned to other users?Q-Ian, I like your solution better.<br/><br/>Thanks.Thu, 11 Jun 2009 20:25:52 Z2009-06-11T20:25:52Zhttp://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/e8891d49-1d82-422e-8c7f-eb99326ec14c#35a3fd8a-4816-415c-875d-07a98d466536http://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/e8891d49-1d82-422e-8c7f-eb99326ec14c#35a3fd8a-4816-415c-875d-07a98d466536Dilip Nikamhttp://social.msdn.microsoft.com/Profile/en-US/?user=Dilip%20NikamHow to CAML query workflow tasks assigned to other users?<blockquote>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.<br/><br/>Add LookupId=\&quot;TRUE\&quot; to the fieldref tag and you can search by just the SPUser.ID<br/><br/>&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name=\&quot;AssignedTo\&quot; LookupId=\&quot;TRUE\&quot; /&gt;&lt;Value Type=\&quot;User\&quot;&gt;SPUser.ID&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;<br/><br/>Hope this helps someone!</blockquote> <br/>I have a Multiple Users. Now i want to write a caml query for that. Can you help me to create this type of query ......Wed, 11 Nov 2009 08:26:05 Z2009-11-11T08:26:05Z