0

Can we get workflow id if we have workflow name in Powershell script?

Scenario 1:
I have workflow name "Test workflow" based on its name can I get its id in Powershell script?

Scenario 2:

Can we get workflow state id as well if I have workflow state name in Powershell script?

2
  • So you mean that you don't have path and ID of the item, only name and using that you want to identify the workflow ID and it's details right? Commented Apr 26, 2022 at 13:17
  • Yes @SumitBhatia
    – Nisha
    Commented Apr 26, 2022 at 14:12

4 Answers 4

1

As per my understanding, you would like to get workflow ID based on workflow name only.

For your first scenario try this approach :

(Get-Item  -Path  "master:/sitecore/system/Workflows/<your workflow name>").ID

For your second scenario try the same approach and add your workflow state name like below :

(Get-Item  -Path  "master:/sitecore/system/Workflows/<your workflow name>/<your workflow state name>").ID
1
  • Able to get id here. Thanks you !
    – Nisha
    Commented Apr 26, 2022 at 17:34
2

Scenario 1:

As we discussed in comments, If you don't have the Path and ID of the workflow item then you need to use a Query to get the item like below.

Get-Item -Path "master:" -Query "/sitecore/system/Workflows//*[@@templatename='Workflow']" | Where-Object { $_.Name -eq "<Your Workflow Name>"}

So in the above query, we have to provide the location where Sitecore maintains all the workflows. i.e. /sitecore/system/Workflows

Using the above query, it will get all the items by filtering with the template name and item name.

Scenario 2:

Using the same approach we will get the children of the Workflow that we get from the query and then loop through its child items to identify the state like this.

$workflow = Get-Item -Path "master:" -Query "/sitecore/system/Workflows//*[@@templatename='Workflow']" | Where-Object { $_.Name -eq "<Your state name>"} 

Get-ChildItem -ID $workflow.Id | Where-Object { $_.Name -eq "Deployed"} 

Hope this helps.

1
  • It was showing full details of the item along with the id. I need only id of the workflow.
    – Nisha
    Commented Apr 26, 2022 at 17:32
1

You can get the workflow id by using the below -

Scenario 1:

1st way - (Get-Item master: -ID $_."__Workflow state").Name

2nd way -

Get-ItemWorkflowEvent -Path master:\content\home

Output will be like this -

Date     : 2014-07-27 14:23:33
NewState : {190B1C84-F1BE-47ED-AA41-F42193D9C8FC}
OldState : {46DA5376-10DC-4B66-B464-AFDAA29DE84F}
Text     : Automated
User     : sitecore\admin

Date     : 2014-08-01 15:43:29
NewState : {190B1C84-F1BE-47ED-AA41-F42193D9C8FC}
OldState : {190B1C84-F1BE-47ED-AA41-F42193D9C8FC}
Text     : Just leaving a note
User     : sitecore\admin

Follow this - https://doc.sitecorepowershell.com/appendix/common/get-itemworkflowevent

Scenario 2: Try this, I haven't tested this.

(Get-Item master: -Name $_."__Workflow state").ID
1
  • I have tried this and it is not showing anything.
    – Nisha
    Commented Apr 26, 2022 at 17:29
1

Scenario 1: You can get an Id based on the path of workflow, like below:

Get-Item  -Path  "master:/sitecore/system/Workflows/Analytics Testing Workflow"

enter image description here

Scenario 2:

If you have different states in workflow like below:

enter image description here

You need to do the similar thing which you did in Scenario 1, need to pass state path and it will return the ID

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.