Kentico CMS 7.0 Developer's Guide

Managing workflows

Managing workflows

Previous topic Next topic Mail us feedback on this topic!  

Managing workflows

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

Arrow


API examples for newer versions


Please visit the latest API Examples documentation to view API examples for newer versions of Kentico.



The following example creates a workflow.

 

private bool CreateWorkflow()

{

  // Create new workflow object

  WorkflowInfo newWorkflow = new WorkflowInfo();

 

  // Set the properties

   newWorkflow.WorkflowDisplayName = "My new workflow";

   newWorkflow.WorkflowName = "MyNewWorkflow";

 

  // Save the workflow

  WorkflowInfoProvider.SetWorkflowInfo(newWorkflow);

 

  // Create the three default workflow steps

  WorkflowStepInfoProvider.CreateDefaultWorkflowSteps(newWorkflow.WorkflowID);

 

  return true;

}

 

The following example gets and updates the workflow created by the code example above.

 

private bool GetAndUpdateWorkflow()

{

  // Get the workflow

  WorkflowInfo updateWorkflow = WorkflowInfoProvider.GetWorkflowInfo("MyNewWorkflow");

  if (updateWorkflow != null)

   {

      // Update the properties

       updateWorkflow.WorkflowDisplayName = updateWorkflow.WorkflowDisplayName.ToLower();

 

      // Save the changes

      WorkflowInfoProvider.SetWorkflowInfo(updateWorkflow);

 

      return true;

   }

 

  return false;

}

 

The following example gets and bulk updates workflows matching the specified WHERE condition.

 

private bool GetAndBulkUpdateWorkflows()

{

  // Prepare the parameters

  string where = "WorkflowName LIKE N'MyNewWorkflow%'";

 

  // Get the data

  DataSet workflows = WorkflowInfoProvider.GetWorkflows(where, null, 0, null);

  if (!DataHelper.DataSourceIsEmpty(workflows))

   {

      // Loop through the individual items

      foreach (DataRow workflowDr in workflows.Tables[0].Rows)

       {

          // Create object from DataRow

          WorkflowInfo modifyWorkflow = new WorkflowInfo(workflowDr);

 

          // Update the properties

           modifyWorkflow.WorkflowDisplayName = modifyWorkflow.WorkflowDisplayName.ToUpper();

 

          // Save the changes

          WorkflowInfoProvider.SetWorkflowInfo(modifyWorkflow);

       }

 

      return true;

   }

 

  return false;

}

 

The following example deletes the workflow created by the first example on this page.

 

private bool DeleteWorkflow()

{

  // Get the workflow

  WorkflowInfo deleteWorkflow = WorkflowInfoProvider.GetWorkflowInfo("MyNewWorkflow");

 

  // Delete the workflow

  WorkflowInfoProvider.DeleteWorkflowInfo(deleteWorkflow);

 

  return (deleteWorkflow != null);

}