Microsoft Developer Network > 포럼 홈 > SharePoint - Workflow > How to CAML query workflow tasks assigned to other users?
질문하기질문하기
 

답변됨How to CAML query workflow tasks assigned to other users?

  • 2008년 6월 12일 목요일 오후 3:57JunHOV 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    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

답변

  • 2008년 6월 13일 금요일 오후 10:29wss_cool 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨

    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

     

     

모든 응답

  • 2008년 6월 12일 목요일 오후 9:59wss_cool 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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

  • 2008년 6월 13일 금요일 오후 1:59JunHOV 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    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

  • 2008년 6월 13일 금요일 오후 10:29wss_cool 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨

    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

     

     

  • 2008년 6월 16일 월요일 오후 4:48JunHOV 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    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

  • 2008년 8월 8일 금요일 오전 12:05IDicker 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     제안된 답변코드 있음
    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>";

    • 답변으로 제안됨IDicker 2008년 8월 8일 금요일 오전 12:28
    • 편집됨IDicker 2008년 8월 8일 금요일 오전 12:06Clarified how view created
    •  
  • 2009년 4월 14일 화요일 오후 1:33Q-Ian 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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!
  • 2009년 6월 11일 목요일 오후 8:25deepakjg 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Q-Ian, I like your solution better.

    Thanks.
  • 2009년 11월 11일 수요일 오전 8:26Dilip Nikam 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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!

    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 ......