0

We would like to get workflow state name of the item. I tried to find on internet but did not get any relevant result.

Could someone help me out ?

4 Answers 4

1

If you are looking for Sitecore PowerShell script then you try this :-

$contentItem = Get-Item "master:path.."
(Get-Item master: -ID $contentItem."__Workflow state").Name 
3

You can get the workflow state using the below PowerShell script:

$item = Get-Item master:/sitecore/content/Home | Get-ItemField -IncludeStandardFields -ReturnType Field -Name "*" 
$item | ForEach-Object {
    if ($_.Name -eq '__Workflow state') {
        (Get-Item -Path "master:" -ID $_.Value).Name 
     }
}
2

I have assumed that you mean in .NET and not SPE.

If an item has a workflow state, you will be able access the name of that state by using one of the following ways:

  1. Through use of the Sitecore workflow state field directly:

    var workflowState = (Sitecore.Data.Fields.ReferenceField)Sitecore.Context.Item.Fields[Sitecore.FieldIDs.WorkflowState];
    var workflowStateName = workflowState.TargetItem.DisplayName;
    
  2. Using the workflow provider

     var workflow = Sitecore.Context.Database.WorkflowProvider.GetWorkflow(Sitecore.Context.Item);
     var workflowState = workflow.GetState(Sitecore.Context.Item);
     var workflowStateName = workflowState.DisplayName;
    

I hope this helps!

1

To get the workflow state you can use :

var workflowStateItemid=currentItem["__Workflow state"];
var workflowStateItem=Sitecore.Context.Dabase.GetItem(new ID(workflowStateItemid));
var workflowStateItemName=workflowStateItem.Name; 
1
  • Could you assist me how I can get workflow state of the item in Sitecore power shell script ?
    – Nisha
    May 2, 2022 at 8:47

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.