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 ?
Sitecore Stack Exchange is a question and answer site for developers and end users of the Sitecore CMS and multichannel marketing software. It only takes a minute to sign up.
Sign up to join this communityWe 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 ?
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
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
}
}
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;
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:
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;
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!