Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to add assignments to Projects in SharePoint 2013 using CSOM?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 821
    Comment on it

    In SharePoint, each project has its own tasks, assignments, team members etc. While creating projects in SharePoint we have to also create tasks, assignments, team members and custom fields.

    Here below is the sample code for creating assignments in projects.    

    PublishedProject publishedProject = null; 
    DraftProject draftProject = null;
    DraftAssignment draftAssignment = null;
    AssignmentCreationInformation assignmentInfo = null;
    QueueJob queueJobAssignment = null;
    
    try
    {
    	publishedProject = availableProjects[new Guid(projectId)]; //find publishedProject from all available Projects
    	draftProject = publishedProject.CheckOut();
    
    	// Load/read all assignments
    	projectContext.Load(draftProject.Assignments);
    	projectContext.ExecuteQuery();
    	
    		assignmentInfo = new Microsoft.ProjectServer.Client.AssignmentCreationInformation();
    		try
    		{
    			assignmentInfo.Id = new Guid();
    			assignmentInfo.TaskId = new Guid();
    			assignmentInfo.ResourceId = new Guid();
    			assignmentInfo.Start = DateTime.ParseExact("2015-01-01 08:00 AM", "yyyy-MM-dd HH:mm tt", null);
    			assignmentInfo.Finish = DateTime.ParseExact("2016-01-01 08:00 AM", "yyyy-MM-dd HH:mm tt", null);
    			assignmentInfo.Notes = string.Empty;
    
    			// Add the assignment to the checked out project.
    			draftAssignment = draftProject.Assignments.Add(assignmentInfo);
    
    			//Update the assignment with the baseline information
    			draftAssignment.ActualWorkTimeSpan = TimeSpan.FromMilliseconds(Convert.ToDouble("100"));
    			draftAssignment.WorkTimeSpan = TimeSpan.FromMilliseconds(Convert.ToDouble("10"));
    			draftAssignment["BaselineWorkTimeSpan"] = TimeSpan.FromMilliseconds(Convert.ToDouble("50"));
    			draftAssignment.ActualCost = Convert.ToDouble("500");
    			draftAssignment.Cost = Convert.ToDouble("100");
    			draftAssignment["BaselineCost"] = Convert.ToDouble(drAssignments[ind]["BaselineCost"]);
    			draftAssignment.ActualStart = DateTime.ParseExact("2016-01-01 08:00 AM", "yyyy-MM-dd HH:mm tt", null);
    			draftAssignment["BaselineStart"] = DateTime.ParseExact("2016-01-01 08:00 AM", "yyyy-MM-dd HH:mm tt", null);
    			draftAssignment.ActualFinish = DateTime.ParseExact("2016-02-02 08:00 AM", "yyyy-MM-dd HH:mm tt", null);
    			draftAssignment["BaselineFinish"] = DateTime.ParseExact("2016-02-02 08:00 AM", "yyyy-MM-dd HH:mm tt", null);
    		}
    		catch (Exception ex)
    		{
    			// log exception assignment not added
    		}
    	
    
    	queueJobAssignment = draftProject.Update();
    	queueJobAssignment = draftProject.Publish(true);
    }
    catch (Exception ex)
    {
    	// log exception assignment not added
    }

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: