locked
How to assign values to workflow task person or group custom field? RRS feed

  • Question

  • Using visual studio 2008, in createTask_MethodInvoking, I have the following code. RequestFields has the values from the InfoPath form. ApprovingPersons is a person or group field, added to the task list by my custom task content type. I checked the task list associated with the workflow and I see the custom field.

    SPUser user;
    SPFieldUserValueCollection fuvc = new SPFieldUserValueCollection();
    foreach (Contact person in RequestFields.Persons)
    {
          user = workflowProperties.Web.EnsureUser(person.LoginName);
          fuvc.Add(new SPFieldUserValue(workflowProperties.Web, user.ID, user.Name));
    }

    // this is the line causing problem, I believe
    PreApprovalTask_TaskProperties.ExtendedProperties["ApprovingPersons"] = fuvc;

    I got the following error message:

    at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
       at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] argument

    Thanks,

    Tony
    Tuesday, February 23, 2010 5:42 PM

Answers

  • Step1.

    Hide Assign To Column in Task List,
    and Create a New column with any name with type People-picker with multiple Users, In default view

    Hi,

    Please follow below step to do the same.

    Step1.

    Create a new custom field(User and Group) in Task list with multiple user selection.

    Step2.

    Assign users to New column which accept multiple users,

    Process:

    1. Get a current taskId
    2. Get the current list item from the task list with help of taskId.
    3. Assign multiple user to that new created column separated by semi colon.

    Note: If you are using OOTB email Notification, It does not work

    TaskFirst_TaskProperties1.SendEmailNotification = true;

    You need to create you own custom email notification;

    If you need more details do let me know.

    Cheers, Sanjiv Kumar
    • Marked as answer by Tony Yin Thursday, February 25, 2010 8:53 PM
    Wednesday, February 24, 2010 11:33 AM

All replies

  • i have the same problem, the custom field person or group cannot accept the value eq. 1;#user1;#11;#user2;#13;#user3 from fuvc; workflow will send message error occured
    Wednesday, February 24, 2010 9:38 AM
  • Step1.

    Hide Assign To Column in Task List,
    and Create a New column with any name with type People-picker with multiple Users, In default view

    Hi,

    Please follow below step to do the same.

    Step1.

    Create a new custom field(User and Group) in Task list with multiple user selection.

    Step2.

    Assign users to New column which accept multiple users,

    Process:

    1. Get a current taskId
    2. Get the current list item from the task list with help of taskId.
    3. Assign multiple user to that new created column separated by semi colon.

    Note: If you are using OOTB email Notification, It does not work

    TaskFirst_TaskProperties1.SendEmailNotification = true;

    You need to create you own custom email notification;

    If you need more details do let me know.

    Cheers, Sanjiv Kumar
    • Marked as answer by Tony Yin Thursday, February 25, 2010 8:53 PM
    Wednesday, February 24, 2010 11:33 AM
  • Thanks for the reply Sanjiv. Based on your idea I was able to accomplish this.

    Here is what I did in high level:

    In createTask method, I leave out the statement of assigning values of "ApprovingPersons".
    In taskCreated method, I assign the values to the field of "ApprovingPersons" by doing the following:

    SPList taskList = workflowProperties.TaskList;
                SPListItem taskItem = taskList.GetItemById(PreApprovalTaskChanged_AfterProperties.TaskItemId);
                if (RequestFields.Persons != null && RequestFields.Persons.Length > 0)
                {

                    SPUser user;
                    SPFieldUserValueCollection fuvc = new SPFieldUserValueCollection();
                    foreach (Contact person in pRequestFields.Persons)
                    {
                        user = workflowProperties.Web.EnsureUser(person.LoginName);
                        fuvc.Add(new SPFieldUserValue(workflowProperties.Web, user.ID, user.Name));
                    }

                    taskItem["ApprovingPersons"] = fuvc;
                    // note this causes onChanged event called
                    taskItem.SystemUpdate(false);
                }
     
    • Edited by Mike Walsh FIN Tuesday, August 30, 2011 6:33 AM Thread was already closed. New question edited out
    Thursday, February 25, 2010 8:50 PM
  • Thanks for the suggestion. I was able to get it to work based on your idea, although I ran into some other issues, but I was able to resolve them.
     
    • Edited by Mike Walsh FIN Tuesday, August 30, 2011 6:33 AM New question removed
    Thursday, February 25, 2010 8:55 PM