locked
Assigning a task based on 'person' column. RRS feed

  • Question

  • Hi All,

    I am creating an employee of the month type feature in Visual Studio.

    This involves a nominations list (where users can submit a nomination) and a custom task list (based on workflow tasks)

    In a nomination, a "Line Manager" is entered, and is set up as a Person Column. In code, I create a task, and I am trying to assign the task to the line manager. The code I have is:

    taskProperties.AssignedTo = workflowProperties.Item[

    "Line Manager"].ToString();

    This does return the name of the nominator (but with a prefix, usually #795; (or something like that)).

    How can I assign a task in code to a user based on the selection of a Person field (chosen using People Picker)?

     

     


    Andrew Berry - Software analyst/Developer
    Thursday, September 9, 2010 10:43 AM

Answers

  • Hi,

    You have to write the AccountID of the person, to whom you want to assign the task. Your code should be like this :

    TaskProperties.AssignedTo = @"domain\Username";

    So make sure that the field "Line Manager" consist of the AccountId.

    Regards

    Ginni

    • Marked as answer by Andrew J Berry Thursday, September 9, 2010 12:36 PM
    Thursday, September 9, 2010 11:02 AM

All replies

  • Hi,

    You have to write the AccountID of the person, to whom you want to assign the task. Your code should be like this :

    TaskProperties.AssignedTo = @"domain\Username";

    So make sure that the field "Line Manager" consist of the AccountId.

    Regards

    Ginni

    • Marked as answer by Andrew J Berry Thursday, September 9, 2010 12:36 PM
    Thursday, September 9, 2010 11:02 AM
  • Ignore that, have used the name to find the loginname (containing the id).

    I did the following:

    SPUser

     

    LineManager = null;

     

    using (SPSite site = new SPSite("http://sfssharepoint"))

    {

     

    using (SPWeb web = site.OpenWeb())

    {

     

    string login = workflowProperties.Item["Line Manager"].ToString().Remove(0,5);

    LineManager = web.EnsureUser(login);

    }

    }

    taskProperties.AssignedTo = LineManager.LoginName;

    And this assigns the task as expected. Cheers!

     

    Thursday, September 9, 2010 11:55 AM