2

I am moving workflow state through Powershell script to approved state. However, it is not publishing that item in the web database.

Code:-

$item.Editing.BeginEdit()
$item.__Workflow=$workflowId
$item."__Workflow state"=$workflowStateId
$item."__Default Workflow"=$workflowId
$item.Editing.EndEdit($false,$false)
7
  • Did you try manually changing this? Is it working? And did you check the raw value that the ID is updating of the desired workflow? Apr 28 at 10:52
  • Are you using the proper code format using brackets? - $item.Fields["__Workflow state"].Value = $workflowStateId Apr 28 at 11:05
  • @SumitBhatia, yes I have tried manually and it is working fine and checked its raw value as well and it is updating.
    – Nisha
    Apr 28 at 11:21
  • @MahendraShekhawat, I have tried your code and still it is not updating and showing in web databse .
    – Nisha
    Apr 28 at 11:22
  • @Nisha publishing means? after running the PowerShell, you are manually publishing the item and it's not going to web database? Apr 28 at 11:23

1 Answer 1

3

Changing the Workflow State field does not trigger any workflow actions. You need to use the WorkflowProvider to get the workflow and move it to the desired state.

With SPE you can do this via the Invoke-Workflow command:

Invoke-Workflow -Path master:/path-to-your/item `
    -CommandName "The Name of the Command" -Comments "Automated"

This will change the state of the item and execute any workflow actions that are setup in your workflow.

Here is the documentation for Invoke-Workflow

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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