SharePoint 2013 - SPLessons

Assigning multiple users to a workflow task in sharepoint

Home > > Tutorial
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Assigning multiple users to a workflow task in sharepoint

Assigning multiple users to a workflow task in SharePoint

Description Hi, Today I am going to explain about assigning multiple users to a workflow task in SharePoint. Our requirement is dynamically create  the tasks and assign to multiple users in SharePoint visual studio workflows.   Step 1: To create an Empty SharePoint Project
  1.  Start Visual Studio 2012 in administrator mode.
  2. On the File menu, point to New, and then click Project. If Visual Studio is set to use Visual c# development,settings, on the File menu, click New Project.
  3. In the New Project dialog box, select the SharePoint Soluction node.
  4. In the Templates pane, select Empty SharePoint Project.
  5. Then in that soluction Add new item  Select Sequential Work Flow For the name of the project, type CreteMultiuserTask, and then click OK.
  Click Next Button     Select Target List and  Task List name , then Click Next Button and Then Finish Button     After Click finish button We will get screen like This   Step 2: Go to the Toolbox Select Replicator and drag , by using replicator we will loop the assign users list   Then select Sequence activity and drag inside the Replicator     Next Select the Create Task and drag the inside sequence activity  for creating each user items inside the task list   Step 3: Select the Replicator activity and  right click then select properties .Select InitialChildData then click the ellipsis button (…).   In the Choose the type of member to create option list, click Create Field. Click OK.     Check ExecutionType   and then Select Parallel(Based on Requirement)     Enter the Initilized Method Name     Next Select the UntilCondition  Column   as a Code Condition     And then write the CodeCondition Method Name     Select the Create Task activity and  right click then select properties. Write the CorelationToken Name     Select The OwerActivity Name     Select the TaskId  And Task Properties     And then  Write Method Invoking Method name   Step 4: Go to the Toolbox Select While Activity and drag   Select the While  activity and  right click then select properties.And then Check condition and Select code Condition Method     Go to the Toolbox Select OntaskChange Activity and drag     Select theOnTaskChange activity and  right click then select properties and  Select Corelation Token  and Task Id     Next Select The AfterProperties      And then write the Invoked method     Select the OnWorkflow Activity  and Duble Click   Step 5: Total Code Here [c-sharp] public sealed partial class CreateMultiUserTask : SequentialWorkflowActivity { public CreateMultiUserTask() { InitializeComponent(); } public Guid workflowId = default(System.Guid); public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties(); public Guid createTask1_TaskId1 = default(System.Guid); public SPWorkflowTaskProperties createTask1_TaskProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties(); public int count = 0; //For craete the Multiple Tasks private void CreateTaskMethod(object sender, EventArgs e) { createTask1_TaskId1 = Guid.NewGuid(); createTask1_TaskProperties1.Title = "Relipcator"; createTask1_TaskProperties1.AssignedTo = replicatorActivity1.InitialChildData[count].ToString(); count++; } public bool isfin = false; // Check the on task chenge Condition private void IfMultiUserApprove(object sender, ConditionalEventArgs e) { if (onTaskChanged1_AfterProperties1.PercentComplete == 1.0) { e.Result = true; } else { e.Result = false; } } public SPWorkflowTaskProperties onTaskChanged1_AfterProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties(); private void OnTaskChange(object sender, ExternalDataEventArgs e) { onTaskChanged1_AfterProperties1 = onTaskChanged1.AfterProperties; } // end of the task chenge Condition public IList replicatorActivity1_InitialChildData1 = default(System.Collections.IList); public IList assignees = default(System.Collections.IList); //replecator Method private void ReplecatorMethod(object sender, EventArgs e) { replicatorActivity1.InitialChildData = assignees; } private void ReplicatorCodition(object sender, ConditionalEventArgs e) { e.Result = !(count < assignees.Count); } // End of the replecator //workflow Acctivity method private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e) { workflowId = new Guid(); assignees = new ArrayList(); string assigner = string.Empty; string multiusers = string.Empty; string user = string.Empty; char[] to_splitter = { ';' }; string to_list = Convert.ToString(workflowProperties.Item["TR_Assigndto"]); // Reads value stored in SPList. (i.e., "Domain\User1; Domain\User2") string[] arr = to_list.Split(to_splitter); ArrayList entityArrayList = new ArrayList(); for (int i = 0; i < arr.Length; i++) { if (i != 0 && (i % 2) == 0) { user = arr[i].Substring(arr[i].IndexOf("#") + 1); assignees.Add(workflowProperties.Web.SiteUsers.GetByID(int.Parse(user)).LoginName); } else if (i == 0) { user = arr[i]; assignees.Add(workflowProperties.Web.SiteUsers.GetByID(int.Parse(user)).LoginName); } } count = 0; } // end of the workflow Acctivity method } [/c-sharp] And then Deploy the solution Step 6:   Go to the sharepoint site and add the item into the sharepoint list     Now Go to the task list to check the How many tasks are created based on previous enter users snap