4

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

But I have a code to update some of the items programatically 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 doesn't appear in Workbox. The goal is to update the items programatically (including create new version), but someone has to review and submit to get the updated items published.

Please let me know if anyone got inputs.

Thanks, Sharath

2

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

  • How would you set the state to another? e.g Approved – Percy Jan 2 '19 at 14:17
  • You can see that here : cognifide.com/our-blogs/sitecore/… – Ahmed Okour Jan 3 '19 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 '19 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.

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

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.