Managing workflow schema

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

The following code samples show how to create a new schema Testing workflow with following steps:

 

Edit -> Article Approval (custom step) -> Publish -> Archive

 

It also creates a workflow scope that applies this workflow to all articles in the /TestingWorkflow section.

 

Creating a new workflow schema

 

[C#]

 

using CMS.SettingsProvider;

using CMS.CMSHelper;

using CMS.DataEngine;

using CMS.GlobalHelper;

using CMS.TreeEngine;

using CMS.SiteProvider;

using CMS.WorkflowEngine;

 

...

          // Prepare the data

          WorkflowInfo wi = new WorkflowInfo();

           wi.WorkflowDisplayName = "Testing workflow";

           wi.WorkflowName = "TestingWorkflow";

 

          // Insert the workflow

          WorkflowInfoProvider.SetWorkflowInfo(wi);

 

          // Create default steps (required for proper operation)

          WorkflowInfoProvider.CreateDefaultWorkflowSteps(wi.WorkflowID);      

 

 

Creating a workflow step

 

[C#]

 

using CMS.SettingsProvider;

using CMS.CMSHelper;

using CMS.DataEngine;

using CMS.GlobalHelper;

using CMS.TreeEngine;

using CMS.SiteProvider;

using CMS.WorkflowEngine;

 

...

 

          // Get the workflow

          WorkflowInfo wi = WorkflowInfoProvider.GetWorkflowInfo("TestingWorkflow");

          if (wi != null)

           {

              // Init new step

              WorkflowStepInfo wsi = new WorkflowStepInfo();

               wsi.StepDisplayName = "Article approval";

               wsi.StepName = "ArticleApproval";

 

              // Get published step info for the proper position

              WorkflowStepInfo psi = WorkflowInfoProvider.GetPublishedStep(wi.WorkflowID);

              if (psi != null)

               {

                  // New step has the previous published step order

                   wsi.StepOrder = psi.StepOrder;

 

                  // Move the published step down

                   psi.StepOrder += 1;

                  WorkflowInfoProvider.SetWorkflowStepInfo(psi);

 

                  // Move the archived step down

                  WorkflowStepInfo asi = WorkflowInfoProvider.GetArchivedStep(wi.WorkflowID);

                  if (asi != null)

                   {

                       asi.StepOrder += 1;

                      WorkflowInfoProvider.SetWorkflowStepInfo(asi);

                   }

               }

 

              // Insert the step to the database

               wsi.StepWorkflowID = wi.WorkflowID;

              WorkflowInfoProvider.SetWorkflowStepInfo(wsi);

           }      

 

 

Defining a workflow scope

 

[C#]

 

using CMS.SettingsProvider;

using CMS.CMSHelper;

using CMS.DataEngine;

using CMS.GlobalHelper;

using CMS.TreeEngine;

using CMS.SiteProvider;

using CMS.WorkflowEngine;

 

...

 

          // Get the workflow

          WorkflowInfo wi = WorkflowInfoProvider.GetWorkflowInfo("TestingWorkflow");

          if (wi != null)

           {

              // Init new workflow scope

              WorkflowScopeInfo wsi = new WorkflowScopeInfo();

               wsi.ScopeStartingPath = "/TestingWorkflow";

 

              // Assign the document type article

              DataClassInfo ci = DataClassInfoProvider.GetDataClass("CMS.Article");

              if ( ci != null )

               {

                   wsi.ScopeClassID = ci.ClassID;

               }

 

               wsi.ScopeSiteID = CMSContext.CurrentSite.SiteID;

               wsi.ScopeWorkflowID = wi.WorkflowID;

 

              // Save the scope to the database

              WorkflowInfoProvider.SetWorkflowScopeInfo(wsi);

           }

 

 

Deleting a workflow

 

[C#]

 

using CMS.SettingsProvider;

using CMS.CMSHelper;

using CMS.DataEngine;

using CMS.GlobalHelper;

using CMS.TreeEngine;

using CMS.SiteProvider;

using CMS.WorkflowEngine;

...

 

          // Get the workflow

          WorkflowInfo wi = WorkflowInfoProvider.GetWorkflowInfo("TestingWorkflow");

 

          // Delete the worfklow

          WorkflowInfoProvider.DeleteWorkflowInfo(wi.WorkflowID);

 

Page url: http://devnet.kentico.com/docs/devguide/index.html?managing_workflow_schema.htm