3

I need create a PowerShell code to get the status of a workflow in a list items of the SharePoint Online. It's simple in On Premise SharePoint, but in online I have serious difficulties.

Someone can help me?

2 Answers 2

2

You could utilize CSOM/REST API for that purpose, below is demonstrated how to consume CSOM to retrieve workflow status in PowerShell.

How to retrieve workflow status for List Item using CSOM in PowerShell

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")


Function Get-SPOCredentials([string]$UserName,[string]$Password)
{
   if([string]::IsNullOrEmpty($Password)) {
      $SecurePassword = Read-Host -Prompt "Enter the password" -AsSecureString 
   }
   else {
      $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
   }
   return New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
}


 Function GetWorkflowStatus([Microsoft.SharePoint.Client.List]$list,[int]$listItemId, [string]$workflowName)
 {
     $context = $list.Context
     $listItem = $list.GetItemById($listItemId)
     $context.Load($listItem.FieldValuesAsHtml)

     $workflowStatusField = $listItem.ParentList.Fields.GetByTitle($workflowName)
     $context.Load($workflowStatusField)
     $context.ExecuteQuery()

     if ($listItem.FieldValuesAsHtml[$workflowStatusField.StaticName] -ne $null)
     {
         $statusValue = $listItem.FieldValuesAsHtml[$workflowStatusField.StaticName]
         return $statusValue;
     }
     return $null
 }





$UserName = "[email protected]"
$Password = Read-Host -Prompt "Enter the password"    
$WebUrl = "https://tenant.sharepoint.com/"
$ListTitle = "Documents"
$ListItemId = 1
$WorkflowTitle = "Approval"

$Context = New-Object Microsoft.SharePoint.Client.ClientContext($WebUrl)
$Context.Credentials = Get-SPOCredentials -UserName $UserName -Password $Password
$list = $Context.Web.Lists.GetByTitle($ListTitle)
$statusValue = GetWorkflowStatus -list $list -listItemId $ListItemId -workflowName $workflowTitle
$Context.Dispose()

Key points:

  • Method GetWorkflowStatus demonstrates how to retrieve workflow status name
0
0

SharePoint Online Management Shell is very limited to use. As you can see in the below article only few options are available to query Sharepoint online. Unfortunately there is no cmdlets for getting workflow status or something.

http://office.microsoft.com/en-in/sharepoint-help/introduction-to-the-sharepoint-online-management-shell-HA102915057.aspx

4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.