none
Assign Enterprise User a Task with PowerShell RRS feed

  • Question

  • I've been banging my head against a wall all day with this. I'm trying to use PowerShell to assign Enterprise Users a task in Project Online. Here's what I have (Project, Task, and Enterprise Resource are not null, I just cut out the code to get those)

    $DraftProject = $Project.Checkout()
    $NewAssignment = New-Object Microsoft.ProjectServer.Client.AssignmentCreationInformation
    $NewAssignment.ResourceId = $EnterpriseUser.Id
    $NewAssignment.TaskId = $Task.Id
    $returned = $DraftProject.Assignments.Add($NewAssignment)
    $QueueJob = $DraftProject.Update()
    $Job = $ProjectContext.WaitForQueue($DraftProject.Publish($true), 20)

    I get no errors, but no assignment happens. 

    When I try to use this code (different check in method) I get the error "PJClientCallableException: GeneralQueueCorrelationBlocked"

    $DraftProject = $Project.Checkout()
    $NewAssignment = New-Object Microsoft.ProjectServer.Client.AssignmentCreationInformation
    $NewAssignment.ResourceId = $EnterpriseUser.Id
    $NewAssignment.TaskId = $Task.Id
    $returned = $DraftProject.Assignments.Add($NewAssignment)
    $QueueJob = $DraftProject.Update()
    $ProjectContext.Load($QueueJob)
    $ProjectContext.ExecuteQuery()
    $Job = $ProjectContext.WaitForQueue($QueueJob, 20)
    $QueueJob2 = $DraftProject.CheckIn($false)
    $ProjectContext.Load($QueueJob2)
    $ProjectContext.ExecuteQuery()
    $Job2 = $ProjectContext.WaitForQueue($QueueJob2, 20)

    Any ideas?

    • Edited by Ryan EphgraveMVP Friday, November 18, 2016 11:36 PM added second code block
    Friday, November 18, 2016 11:32 PM

Answers

  • I figured it out. I had to add the resource to the project before creating the assignment.

    I used this code to do that:

        $temp = $DraftProject.ProjectResources.AddEnterpriseResource($EnterpriseResource)
        $queuejob = $DraftProject.Update()
        $Published = $DraftProject.Publish($true)
        $Job = $ProjectContext.WaitForQueue($Published, 120)

    Sunday, November 20, 2016 8:35 PM