Workflow internals

  Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic! Mail us feedback on this topic!  

The workflow process is managed by the methods of the WorkflowManager class. Document uses workflow if there is a workflow scope defined for the document type and document location (SiteManager –> Development –> Workflow). If the document is in the middle of the workflow process and the workflow has been removed from the given group of documents, the current workflow must be finished (document must be published) in order to disable the workflow for the document.

 

There are three default workflow steps that are always used in the workflow process:

 

Edit – A new version of the document is edited.

 

Published – Document version was approved to be published and is either published or waiting to be published (if it's a scheduled document).

 

Archived – Document is archived, it is no longer published but it's stored for archive purposes.

 

You add your own workflow steps between the Edit and Published steps.

 

Here are some examples on how to use the workflow API:

 

Getting the document

 

You always need to get the proper document version first in order to keep the document data consistent if working with the versioned data. You can use both published and latest document version of the document for the basic workflow operations since it affects only the not-versioned data.

 

[C#]

 

using CMS.SiteProvider;

using CMS.TreeEngine;

using CMS.CMSHelper;

using CMS.WorkflowEngine;

 

// Always work with some user when editing documents

UserInfo ui = UserInfoProvider.GetUserInfo("administrator");

TreeProvider tree = new TreeProvider(ui);

 

// First, get the document

CMS.TreeEngine.TreeNode node =

tree.SelectSingleNode(CMSContext.CurrentSite.SiteName, "/News/Your-first-news", "en-us");

 

Getting the document workflow information

 

You can use the WorkflowManager.GetNodeWorkflow method to get the workflow information for the document node.

 

[C#]

 

using CMS.WorkflowEngine;

 

// Create the workflow manager instance

WorkflowManager wm = new WorkflowManager(tree);

WorkflowInfo wi = wm.GetNodeWorkflow(node);

if (wi != null)

{

// Document is using workflow

}

else

{

// Not using workflow

}

 

You can also use the WorkflowManager.GetNodeWorkflowScope method to check whether there is some workflow scope defined for the given document.

 

Getting current workflow step

 

The current workflow step ID is stored in the document field DocumentWorfklowStepID. Please note: if the workflow is defined and step ID is missing, the document is in the “edit” step.

 

[C#]

 

using CMS.WorkflowEngine;

 

if (wi != null)

{

// Document is using workflow, get current step information

WorkflowStepInfo si = wm.GetStepInfo(node);

if (si != null)

 {

  // Use the workflow step information

 }

}

 

Changing the workflow step

 

You should always follow the workflow definition and use the built-in methods only to move between the workflow steps to ensure the system consistency. Workflow process moves one step at a time, you can move through several steps by calling the methods several times. You should not attempt to move before the “edit” step and after the “archived” step. Use WorkflowManager.MoveToNextStep (the "approve" action) and WorkflowManager.MoveToPreviousStep (the "reject" action).

 

[C#]

 

if (si != null)

{

// Use the workflow step information to approve the document until it is published

while (si.StepName.ToLower() != "published")

 {

   si = wm.MoveToNextStep(node, "");

  if (si == null)

   {

      break;                      

   }

 }

}

 

Or

 

[C#]

 

if (si != null)

{

// Use the workflow step information to reject the document until it is in the edit step

while (si.StepName.ToLower() != "edit")

 {

   si = wm.MoveToPreviousStep(node, "");

  if (si == null)

   {

      break;                      

   }

 }

}

 

To move the document to the Archived step, use WorkflowManager.ArchiveDocument method.

 

Page url: http://devnet.kentico.com/docs/5_5r2/devguide/index.html?workflow_internals.htm