Validation of SharePoint Approval Workflow with Powershell RRS feed

  • Question

  • Hi,

    I'm trying to built a powershell script (or c# application) to approve SharePoint approval Workflow. 

    This is my PowerShell code so far:

    $ci = New-Object System.Globalization.CultureInfo("fr-fr") 
    $taskStatus = [Microsoft.SharePoint.SPResource]::GetString($ci, "WorkflowTaskStatusComplete")
    $spweb = get-spweb -Identity "<Url of the Site>"
    $spweb.AllowUnsafeUpdates = $true
    $list = $spweb.Lists["<Name of the list where the workflow have to be approved>"]
    Foreach ($item in $list.Items)
        $workflows = $item.workflows
        Foreach ($workflow in $workflows)
            $tasks = $workflow.Tasks
            Foreach ($Task in $tasks)
    	    $ht = new-object Hashtable
                $ht[[Microsoft.SharePoint.SPBuiltInFieldId]::PercentComplete] = 1
                $ht[[Microsoft.SharePoint.SPBuiltInFieldId]::Completed] = $true
                $ht[[Microsoft.SharePoint.SPBuiltInFieldId]::WorkflowOutcome] = "Approved"
                $ht[[Microsoft.SharePoint.SPBuiltInFieldId]::TaskStatus] =  $taskStatus
                $ht["FormData"] = [Microsoft.SharePoint.Workflow.SPWorkflowStatus]::Completed
                [Microsoft.SharePoint.Workflow.SPWorkflowTask]::AlterTask($Task, $ht, $true)

    At the end of the script, this is how my workflow looks:

    Workflow state at the end

    As you can see, the workflow stay in "En cours" (French for "In progress"), even if the two tasks are finished (Terminé). And the column Résultat (Outcome) is not updated.

    I'm running out of ideas right now... It looked like a simple problem, but it's more complicated than I think! Any help would be great.

    Wednesday, June 10, 2015 1:22 PM

All replies

  • Hello,

    I am just wondering if this problem could be related to delay response or lock WF. Just to verify that try to pass "$false" in below line:

    Microsoft.SharePoint.Workflow.SPWorkflowTask]::AlterTask($Task, $ht, $false)
    You may want to read more: http://www.sharepointblogs.be/blogs/vandest/archive/2011/06/28/follow-up-programmatically-approving-a-workflow.aspx

    Let us know your result

    Hemendra:Yesterday is just a memory,Tomorrow we may never see<br/> Please remember to mark the replies as answers if they help and unmark them if they provide no help

    Thursday, June 11, 2015 6:35 AM
  • Hello Hermendra,

    I just tried to set the third parameter to $false and it did not change anything. 

    Thursday, June 11, 2015 7:20 AM
  • The weird thing I noticed, is the "WorkflowOutcome" field of the task is not updated, even using the AlterTask method.

    Thursday, June 11, 2015 8:08 AM