4

I want to replicate the scenario workflow scenario programmatically. I have a simple workflow with 2 states Draft and Published (or Approved). Users with the right permission can edit, save and even submit the changes Or other users can review and submit from their workbox. This works fine when the user edits the changes in the content editor.

But I have a code to update some of the items programmatically and I am using switch user to run that piece of code under some specific user context. Now the problem is, those updates are not going through workflows. I am able to update the workflow details (workflow id, state id) to the item's corresponding field ("__Workflow", "__Workflow state") but the problem is those items don't appear in Workbox. The goal is to update the items programmatically (including creating a new version), but someone has to review and submit to get the updated items published.

Please let me know if anyone got input.

Thanks, Sharath

2 Answers 2

3

You can use Sitecore Workflow API to add the newly created item/version into workflow, the new version will go into the initial state of your workflow, which usually would be the "Draft" state.

ID WorkflowID = ID.Parse("ID of your workflow Item");
newItemVersion.Editing.BeginEdit();
newItemVersion.Fields[Sitecore.FieldIDs.Workflow].Value = WorkflowID;
IWorkflow wf = master.WorkflowProvider.GetWorkflow(WorkflowID);
wf.Start(newItemVersion);
newItemVersion.Editing.EndEdit();

Hope this helps

3
  • How would you set the state to another? e.g Approved
    – Percy
    Jan 2, 2019 at 14:17
  • You can see that here : cognifide.com/our-blogs/sitecore/… Jan 3, 2019 at 17:08
  • Cheers Ahmed - I found your site and used it to come up with a solution Thank you - copy paste gave me a few errors but it managed to point me in the right direction.
    – Percy
    Jan 3, 2019 at 17:10
0

Sitecore PowerShell Extensions comes with a few commands to help manipulate workflow data.

Invoke-Workflow is likely the command you would use in your scenario.

Example: The following transitions the item through the workflow by triggering the command programmatically.

Invoke-Workflow -Path master:/content/home -CommandName "Submit" -Comments "Automated"

Other commands of interest include New-ItemWorkflowEvent and Get-ItemWorkflowEvent.

1
  • Thanks you Michael, good to know that this can be done with Sitecore PowerShell too..!
    – Sharath
    Oct 6, 2017 at 3:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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