1

I'm working on a SPE script to execute when a workflow state is hit.

I've been trying to get the context item in the script, using the command Get-Item . (as I understand it, this should get the context item).

Instead of getting the context item, I get the home node.

I've tried rebuilding the links database and reindexing the Master and Web databases, to no avail.

I guess I have a few questions -

  1. Is that the correct way to get the context item in a SPE 6.4 script? If it's changed, how is it done now? (Some of the articles are a few years old)
  2. Is there another option for getting the context item? I haven't been able to find anything.

2 Answers 2

1

You can attach action of type "/sitecore/templates/Modules/PowerShell Console/PowerShell Script Workflow Action" to the workflow as below.

enter image description here

Inside above action,you can attach script from the Script Library and run either of these codes. It will return the context item on which workflow is fired.

$contextItem = Get-Item .
Write-Log ($contextItem | Format-Table | Out-String)

or

$contextItem = $SitecoreContextItem
Write-Log ($contextItem | Format-Table | Out-String)

This will output the context item in the SPE log file as below.

enter image description here

Hope this helps!!!

0

Try running this code to get the context item in your workflow state hit.

$item = $SitecoreContextItem
$comment = Show-Input -Prompt "Enter a comment:"
if($comment) {
    New-ItemWorkflowEvent -Item $item -Text $comment
}
Close-Window

Refet to this document for more details.

https://doc.sitecorepowershell.com/modules/integration-points/workflows

Hope this helps.

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.